Post about your Basic project here

Moderator: Mmiscool

User avatar
By forlotto
#36844 This is the AC light Dimmer I picked up from Krida

http://www.inmojo.com/store/krida-elect ... -heatsink/

Now to figure out if it is even possible to get this going with Basic.

I am not to sure which pins to use for gate and sync.

And I have a lack of knowledge about Zero Cross Detection according to this it is on the board already.

So many questions now that I have this board...

Does timing need to be handled by the esp?
Can the ESP handle the proper fractions of a second?
Is Basic in its current form able to handle this type of project?

There is a sketch for the arduino as well as an android.apk to control it with the HC05 bluetooth adapter...
Sketch: https://drive.google.com/open?id=0B6GJo ... zF5MHBnUDQ
Code: Select all

// Testing sketch for 50Hz !!!
//
// Bluetooth Module HC-05, Speed 9600kbps
//
// How to connect dimmer and hc-05 modules to Arduino UNO board
//
// Dimmer   Arduino
//   |             |
//  GND           GND
//  VCC           5V
//  SYNC        DIGITAL.3
//  GATE         DIGITAL.7
//
//  HC-05       Arduino UNO 
//   |             |
//  GND           GND
//  VCC           5V
//  TX            RX (DIGITAL.0)


#include <TimerOne.h>    // download this library from arduino.cc

unsigned char channel_1 = 7; // Output to Opto Triac pin, channel 1
unsigned char CH1;
unsigned char i=0;
unsigned char clock_tick; // variable for Timer1
int incomingByte = 0;
int mas[3];


void setup() {

Serial.begin(9600);
pinMode(channel_1, OUTPUT);// Set AC Load pin as output
attachInterrupt(1, zero_crosss_int, RISING);
Timer1.initialize(100); // set a timer of length 100 microseconds for 50Hz or 83 microseconds for 60Hz;
Timer1.attachInterrupt( timerIsr ); // attach the service routine here

CH1=95; // WHEN ARDUINO START, BULB OFF (95 - FULLY OFF ; 5 - FULLY ON) !!!

}

void timerIsr()
{
clock_tick++;

if (CH1==clock_tick)
{
digitalWrite(channel_1, HIGH); // triac firing
delayMicroseconds(10); // triac On propogation delay (for 60Hz use 8.33)
digitalWrite(channel_1, LOW); // triac Off
}

}



void zero_crosss_int() // function to be fired at the zero crossing to dim the light
{
// Every zerocrossing interrupt: For 50Hz (1/2 Cycle) => 10ms ; For 60Hz (1/2 Cycle) => 8.33ms
// 10ms=10000us , 8.33ms=8330us

clock_tick=0;
}



void loop() {

if (Serial.available() > 0) {

incomingByte = Serial.read();

if (incomingByte=='X')
{
mas[0]=Serial.read();
mas[1]=Serial.read();
mas[2]=Serial.read();
Serial.flush();
}

if (mas[0]=='A') { if(mas[1]>=0) {CH1=mas[1]; CH1=100-CH1; if (CH1<5) {CH1=5;} if (CH1>95) {CH1=95;}}}

}


}


Android APK: https://drive.google.com/open?id=0B6GJo ... 196ODF4U2s

However this is a basic forum and I kind of want to make it possible for basic and share the project and create a video of it operating etc....

Anyone with a decent knowledge feel free to join in on this project and help it along right now I do not have anything but "some of the parts" and a whole lot of questions. I still need a light fixture for the final application but for now I have a light fixture that will work as a test rig.

I would like to share all instructions, parts, code, etc... But I must say that I would never suggest that ANYONE who is not certified to work with High Voltage should do so nor that anyone should try it without the proper safety, knowledge, and tools.

Thanks in advance to any contributions made to this project we need to show some cool stuff with basic in mind I have all the tools at my disposal to make this happen.

Somethings to note:
Currently the electric I use is 60hz 120VAC
So all timing will be based off of this!

Could I just copy and paste code and get this thing working with my arduino?
Yes I could but it defeats the purpose of bringing this to Basic to really show the potential.

I will need help on this one due to my lack of understanding but in the end the project will be a community project that will improve upon what is available with Basic.

