Re:How to make the A/C to be off using Decoding method

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*
    }

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
Code: [Select]
Code: [Select]

// 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
}

We're getting bored with the cross-posting.

Please stop.
You can edit in the code tags you missed by hitting the "modify" control.

Can you explain WHAT the program needs to do. How does the heater work?
I can't immediately see any need for such complex code.

What is the long list of number-pairs intended for ?

...R

Hi

i am trying to turn on A/C for pre-defined time lets say 30mins,and off for other 30 mins ,to do this i taken code of IR decoder with which i can get the Power on/off key values,the array is the decoded value in void loop(),reading this array to turn onA/C.Kindly guide me how to turn off A/c after pre-defined time

Thank you

samathasan1:
i am trying to turn on A/C for pre-defined time lets say 30mins,and off for other 30 mins ,to do this i taken code of IR decoder with which i can get the Power on/off key values,the array is the decoded value in void loop(),reading this array to turn onA/C.Kindly guide me how to turn off A/c after pre-defined time

Your code was too detailed to make sense of and this description is too general.

I am tempted to say all you need (based on the above quote) is something like

digitalWrite(acPIN, HIGH);
delay(30mins);
digitalWrite(acPIN, LOW);
delay(30mins);
repeat

but I suspect it needs to be more complex.

May I ask for a second time, what are all the pairs of numbers for ?

...R

May I ask for a second time, what are all the pairs of numbers for ?

// This is the code I determined works for my Duraflame heater
int IRsignal[] = {
// ON, OFF (in 10's of microseconds)

Regarding Reply #6 ...

@AWOL, that may make sense for you, but alas, not for me.

...R