Hi
I am New to Arduino Family.As i am doing a project on to turn on/off AC automatically in pre-defined time(1sec on and 1 hour off).i taken power on button data using decode method …now i am able to turn on the AC but not turnning off .Kindly guide me how can i make AC to turn-off in the specified time.
I am using UNO …Hardware discription is using IR LED at pin number13
Thanks in advance
Samatha````
// This program allows an Arduino to power on/off a Duraflame heater using infrared
//
// Usage: hook up an IR led with Annode on pin 13. Then send serial data “POWER”
// to the arduino. It should flash the LED code.
//
// By Rick Osgood with code borrowed from adafruit.com
//
#define IRledPin 13
#define NumIRsignals 98
boolean toggle1 = 0;
int val=0;
// This is the code I determined works for my Duraflame heater
int IRsignal = {
// ON, OFF (in 10’s of microseconds)
894, 410,
54, 156,
50, 52,
50, 54,
48, 54,
48, 158,
48, 56,
46, 56,
48, 54,
48, 56,
46, 56,
48, 56,
46, 56,
48, 56,
46, 56,
46, 56,
46, 58,
46, 56,
46, 58,
46, 160,
46, 160,
46, 58,
44, 58,
46, 56,
46, 58,
46, 56,
46, 58,
46, 160,
46, 158,
48, 3172,
886, 418,
48, 160,
46, 56,
46, 58,
46, 56,
46, 160,
46, 58,
46, 56,
46, 56,
46, 162,
46, 158,
48, 56,
46, 56,
48, 54,
48, 56,
48, 54,
48, 56,
46, 56,
48, 56,
46, 56,
48, 56,
46, 56,
46, 160,
46, 58,
46, 160,
46, 56,
46, 58,
46, 56,
46, 160,
46, 3724,
38, 0};
void setup(void) {
digitalWrite(IRledPin, LOW); //Make sure LED starts “off”
Serial.begin(9600); //Initialize Serial port
pinMode(13, OUTPUT);
cli();//stop interrupts
//set timer1 interrupt at 1Hz
TCCR1A = 0;// set entire TCCR1A register to 0
TCCR1B = 0;// same for TCCR1B
TCNT1 = 0;//initialize counter value to 0
// set compare match register for 1hz increments
OCR1A = 15624;// = (1610^6) / (11024) - 1 (must be <65536)
// turn on CTC mode
TCCR1B |= (1 << WGM12);
// Set CS12 and CS10 bits for 1024 prescaler
TCCR1B |= (1 << CS12) | (1 << CS10);
// enable timer compare interrupt
TIMSK1 |= (1 << OCIE1A);
sei();//allow interrupt
}
ISR(TIMER1_COMPA_vect){//timer1 interrupt 1Hz toggles pin 13 (LED)
//generates pulse wave of frequency 1Hz/2 = 0.5kHz (takes two cycles for full wave- toggle high then toggle low)
val++;
if (toggle1){
if(val==3600)
{
digitalWrite(13,HIGH);
toggle1 = 0;
val=0;
}
}
else{
digitalWrite(13,LOW);
toggle1 = 1;
}
}
void loop() {
char data[6];
int index = 0;
delay(1000); //Serial input seems to need some kind of short delay or the data gets screwed up.
while (Serial.available() > 0)
{ //Loop if there data on the serial line
if (index < 5)
{ //Make sure we don’t overflow
data[index] = Serial.read(); //Load a character into the string
index++; //Increment the index to get the next character
}
}
data[5]=’\0’; //Null terminate the string
// if (strcmp(data, “POWER”) == 0)//{ //If the Arduino receives the POWER signal…
// Serial.println(“SENDING SIGNAL!”);
for (int i = 0; i < NumIRsignals; i+=2)
{ //Loop through all of the IR timings
pulseIR(IRsignal_*10); //Flash IR LED at 38khz for the right amount of time_
_ delayMicroseconds(IRsignal[i+1]*10); //Then turn it off for the right amount of time_
-
}*
-
//} //Otherwise do nothing!-=-=*
}
// This function allows us to PWM the IR LED at about 38khz for the sensor
// Borrowed from Adafruit!
void pulseIR(long microsecs) { -
// we’ll count down from the number of microseconds we are told to wait*
-
cli(); // this turns off any background interrupts*
-
while (microsecs > 0) {*
-
// 38 kHz is about 13 microseconds high and 13 microseconds low*
-
digitalWrite(IRledPin, HIGH); // this takes about 3 microseconds to happen*
-
delayMicroseconds(10); // hang out for 10 microseconds, you can also change this to 9 if its not working*
-
digitalWrite(IRledPin, LOW); // this also takes about 3 microseconds*
-
delayMicroseconds(10); // hang out for 10 microseconds, you can also change this to 9 if its not working*
-
// so 26 microseconds altogether*
-
microsecs -= 26;*
-
}*
-
sei(); // this turns them back on*
}