If there is zero interest in making this happen or zero help I may just copy and paste code and skip making this project at all so that I don't have equipment sitting around collecting dust for no reason at all.

Lets reinvent this thing and make a basic AC light dimmer!
Arduino Test Sketch:

Code: Select all

unsigned char AC_LOAD = 7;    // Output to Opto Triac pin
unsigned char dimming = 3;  // Dimming level (0-100)
unsigned char i;


void setup() {
  // put your setup code here, to run once:
  pinMode(AC_LOAD, OUTPUT);// Set AC Load pin as output
  attachInterrupt(1, zero_crosss_int, RISING);

  // Serial.begin(9600);

}

void zero_crosss_int()  // function to be fired at the zero crossing to dim the light
{
  // Firing angle calculation : 1 full 50Hz wave =1/50=20ms
  // Every zerocrossing : (50Hz)-> 10ms (1/2 Cycle) For 60Hz (1/2 Cycle) => 8.33ms
  // 10ms=10000us
 
  int dimtime = (100*dimming);    // For 60Hz =>65   
  delayMicroseconds(dimtime);    // Off cycle
  digitalWrite(AC_LOAD, HIGH);   // triac firing
  delayMicroseconds(10);         // triac On propogation delay (for 60Hz use 8.33)
  digitalWrite(AC_LOAD, LOW);    // triac Off
}



void loop() {
   
       
           
          // Serial.println(pulseIn(8, HIGH));
         
          for (i=5;i<85;i++)
          {
            dimming=i;
            delay(20);
          }
       
          for (i=85;i>5;i--)
          {
            dimming=i;
            delay(20);
          }
                     

}



NOTE WE SHOULD NOT NEED TO USE SERIAL FOR THIS !!! WIFI is built in to the ESP...
User avatar
By forlotto
#36931 Descriptions of pins:

+5V -> device power, DC 5 volts
SYNC -> zero-cross detector output positive impulse (pulse length 200us)
GATE -> triac gate input pin
GND -> ground of low voltage side
AC INPUT -> AC voltage input 110/220
AC LOAD -> Connect your load here !

note need to figure out if:

Code: Select alltimer 8.33


Is acceptable if it will do decimal fractions of time not entirely sure that this is allowed with basic although I would assume they use the same timer function from the arduino being that most of the stuff is ported from this.

Dunno gotta think this through shouldn't be impossible to make it happen I would presume
Last edited by forlotto on Mon Dec 21, 2015 10:57 pm, edited 2 times in total.
User avatar
By viscomjim
#36933 I'm no expert, but I have a feeling that since this port is interpreted, the speed might not be there to be able to sense a start pulse from you ZCD circuit and trigger the triac consistently to do phase control. I don't know enough specifics, but timing is critical when doing phase control.

http://www.instructables.com/id/Arduino ... /?ALLSTEPS

A really good article on this and you can see that timing is imperative to make this work. You might want to actually try this with an arduino to wrap your head around it and then experiment with the esp to see how the timing will work for you. I think your board has all the right things to do some testing.

Please keep your result coming as this is a cool project for the esp, especially if it works with this port.

http://sourceforge.net/p/gcbasic/discus ... /b3cdae27/

A thread about doing something similar using a compiled basic using pic micros. Read through this and you can see that timing is the deal breaker.

In another thread in this platform, I see that Mike got the neopixels to work and these require some pretty stringent timing, so your project may be doable, just not sure if the timing based on the interpreter will be tight enough. There may be an existing library for the arduino that Mike can make use of for this.
User avatar
By forlotto
#36935 It is possible with the nodemcu with LUA dunno about basic though ....

Here is a similar circuit and info ...

http://www.esp8266-projects.com/2015/05 ... -with.html

The hardware may require tighter timing as well wish I would have went with this hardware instead to be honest in case there is an issue with my hardware but I have what I have want to attempt a bit to make it work ...

Perhaps I should try with the arduino but, I'm in no real need of this personally it was more bought to try and share a project for basic more than anything.

Anyhow I'll have to keep plugging away and reading before I do too awful much would rather not ruin a 30 dollar board messing about without the proper research first.