i just started working with an IR receiver and i used an example online that showed me how to read the IR signal from a remote. I will be honest i didn't understand how it all worked. I don't really need to see the signal on the serial monitor. I am just trying to use it as a on/off switch for a led. I messed around with the button example and tried to get it to trigger of any IR reading but i cant seem to figure it out. Thanks in advance!
Hi Ethanmo43,
It's usually a good idea to start by reading things on the serial monitor, because it lets you know where your problem is if your sketch doesn't work. If you're successfully reading the signal you need, then the trick is to hook this up to an output -- in this case your LED. The easiest way to do this is to connect your LED via a resistor to one of the digital pins on your Arduino, specify it as an output and use the digitalWrite function to turn it on and off. The reference section under the 'learning' tab can help you with this.
If you need more help than that, you'll have to post up your code and a circuit diagram so we can see what you're doing ![]()
The IR receiver is probably a 38kHz receiver. So, its output goes low (or high) when it "sees" a 38kHz flashing light. You could use an IR LED on an output pin driven with Tone at 38kHz as your light source.
thanks for the reply. I did get it to read a remote and show up on my serial monitor. the problem is i used someone else's code and it seems like it is reading the signal pattern and all these numbers show up every time i use the remote, also the code i used has so much going on i got lost. thanks for the help i should be able to figure it out with what you have told me.
You'll probably want to read through A Multi-Protocol Infrared Remote Library for the Arduino.
That's from the IRLib exemple.
You can dump the code of your remote. Just open the Serial monitor and press a key on any remote.
file/exemples/IRLib/Dump ...
#include <IRLib.h>
//Create a receiver object to listen on pin 11
IRrecv My_Receiver(10);
//Create a decoder object
IRdecode My_Decoder;
void setup()
{
Serial.begin(9600);
My_Receiver.enableIRIn(); // Start the receiver
}
void loop() {
//Continuously look for results. When you have them pass them to the decoder
if (My_Receiver.GetResults(&My_Decoder)) {
My_Decoder.decode(); //Decode the data
My_Decoder.DumpResults(); //Show the results on serial monitor
My_Receiver.resume(); //Restart the receiver
}
}
that's my code that command my HTPC,
you can easily modify it with an other IR protocol and a Boolean to achieve your goal.
#include <IRLib.h>
#include <Keyboard.h>
#define MY_PROTOCOL RC6 // Remote QNAP-IR002 Protocol RC6
IRrecv My_Receiver(10); //IR Sensor on Pin 10
IRdecode My_Decoder;
void setup()
{
My_Receiver.enableIRIn(); // Start the receiver
Keyboard.begin();
pinMode(2, OUTPUT);
}
void loop()
{
while(!My_Receiver.GetResults(&My_Decoder)) // try to accelerate the process
{
}
My_Decoder.decode();
if(My_Decoder.decode_type==MY_PROTOCOL)
{
switch(My_Decoder.value)
{
case 0x800F040C: power(); break; // dumped ir code linked to an action // call the function power
// ...
// ...not relevant to you
// ...
}
delay(170);
}
My_Receiver.resume();
}
void power() //trigger the optocoupleur to shorten the power-switch and then turn ON/OFF the computer
{
digitalWrite(2, HIGH);
delay(500);
digitalWrite(2, LOW);
}
Best luck.