I am doing a project on IR controlled light dimmer using an Arduino. I am using 4N35 for zero crossing detection and I am giving that zero crossing as interrupt. Also when I am combining the IR receiver and the interrupt the ground of the receiver is floating and it starts receiving garbage value. So I need to know what is the problem with this?
I have used standard schematics for zero cross detection (4N25 + bridge rectifier), MOC 3021 + BT136 traic, and standard IR receiver.
So what happens if you cut your interrupt routine down to the bare minimum, like this.
It won't work. The triac needs to be fired on a very tight schedule - inside the ISR.
OP - Frankly, you are pushing the limits of the Arduino - probably past the breaking point. You might be able to get two Arduinos to talk to each other. One would deal with the dimming. The other would deal with the the IR.
PaulS:
It won't work. The triac needs to be fired on a very tight schedule - inside the ISR.
OP - Frankly, you are pushing the limits of the Arduino - probably past the breaking point. You might be able to get two Arduinos to talk to each other. One would deal with the dimming. The other would deal with the the IR.
VERY tight? Aren't we talking about 50hz mains? I'm sure a few microseconds won't do any harm.
Thanks KenF and PaulS for your replies. I have modified the code so that now I don't use interrupts.
I have modified the IRRemote library to access the decodeNEC as public method in my code (Remote I used sends NEC encoded codes), as the decode method is a bit slow. I had to modify the decodeNEC method as decode method do some inits before calling decodeNEC. Now it is working
Following is the modified code
#include <IRremote.h>
int RECV_PIN = 11;
decode_results results;
int ZERO_CROSS_PIN = 10;
IRrecv irrecv(RECV_PIN);
int AC_LOAD = 13;
volatile int dimming = 67;
int isOn = 1;
int dimInc = -4;
void setup()
{
//Serial.begin(9600);
irrecv.enableIRIn();
pinMode(AC_LOAD, OUTPUT);
pinMode(ZERO_CROSS_PIN, INPUT);
}
void zero_crosss_int()
{
int dimtime = 75*dimming;
delayMicroseconds(dimtime); // Off cycle
digitalWrite(AC_LOAD, HIGH); // triac firing
delayMicroseconds(11); // triac On propogation delay
digitalWrite(AC_LOAD, LOW); // triac Off
}
long prevMills = 0;
void loop()
{
if(digitalRead(ZERO_CROSS_PIN) && isOn){
zero_crosss_int();
}
if(millis() - prevMills > 10000){
prevMills = millis();
dimming += dimInc;
// Serial.println(dimming);
if(dimming >= 67){
dimInc = -4;
}else if(dimming <= 50){
dimInc = 4;
}
}
if (irrecv.decodeNEC(&results)) {
long currentMicros = micros()-lastMicros;
// Serial.println(currentMicros);
// Serial.print("0x");
// Serial.println(results.value, HEX);
switch(results.value){
case 0xFFEA15:
dimming = 71;
break;
case 0xFFDA25:
dimming = 67;
break;
case 0xFFFA05:
dimming = 63;
break;
case 0xFF6A95:
dimming = 59;
break;
case 0xFF5AA5:
dimming = 55;
break;
case 0xFFE21D:
isOn = !isOn;
}
irrecv.resume();
}
}
This code also contains 5 step testing of the dimmer in every 10 secs.
I think this would help anyone who have/had faced this issue.
Depends on the board that you conveniently forgot to mention. For Arduinos, look at EEPROM.put() and EEPROM.get(). This will probably not work for ESPs and STMs (but I have no experience with them).
For everybody that wants to reply, please note that this thread is about 6 years old.