Aug 31st 2017
Know How... 341
IR Basics Part 1
Repurpose your old remote controls.
Basics of IR Control
IR control is a BINARY communications system
- It uses a series of "0" and "1" (off or on) to convey a value from a transmitter to a receiver
- The "Transmitter" is an IR LED and the "Receiver is a photosensitive element that responds to IR light"
- However... just being able to "see" if the IR LED is lit doesn't allow us to communicate.
- We need to have a "protocol" that defines how long a "control sequence" is and how to read it.- In other words, I need to know when the sequence starts, and when it ends.
We're going to use the "IRremote" library which understands most of the POPULAR protocols
Demo of Reading IR Codes
- Show Interface
- Show codes
- Show Hardware
Let's Assemble the hardware!
Parts
- IR Receiver (AX-1838HS) and LED
- Arduino Nano
Pinout of the IR Receiver
From left to right, looking at the front of the sensor
- Out
- GND
- VCC
Let's Program!
- First, we need to include the "IRremote" Library
- Sketch > Include Library > Manage Libraries
#include <IRremote.h> // This is the library we need to speak IR protocols
#define IR_PIN 2 // The digital pin to which the IR Reciever is connected
IRrecv irrecv(IR_PIN); // Turn on the reciever
decode_results ircode; // Create a structure called "IRcode"
void setup()
{
Serial.begin(9600); // Start the Serial Port (for debug)
irrecv.enableIRIn(); // Start the receiver
}
void loop()
{
if (irrecv.decode(&ircode)) // IF the IR reciever has received a code, THEN run the following:
{
Serial.println(ircode.value, HEX); // Print the received code to the Serial Port (for Debug)
irrecv.resume(); // Wait for the next IR code
}
}
** This code is a basic IR code reader. It will receive an IR code from a remote, then print it to the serial console
Now that we know we can receive IR codes w/our Nano, let's DO something with it!
Code for this Episode can be found at the link below:
https://www.dropbox.com/s/qf0htfgfo5de9zb/KH341_IR.zip?dl=0
Connect with us!
- Don't forget to check out our large library of projects at https://twit.tv/shows/know-how.
- Join our Google+ Community.
- Tweet at us at @PadreSJ and @Anelf3.
Thanks to CacheFly for the bandwidth for this show.