Go Down

Topic: ir relay control (Read 1 time) previous topic - next topic

aouate3

trying to get 3 relays to be controlled through a ir reciever connected to a arduino, but my code is flawed, it wont compile, and im probbaly doing it wrong anyway...

need the following hex codes recieved from the  remote to do the following

801 - turn on relay one

802 - turn off relay one

803 - turn on relay two

804 -turn off relay two

805 - turn on relay three

806 - turn off relay threee

here is my code

Code: [Select]

// example 32.1 - IR receiver code repeater
// http://tronixstuff.com/tutorials > chapter 32
// based on code by Ken Shirriff - http://arcfn.com
#include <IRremote.h> // use the library
int receiver = 11; // pin 1 of IR receiver to Arduino digital pin 11
IRrecv irrecv(receiver); // create instance of 'irrecv'
decode_results results;
void setup()
{
  Serial.begin(9600); // for serial monitor output
  irrecv.enableIRIn(); // Start the receiver
  pinMode(13, OUTPUT); // sets the digital pin as output
pinMode(4, OUTPUT); // sets the digital pin as output
pinMode(7, OUTPUT); // sets the digital pin as output
}
void loop()
{
  if (irrecv.decode(&results)) // have we received an IR signal?
  {
    Serial.println(results.value, HEX); // display it on serial monitor in hexadecimal
    irrecv.resume(); // receive the next value
  }  // Your loop can do other things while waiting for an IR command
  int (results.value)=80;
if (irrecv.decode(&results))0)
{
/* Here we wait for the first byte of a two byte control sequence. Send A, B or C to control filterpump,boosterpump, light, or blower.
*/
(irrecv.decode(&results))
if (!have_control)
{
have_control=true;

control_relay=12;
else if (results.value=='801')
control_relay=13;
}

// We have the control byte, now lets look for 1 or 0
if (results.value=='801')
{
// Turn specified relay on

if (control_relay==13)
state_SpaLight=HIGH;
}
else if (results.value=='802')
{
// Turn specified relay off

if (control_relay==13)
state_SpaLight=LOW;
}

else if (serial_byte=='?')
{


// This is where we issue our actual pin state to the arduino digital pins

digitalWrite(13, state_SpaLight);
}
 
}
}


i seriously have no idea what im doing, someone do this for me.. im going with hardware not software

PaulS

Quote
it wont compile,

And there errors are?

Code: [Select]
if (irrecv.decode(&results))0)
This is one of the problems lines, I'd bet. You need to look at the documentation for the irrecv.decode() function to see what you are supposed to pass to the function. Almost certainly, the 0 does not belong there.

Code: [Select]
control_relay=12;
else if (results.value=='801')

The else statement needs to follow of if statement, or if block, not some random statement.

'801' is a multi-byte character constant. While not syntactically wrong, multi-byte character constants are not supported on the Arduino.

Where is control_relay declared?

Quote
i seriously have no idea what im doing, someone do this for me.

Then they are not doing it right. Delete most of that code. Get the data from the IR, and print out the decoded results. NOTHING ELSE until that works.


aouate3

yea, with a philips remote, i got werid codes, but i used a hitachi remote, and i got hex codes that make more sense, ill post them later, but first i have to figure out whats work with my arduino IDE....

ill post the picture, this started happening the other day, and i tried redownloading the IDE twice, it doesnt fix the problem, anyone seen this before?
if it helps, im running windows seven ultimate 32-bit, 2.8 gigs of ram, all drivers are up to date, not sure about java, i think the IDE uses java, could that be the problem, also this started happening when i used a sony remote with a ir detection sketch, as soon as i tried the sony remote with it, the arduino IDE started acting werid, also, when i tried the sony remote, on the serial monitor window, a odd message super-imposed itself on the window, saying something about the buad rate and protocall, which is odd, because the ir detector sketch didnt decode the ir, just said when it was recieved...

very odd.. and concerning... and yes, i did try restarting my computer... no i will not call a support line and be forced to talk to someone from a 3rd world country that cant speak english, and yes, my computer is plugged in, i do have a keyboard and mouse connected, and no, there is not blue screen showing up, lol, sorry, bad phone support memories.... lol..

also, that black text skewed across in the window, i believe that is part of the message i recieved when i tried the sony remote..

no im not joking about this, not trying to troll you, didnt photoshop this, IM SERIOUS, AND THIS IS ACTUALLY HAPPENING!!


Big Oil

I used a Phillips to control a relay using the same library. 
http://www.arduino.cc/cgi-bin/yabb2/YaBB.pl?num=1279084882  The 'lamp code' uses a relay.  I had to use a weird 'codeValue' variable to get it to work with the Phillips remote.
I think something is wrong about where you placed:  irrecv.resume() .  It should be at the end, after you switch the relays on or off.

Go Up