What Our Circuit Will Do
The circuit will detect when a button, any button, from a remote control is pressed and let us know through the serial port.
Parts Required
I used:
- Sparkfun’s IR Receiver Diode
- 1uF capacitor
- 47 ohm resistor
The circuit was pretty easy to set up, I just followed the receiver’s datasheet. The schematic is below.
How The Infrared Receiver Works
The pictures below were taken with an oscilloscope, they are the output of the receiver.
The output of the receiver is normally approximately 5 volts.
If an infrared signal is present the output is 0v, each remote key makes the IR light in the remove turn on and off producing a square wave at the output of the receiver diode.
Next is a close up of the signal above.
Infra Red Receiver Code
We won’t be differentiating between signals from each remote key, instead we just want to know when a button is pressed. Since the signal is normally 5v (HIGH), when a button is pressed the signal changes to 0V (LOW), since each key produces several ups and downs we are going to wait for about 50ms (your remote might need more, just test different values) so that we let the signal rest back up to HIGH again.
int irPin=2; void setup() { pinMode(irPin,INPUT); Serial.begin(9600); } void loop() { if(pulseIn(irPin,LOW)) { //button pressed delay(100); Serial.println("You pressed a button"); } }
This is what you should get from the serial monitor every time you press a key in your remote.
What are you planning to do with infrared? leave your comments or questions below.