I am developing 3 Channel light dimmer and try to cotrolled light dimming by receceving Serial Data. Single AC Light is working OK but in multiple light fist lamp get OFF while controlling other or start fluctuating. In third Lamp i need to performed just ON and OFF operation but data loss in serail communication
#include <TimerOne.h>
int AC_LOAD[] = {3,4,5}; // Output to Opto Triac pin
int i;
int dimming,dimming1,dimming2 = 128;
int flag1,flag2,flag3=0;
String inString = ""; // string to hold input
unsigned char clock_tick; // variable for Timer1
// char living[6]; #define PINS 3
void setup()
{
Serial.begin(9600);
for( i=0; i < PINS; i++) { //set the pins to output
pinMode(AC_LOAD*, OUTPUT);// Set AC Load pin as output*
}*
attachInterrupt(0, 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*
while (!Serial)*
{*
;*
} *
}*
// Firing angle calculation : 1 full 50Hz wave =1/50=20ms*
// Every zerocrossing thus: (50Hz)-> 10ms (1/2 Cycle) For 60Hz => 8.33ms (10.000/120)*
Please read the first post in any forum entitled how to use this forum. http://forum.arduino.cc/index.php/topic,148850.0.html then look down to item #7 about how to post your code.
It will be formatted in a scrolling window that makes it easier to read.
Can you please post a copy of your circuit, in CAD or a picture of a hand drawn circuit in jpg, png?
{facepalm} No, not in a thread called "Code Tags" (which the forum told you hadn't been posted to in a long while, and asked you if you were sure you wanted to post in) but inside actual [code]your code goes here[/code] tags.
This is probably (part of) the problem.
There's more going on in that sketch, including delays of lots of microseconds, so there's a fair chance you miss your clock_tick. Test for > instead of ==.
If I have using this ocde light will get off automaticlly in few Second,what changes required, please Help
/*AC Light Control FOR 8 CHANNEL UNIT
Updated by Joey Pongallo
6/23/2018
JoeyPongallo@gmail.com
Revised code from Robert Twomey who Adapted from Ryan McLaughlin
*/
#include <TimerOne.h> // Avaiable from http://www.arduino.cc/playground/Code/Timer1
volatile int i = 0; // Variable to use as a counter volatile as it is in an interrupt
volatile int i2 = 0;
volatile int i3 = 0;
volatile boolean zero_cross = 0; // Booleans to store a "switch" to tell us if we have crossed zero
volatile boolean zero_cross2 = 0;
volatile boolean zero_cross3 = 0;
int channel1 = 3; // Output to Opto Triac / Channels
int channel2 = 4;
int channel3 = 5;
int dim = 128; // Dimming level (0-128) 0 = on, 128 = 0ff
int dim2 = 128;
int dim3 = 128;
int freqStep = 75; // This is the delay-per-brightness step in microseconds.
// For 60 Hz it should be 65
// It is calculated based on the frequency of your voltage supply (50Hz or 60Hz)
// and the number of brightness steps you want.
//
// Realize that there are 2 zerocrossing per cycle. This means
// zero crossing happens at 120Hz for a 60Hz supply or 100Hz for a 50Hz supply.
// To calculate freqStep divide the length of one full half-wave of the power
// cycle (in microseconds) by the number of brightness steps.
//
// (120 Hz=8333uS) / 128 brightness steps = 65 uS / brightness step
// (100Hz=10000uS) / 128 steps = 75uS/step
void setup() {
pinMode(channel1, OUTPUT); // Set the Triac pins as output
pinMode(channel2, OUTPUT);
pinMode(channel3, OUTPUT);
attachInterrupt(0, zero_cross_detect, RISING); // Attach an Interupt to Pin 2 (interupt 0) for Zero Cross Detection
Timer1.initialize(freqStep); // Initialize TimerOne library for the freq we need
Timer1.attachInterrupt(dim_check, freqStep);
// Use the TimerOne Library to attach an interrupt
// to the function we use to check to see if it is
// the right time to fire the triac. This function
// will now run every freqStep in microseconds.
Serial.begin(9600);
}
void zero_cross_detect() {
zero_cross = true; // set the boolean to true to tell our dimming function that a zero cross has occured
zero_cross2 = true;
zero_cross3 = true;
i = 0;
i2 = 0;
i3 = 0;
digitalWrite(channel1, LOW); // turn off TRIAC (and AC)
digitalWrite(channel2, LOW);
digitalWrite(channel3, LOW);
}
// Turn on the TRIAC at the appropriate time
void dim_check() {
if (zero_cross == true) {
if (i >= dim) {
//Serial.println(i);
digitalWrite(channel1, HIGH); // turn on light
i = 0; // reset time step counter
zero_cross = false; //reset zero cross detection
}
else {
i++; // increment time step counter
}
}
if (zero_cross2 == true) {
if (i2 >= dim2) {
//Serial.println(i2);
digitalWrite(channel2, HIGH); // turn on light
i2 = 0; // reset time step counter
zero_cross2 = false; //reset zero cross detection
}
else {
i2++; // increment time step counter
}
}
if (zero_cross3 == true) {
if (i3 >= dim3) {
//Serial.println(i2);
digitalWrite(channel3, HIGH); // turn on light
i3 = 0; // reset time step counter
zero_cross3 = false; //reset zero cross detection
}
else {
i3++; // increment time step counter
}
}
}
void loop() {
if (Serial.available() > 0) {
//char data = Serial.read(); // reading the data received from the bluetooth module
int value = Serial.parseInt();
Serial.println(value);
if (value > 3 && value < 125) {
dim = value ;
dim = filterDimmingValue(dim);
Serial.println("Channel1: " + dim);
}
if (value > 128 && value < 250) {
dim2 = value - 125;
dim2 = filterDimmingValue(dim2);
Serial.println("Channel2: " + dim2);
}
if (value > 253 && value < 375) {
dim3 = value - 250;
dim3 = filterDimmingValue(dim3);
Serial.println("Channel2: " + dim3);
}
// Turn all lights off
if (value == 0) {
dim = 128;
dim2 = 128;
dim3 = 128;
}
// Turn all lights on max
if (value == 9999) {
dim = 5;
dim2 = 5;
dim3 = 5;
}
}
delay(5);
}
int filterDimmingValue(int value) {
if (value > 128)
value = 128;
if (value < 5)
value = 5;
return value;
}
I am developing a circuit to control light dimming of 3 different LAMP, I am sending data serial from one arduino to anoher arduino controller for control light dimming. In recent code, my LAMP is ON for few Sec Only and get OFF automaticlly.So,what chnages I have rquired in my code in this three LAMP are oreprrated Independently or any other code available to controlled three LAMP independently using Serial communication without Serial Data Loss
What do you want the lamps to do, exactly? (on/off/timed/dimmed/explode/bring world peace/something else maybe?)
What serial communications? (what commands/how often/etc)
From where?
What do you think gets lost? (Serial is very reliable - as long as you got your settings right)
Can you describe "operates erratically"?