Anda di halaman 1dari 14

Food

Living

Outside

Play

Technology

Workshop

Control Any Circuit With a TV Remote (and an Arduino)


by DIY Hacks and How Tos on March 18, 2014

Table of Contents
Control Any Circuit With a TV Remote (and an Arduino) . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .

Intro: Control Any Circuit With a TV Remote (and an Arduino) . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .

Step 1: Materials . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .

Step 2: Download and Install the IR Remote Library . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .

Step 3: The Arduino Code . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .

Step 4: The Circuit . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .

Step 5: Test the Circuit on a Breadboard . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .

Step 6: Solder the Circuit Together on a Printed Circuit Board . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .

Step 7: Mount the Circuit in an Insulated Housing . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .

Step 8: Use Your Remote Controlled Switch to Activate Appliances and Other Electronics . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .

Step 9: Manually Insert IR Values into the Arduino Code (optional) . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .

Related Instructables . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .

Advertisements . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .

Comments . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .

http://www.instructables.com/id/Control-Any-Circuit-With-a-TV-Remote-and-an-Arduin/

Author:DIY Hacks and How Tos

DIY Hacks & How Tos on YouTube


Jason Poel Smith: Inventor, Maker, Hacker, Tinker, and occasional Mad Genius

Intro: Control Any Circuit With a TV Remote (and an Arduino)


Most of the buttons on a remote control are never used. So why not use them to control appliances and other electronics around your house. In this project, I am going to
show you how to use an Arduino to decode the signal from your remote and use it to make an outlet switch that can turn your electronics on and off.
When you are done, you will be able to control lights, fans and even your coffee maker with your TV remote.

Step 1: Materials
Here are the materials and tools that you will need for this project:
Materials:
Arduino Microcontroller
AC Power Adapter For the Arduino
38 kHz Infrared Receiver Module (Radio Shack part# 276-640)
Red LED
Green LED
Momentary Pushbutton Switch
Two 100 ohm Resistors
10 kohm Resistor
Diode
5V Relay or Relay Shield
Printed Circuit Board
Plastic Project Housing
Extension Cord
Tools:
Wire Strippers
Soldering Iron and Solder
Drill and Bit Set
Sharp Knife
Hot Glue Gun

http://www.instructables.com/id/Control-Any-Circuit-With-a-TV-Remote-and-an-Arduin/

Step 2: Download and Install the IR Remote Library


This project uses an IR remote library that was developed by Ken Shirriff. This library lets you decode the signal coming from your remote. You can check out his original
project and setup here: http://www.righto.com/2009/08/multi-protocol-infrared-remote-library.html
The first thing that you need to do for this project is download the library zip file. You can find it here: https://github.com/shirriff/Arduino-IRremote
Click "Download ZIP" on the right side of the page and save the zip file. Then unzip it. Rename the folder "IRRemote" (unless that name is already being used).
Then copy the folder into your libraries directory. The libraries directory should contain the folder "IRremote." If for some reason you already have a folder with this name,
then you may need to rename it. The IRremote folder should contain the files. A lot of problems experienced when uploaded in the code, are caused be the library not
being loaded in the correct location.

Step 3: The Arduino Code


// Upload this code to your Arduino
#include <IRremote.h>
int RECV_PIN = 11;
IRrecv irrecv(RECV_PIN);
decode_results results;
unsigned long CurrentValue = 0;
unsigned long StoredCode = 0;
const int buttonPin = 6; // the number of the pushbutton pin
const int ledPin = 4; // the number of the LED pin
const int outputPin = 3; // the number of the output LED pin
const int relayPin = 2; // the number of the relay pin
int buttonState = 0; // variable for reading the pushbutton status
int RecordState = 0; //is the reciever in record mode
int outputState = 1; //is the output on or off
void setup()
{
Serial.begin(9600);
irrecv.enableIRIn(); // Start the receiver
// initialize the LED pin as an output:
pinMode(ledPin, OUTPUT);
// initialize the pushbutton pin as an input:

http://www.instructables.com/id/Control-Any-Circuit-With-a-TV-Remote-and-an-Arduin/

pinMode(outputPin, OUTPUT);
// initialize the pushbutton pin as an input: pinMode(buttonPin, INPUT);
pinMode(relayPin, OUTPUT);
// initialize the pushbutton pin as an input: pinMode(buttonPin, INPUT);
}
void loop() {
// read the state of the pushbutton value:
buttonState = digitalRead(buttonPin);
// if a signal is detected, store the value
if (irrecv.decode(&results)) {
CurrentValue = (results.value);
// if the recieved value equals the programed value, then toggle the output state
if(CurrentValue == StoredCode) {
outputState = !outputState;
}
// if the record mode is activated store the current value as the programed value
if (RecordState == 1) {
StoredCode = CurrentValue;
RecordState = 0;
digitalWrite(ledPin, LOW);
Serial.println(StoredCode); //displays stored code for reference
}
// Receive the next value
irrecv.resume();
}
else //if no signal is detected, then the current value is 0
{
CurrentValue = 0;
}
// check if the record button is pressed.
// if it is, the buttonState is HIGH:
if (buttonState == HIGH) {
//wait for the button to be released
while (buttonState == HIGH) {
buttonState = digitalRead(buttonPin);
}
//turn on the LED to indicate that record mode is on
digitalWrite(ledPin, HIGH);
RecordState = 1;
}
//set the appropriate output state
if(outputState == 1) {
digitalWrite(outputPin, HIGH);
digitalWrite(relayPin, HIGH);
}
else {
digitalWrite(outputPin, LOW);
digitalWrite(relayPin, LOW);
}
}

http://www.instructables.com/id/Control-Any-Circuit-With-a-TV-Remote-and-an-Arduin/

Step 4: The Circuit


This circuit uses a 38 kHz Infrared Receiver Module to detect the signal from the remote. The right pin of this connected to 5V. The middle pin is connected to GND. The
Left pin connects to digital pin 11 on the board.
The circuit also has two indicator LEDs. One indicates that the receiver is in programming mode and the other indicates whether the output is on or off. One end of each
LED is connected to GND. The other end is connected to a 100 ohm series resistor. The resistors are then connected to digital pins 3 and 4.
A momentary switch is used to set programming mode. One end of the switch is connected to 5V. The other end of the switch is connected to digital pin 6 and a 10 kohm
resistor. The other end of the resistor is connected to GND.
An optional relay/relay shield can be connected to digital pin 2 and GND.
You can add any additional outputs that you want. This can let you control multiple devices or multiple functions on the same device.

Step 5: Test the Circuit on a Breadboard


It is always a good idea to test your circuit on a breadboard before soldering it together.
When the Arduino is powered, the output indicator (green) LED should turn on. This indicates that the output at pin 2 is HIGH and can be used to activate another circuit.
To program the receiver, press the button. When the button is released, the programming mode indicator (red) LED will turn on.
Now point your remote at the receiver module and press a button. If the Arduino registered the signal, the programming mode LED will turn off. The receiver is now
programmed. Pressing this button on the remote again will cause the output at pin 2 to toggle between off and on. The output state is indicated by the LED.
You can use the signal from pin 2 to activates another circuit directly or you can use a relay/relay shield to turn an appliance on and off.
If you connect the Arduino to your computer you can use the serial monitor function to observe the value for the signals that you are programming.

http://www.instructables.com/id/Control-Any-Circuit-With-a-TV-Remote-and-an-Arduin/

Step 6: Solder the Circuit Together on a Printed Circuit Board


After testing the circuit on a breadboard, you can solder it together on a printed circuit board. The IR receiver module, the switch and the LEDs would be mounted to the
housing. So I connected them to the board with jumper wires.
I added a small relay that would be activated by the output of pin 2. In most cases you will want to connect a relay driver circuit. This is because the maximum output of
an Arduino digital pin is 40 mA and most relays require more than this to operate. However, I found a relay that only required 25mA to operate. So I was able to connect it
directly to the digital pin. It is always a good idea to attach a flyback diode across the terminals of the coil of a relay. This helps to protect against voltage spikes when the
relay is turned off.
The relay can act as a general switch and activate just about anything. In this case, I attached an extension cord. This will allow it to act as a remote controlled outlet.
Always check to make sure that your relay is rated high enough for your intended load.

Step 7: Mount the Circuit in an Insulated Housing


Now you need to find a good insulated housing to hold your project. I used a 6x3x2 plastic project housing from RadioShack. On one end, I drilled two holes from the
LEDs, one hole for the IR receiver and one hole for the switch. Then I made holes in the opposite end for the Arduino power cord and the extension cord.
I used hot glue to secure the LEDs and the Receiver. The switch was held in place with its own nut and lock washer. You can also use hot glue to secure loose wires and
to hold the boards in place.
Be very careful not to accidentally pull any wires out of the Arduino as you are fitting everything into the housing.

http://www.instructables.com/id/Control-Any-Circuit-With-a-TV-Remote-and-an-Arduin/

Step 8: Use Your Remote Controlled Switch to Activate Appliances and Other Electronics
Plug in the power supply for the Arduino and it will automatically turn on. Then plug the male end of the extension cord into an outlet and plug the device that you want to
control into the female end of the extension cord. The device should turn on.
To program the receiver, press the red button. The red light will turn on. Then point your remote at the receiver and press a button. If the Arduino registered the signal,
then the red light will turn off. Now you can use that button to turn the attached device on and off.
You can use this to remotely control lights, fans or even your coffee maker.

http://www.instructables.com/id/Control-Any-Circuit-With-a-TV-Remote-and-an-Arduin/

Step 9: Manually Insert IR Values into the Arduino Code (optional)


If you plug the Arduino into your computer, you can use the Serial Monitor tool to view the value of the IR signals for the various buttons on your remote. This gives you
the option of manually inserting these values into the code. By doing this you can program responses to multiple buttons. It also means that you will not have to
reprogram the receiver whenever the power is disconnected.

Related Instructables

Invisible
Signally Beacon
(Infrared LED
Throwie) by DIY
Hacks and How
Tos

Remote
Controlled
Arduino Infrared Balloon Pop
Remote tutorial Prank by DIY
by astrodan3
Hacks and How
Tos

Remote Kill
Switch by DIY
Hacks and How
Tos

Create External
Buttons For
Your Keyboard
by DIY Hacks
Infrared(IR)
remote operated and How Tos
switch (video) by
buildcircuit

http://www.instructables.com/id/Control-Any-Circuit-With-a-TV-Remote-and-an-Arduin/

Advertisements

Comments
47 comments Add Comment

JasonC2 says:

Aug 10, 2014. 3:26 PM REPLY

Can anyone tell me what relay and diode you used?

jorgez661 says:

Aug 11, 2014. 12:45 PM REPLY

Here's the schematic I used based on the one included in this guide.

jorgez661 says:

Aug 10, 2014. 4:18 PM REPLY

This is the relay I used however you might need a transistor to get it to work
https://www.sparkfun.com/products/100
And pretty much any diode will do, I used this one
https://www.sparkfun.com/products/8589

jorgez661 says:

Jul 15, 2014. 1:36 PM REPLY


Great project! I made one but I removed the button on the final case after modifying the code to work with the remote I wanted. I also added a second relay
to which I plan on adding a second outlet later on!

jorgez661 says:

Aug 10, 2014. 1:24 PM REPLY


Made two final modifcations, replaced the arduino with a barebones arduino that I made using another instructable, and replaced the end of the
extension cord with two separate plug-ins mounted on the side of the case. Each of the plug-ins is wired to its own relay so basically it can remote control
two outlets. Thanks again to the DIY Hacks and How for this great Instructable!

http://www.instructables.com/id/Control-Any-Circuit-With-a-TV-Remote-and-an-Arduin/

jorgez661 says:

Jul 15, 2014. 1:40 PM REPLY


For anyone else making this project, I highly recommend PCB screw terminals to wire the extension cord into. It makes attaching the wires a lot easier
that way.

cnguyen37 says:

Jul 8, 2014. 3:19 PM REPLY

For some reason, the red LED for me will not turn on when i press the button.

DIY Hacks and How Tos says:

Jul 8, 2014. 4:36 PM REPLY


First make sure that the LED works and is the correct voltage. Then check to make sure that it is plugged into the correct pin. Then check all the other
parts.

cnguyen37 says:

Jul 8, 2014. 5:38 PM REPLY


I'm pretty sure everything is ok. Here's a picture. I'm not the best with circuit diagrams so I'm not sure if anything needs a fix.

cnguyen37 says:
Sorry, here's a better picture

http://www.instructables.com/id/Control-Any-Circuit-With-a-TV-Remote-and-an-Arduin/

Jul 8, 2014. 5:43 PM REPLY

DIY Hacks and How Tos says:

Jul 9, 2014. 6:29 AM REPLY


Your button doesn't appear to be connected to 5V. One side of the switch needs to be connected to 5V and the other side to the resistor and
the input pin.

cnguyen37 says:

Jul 9, 2014. 3:41 PM REPLY


Now the LED turns on but not the green one. Do you know why? The button is connected to the 5V and the digital pin 6 and the resistor. But
now the green LED won't turn on.i kept the wiring the same except I moved the button to the positive side, connecting to the 5V

DIY Hacks and How Tos says:

Jul 10, 2014. 6:47 AM REPLY


The green light should come on when it recognizes the code from the remote. Try using a different remote.

jhong2388 says:

Jun 6, 2014. 11:53 PM REPLY

5V Relay Module for Arduino


can i use this relay?

DIY Hacks and How Tos says:

Jun 7, 2014. 4:07 AM REPLY

Yes. As long as the appliance is rated for less power than the relay is rated for.

jhong2388 says:

Jun 7, 2014. 11:13 PM REPLY

does this relay need some circuit boarding or adding diode or somthing?

DIY Hacks and How Tos says:

Jun 8, 2014. 10:19 AM REPLY


It appears to have the power transistor and the diode are already built it. You need to check to make sure that the power that is required by the
relay is less that the max output for the Arduino pins. Otherwise you will need an external power source.

jhong2388 says:

Jun 8, 2014. 9:22 PM REPLY

it is ok if i plug my uno overnight?

DIY Hacks and How Tos says:

Jun 9, 2014. 7:15 PM REPLY

You can look up the power ratings for each board on the Arduino website
http://arduino.cc/en/Main/arduinoBoardUno
For an UNO it is 40mA per pin

DIY Hacks and How Tos says:

Jun 9, 2014. 3:36 AM REPLY

Yes. It is ok to leave your Arduino plugged in over night.

jhong2388 says:
if i add 2 servo for my curtain it is still ok to turn on 24/7

http://www.instructables.com/id/Control-Any-Circuit-With-a-TV-Remote-and-an-Arduin/

Jun 9, 2014. 4:12 AM REPLY

DIY Hacks and How Tos says:

Jun 9, 2014. 8:53 AM REPLY

As long as you don't exceed the maximum output rating, it should be fine.

jhong2388 says:

Jun 9, 2014. 9:25 AM REPLY

whats the maximum output rating?


how to know if i exceed?

Isanch99 says:

Apr 1, 2014. 8:38 PM REPLY


What do you do if this pops up when you're uploading the code on the Arduino 'IRecv' does not name a type > DIY Hacks and How Tos

DIY Hacks and How Tos says:

Apr 2, 2014. 3:31 AM REPLY

Check to make sure that the library is loaded properly.

Isanch99 says:

Apr 6, 2014. 12:30 PM REPLY

I checked that the library was loaded correctly and it still can't verify it

DIY Hacks and How Tos says:

Apr 7, 2014. 5:07 AM REPLY

Sorry. I don't know what is wrong then.

Carlitos317 says:

Mar 29, 2014. 12:24 PM REPLY


I have an arduino uno r3 smd edition with arduino 1.0.5-r2 and when I try to upload the code it says 'iRrecv' does not name a type and doesnt upload it plz
help

DIY Hacks and How Tos says:

Apr 2, 2014. 3:39 AM REPLY

Check to make sure that the IR remote library is loaded in the libraries directory correctly.

Isanch99 says:

Apr 1, 2014. 8:54 PM REPLY

error: 'TKD2' was not declared in this scope It said this when I tried to upload the code to the Arduino? DIY Hacks and How Tos

Isanch99 says:

Apr 1, 2014. 8:54 PM REPLY

error: 'TKD2' was not declared in this scope It said this when I tried to upload the code to the Arduino? DIY Hacks and How Tos

stumitch says:

Mar 31, 2014. 8:19 AM REPLY


Nice, clear description of an idea that uses a remote that everyone will have somewhere in their house. If you want to, try http://teachables.org/arduinowithout-the-board to build the project and not have to sacrifice an Uno. Thanks for such a great 'ible!

afioramanti says:
awesome, Congrats. The IR need short distance is there a way to try with with ethernet shield?

http://www.instructables.com/id/Control-Any-Circuit-With-a-TV-Remote-and-an-Arduin/

Mar 31, 2014. 4:21 AM REPLY

toplak666 says:

Mar 31, 2014. 12:26 AM REPLY

Or use one of these: http://www.simerec.com/chips.html Cheaper and easier. No coding required. Still, good project though.

freakyfreak7 says:

Mar 30, 2014. 5:25 AM REPLY

This looks like it could be adapted to control an entire room with one arduino.

DIY Hacks and How Tos says:

Mar 30, 2014. 4:41 PM REPLY


Yes. You can control as many relay devices as you have digital output pins. Just remember to stay under the board's max output current.

steinie44 says:

Mar 30, 2014. 2:59 PM REPLY


I made a remote control for my TV input for my DVR and Arduino TVout. It's about the same as yours only has RCA jacks in it. Works like a champ. Next I'll
make one to control 4 inputs to the TV. I'll use a Arduino Pro Mini, only $5.00.

vroom350 says:

Mar 30, 2014. 1:43 PM REPLY


Great idea! But IR need sight short distance, rather use device socket plug CleverWatt 433Mhz rest no make, just Arduino with TX and RX 433Mhz module can
scan remote, and still with IR stay with you use TV Remote area in like lounge room.

chuckvideo says:

Mar 29, 2014. 8:20 AM REPLY


I now know how I'll be spending my day today, this project is both amazing and simple to build and set up! And I bet it'll work perfectly with the Power Tail AC
switch I bought a while back but didn't know how to use until now. https://www.sparkfun.com/products/10747

DIY Hacks and How Tos says:

Mar 29, 2014. 4:07 PM REPLY

That kind of switch should work perfectly.

danamoose says:

Mar 28, 2014. 3:25 PM REPLY

Great project, nicely done!

samuraijack says:

Mar 28, 2014. 12:15 PM REPLY

awesome.

ade angelis says:

Mar 28, 2014. 2:01 AM REPLY


This is a really nice project, thanks for sharing. I have a problem though: I downloaded the library and copied the code as reported above, yet I get this error.
It'd be great if you could help! Thank you! :)

DIY Hacks and How Tos says:


There is a problem with how the library is set up.

http://www.instructables.com/id/Control-Any-Circuit-With-a-TV-Remote-and-an-Arduin/

Mar 28, 2014. 3:33 AM REPLY

ade angelis says:

Mar 28, 2014. 5:21 AM REPLY

Ok, problem solved, thank you! :)

techie54 says:

Mar 27, 2014. 11:36 AM REPLY

Do you think this would work with an ATTiny85 or a smaller ATmega?

DIY Hacks and How Tos says:


It should work as long as you can load the appropriate libraries.

http://www.instructables.com/id/Control-Any-Circuit-With-a-TV-Remote-and-an-Arduin/

Mar 27, 2014. 12:13 PM REPLY

Anda mungkin juga menyukai