Find all your DIY electronics in the MakerShed. 3D Printing, Kits, Arduino, Raspberry Pi, Books & more!


I do a lot of traveling by car, and I usually end up staying in whatever motel is nearest the interstate when I start to feel tired. Often I find that the room has an inexpensive TV that doesn’t have a sleep-timer function. So I created the TV-Go-Sleep, a timer that turns off any TV, after whatever delay time I command. You can build it in an afternoon.

The timer is built around an Arduino microcontroller that’s been loaded with an open source TV-B-Gone library and a few lines of my own code. A simple pushbutton is used to set the delay time, which is shown on a 7-segment display. When the timer expires, the Arduino uses infrared LEDs to transmit all the TV “off” codes it knows, and the TV shuts down. Good night!


Step #1: Install the header pins.

TV-Go-Sleep Universal TV TimerTV-Go-Sleep Universal TV TimerTV-Go-Sleep Universal TV Timer

Break off 3 blocks of male header pins and install them in the female headers on the Arduino: a 7-pin block in pins GND through 8, a 5-pin block in pins 6 through 2, and a 4-pin block in pins 5V, GND, GND, and Vin.

Step #2: Mark and cut the circuit board.

TV-Go-Sleep Universal TV TimerTV-Go-Sleep Universal TV TimerTV-Go-Sleep Universal TV TimerTV-Go-Sleep Universal TV Timer
  • Fit the perf board over the header pins, with its bottom (copper side) facing the Arduino. Sometimes an Arduino’s headers aren’t lined up perfectly, so you may have to work the board back and forth to get your pins to fit through the holes.
  • Mark the board where the pins extend through, then trim the board so it’s a little smaller than the Arduino beneath it. Leave 1–2 extra rows of holes at each end of the board.
  • Test fit, then remove the perf board. Remove your header pins from the Arduino.

Step #3: Build the circuit.

TV-Go-Sleep Universal TV Timer
  • Solder the circuit on the perf board according to the schematic diagram.
  • Use the 560Ω resistors for the connections to the LED display. The Arduino’s pin 13, used for an all-purpose indicator light, is connected to the decimal point on the display.
  • Pin 11 isn’t used because it’s a PWM pin that shares a timer with pin 3. The TV-B-Gone program uses this timer to create the remote control signals on pin 3, but it accesses the clock directly to increase speed. As a result, an LED attached to pin 11 would flicker when the codes are being sent.
  • The 33Ω resistor controls the current flowing through the 3 infrared LEDs. I chose its value to maximize brightness and service life. A higher resistance will decrease their range; a lower one will shorten their lifespan.
  • Pin 2 has 2 connections: to ground via the 10kΩ resistor, and to the Arduino’s 5-volt reference pin via the pushbutton. When the button is not being pushed, pin 2 is grounded and the input is in the off (or “false”) state. When the button is pushed, the pin is connected to the 5V reference potential, so its state is read as on (or “true”). The 10kΩ resistor limits the current flowing between the 5V and GND pins.

Step #4:

TV-Go-Sleep Universal TV TimerTV-Go-Sleep Universal TV TimerTV-Go-Sleep Universal TV TimerTV-Go-Sleep Universal TV Timer
  • Insert the headers from the bottom of the perf board (the copper side) and solder their connections on the top (the component side), as shown in the first 2 photos here. Use a hot iron and melt just enough solder to get a good connection — if you use too much you’ll end up shorting pins together. It may be helpful to insert the header pins in a breadboard and use bits of wire or masking tape to hold the resistor leads in place while soldering.
  • Insert the 7-segment display on the top of the board, midway between the 2 header rows. Make its connections on the bottom of the board, so you can solder the leads to each other and to the copper pad where they meet.
  • Cut longer wires for connecting the perf board to the switches and the infrared LEDs.
  • CAUTION: Don’t try to solder the headers while they’re installed in the Arduino. The heat could damage the microprocessor!

Step #5: Mount the infrared LEDs.

TV-Go-Sleep Universal TV TimerTV-Go-Sleep Universal TV TimerTV-Go-Sleep Universal TV TimerTV-Go-Sleep Universal TV Timer
  • Drill 3 holes in one end of the enclosure and insert the 3 infrared LEDs so they can be wired in series: anode-to-cathode-to-anode-to-cathode. The anode is the longer lead.
  • Why 3 LEDs? Their lenses focus the IR light into a fairly narrow beam, so adding more LEDs increases the likelihood that one of the beams will reach the TV’s IR receiver. Don’t make them perfectly parallel; let the lenses point in slightly different directions.
  • Drip some hot glue on the backs of the LEDs to hold them in place, and then solder them in series.

Step #6: Mount the switch.

TV-Go-Sleep Universal TV TimerTV-Go-Sleep Universal TV TimerTV-Go-Sleep Universal TV TimerTV-Go-Sleep Universal TV Timer

In the opposite end of the enclosure, make a hole and install your on/off switch.

Step #7: Mount the display.

TV-Go-Sleep Universal TV TimerTV-Go-Sleep Universal TV TimerTV-Go-Sleep Universal TV Timer
  • In the enclosure’s lid, make a rectangular hole for the 7-segment display. The Arduino just barely fits within the width of the RadioShack enclosure, so check the alignment carefully before you start cutting. Leave room for a hole for the pushbutton switch, preferably below the display. Go ahead and cut that hole now too.
  • Insert the display through the rectangular hole and mount the board under the lid with double-stick tape. Install the pushbutton.
  • Solder the leads from the perf board to the switches and IR LEDs. Note that the on/off switch interrupts the ground side of the battery. I did it this way to provide an easy grounding point for the infrared LEDs. Hot-glue the battery clip in the bottom of the case
  • TIP: Masking tape makes it easier to see pencil marks on the lid, and provides a little protection from stray tool marks as well.

Step #8: Install and program the Arduino.

TV-Go-Sleep Universal TV TimerTV-Go-Sleep Universal TV TimerTV-Go-Sleep Universal TV Timer
  • Install the Arduino on the header pins. Be sure to line it up properly!
  • Use a USB cable to connect the Arduino to a computer. Download the Universal Sleep Timer Arduino code, and the TV-B-Gone for Arduino library (main.h and WORLDcodes.cpp), as a zip file here. Open the files in the Arduino IDE and upload them to the device.

Step #9: Close it up and log some tube time.

TV-Go-Sleep Universal TV TimerTV-Go-Sleep Universal TV TimerTV-Go-Sleep Universal TV Timer
  • Disconnect the USB cable, install the 9V battery in the enclosure, and screw the lid in place. I used double-sided tape to attach the instructions to the lid of the box.
  • When you turn on the power switch, the decimal point will flash a few times, and then the display will read “9.” This corresponds to a sleep delay of approximately 90 minutes. Each time the button is pushed, the sleep delay is shortened by roughly 10 minutes.
  • If you press and hold the button, the TV-Go-Sleep goes into test mode, and it will begin sending all of its “off” codes.
  • Place the device where you plan to leave it for the night, and run the test to verify that the TV turns off. If the TV is still on when the test is finished, try realigning the device or moving it closer to the television set.
  • If the TV goes off and then comes back on, it must be responding to 2 different codes being transmitted from the timer. If that should happen, run the test again, but be ready to press the button when the TV turns off. This will stop the test at that point. Later, when you’re asleep and the timer runs down, the device will only send codes until it reaches the point where you stopped the test.
  • If you can’t get the TV to turn off, then its code may not be in the TV-B-Gone library. Check back at for updated libraries.
  • Thanks to Donal Morrissey for showing how to put the Arduino into a low-power mode ( And special thanks to Ken Shirriff, who created the Arduino TV-B-Gone code ( that’s the backbone of this project.


  1. Ian says:

    I have a problem vith the code it says IRLED was not declared and much more errors like that.

  2. Eloy Salinas says:

    Sounds like a needed library file was not #included

  3. Tom Rodgers says:

    I’m glad to see people are trying this build, but I’m sorry it’s not working for everyone!

    The IRLED variable is defined (along with several others) in the “main.h” file, which needs to be “#includ”-ed when the “Universal_Sleep_Timer_Arduino_Code” sketch is compiled. As written, the code does not include a path to that header file, so it should be in the same directory as Universal_Sleep_Timer_Arduino_Code. That will probably solve all of the “[whatever] not declared” errors at once.

    It’s difficult to know what sorts of issues might be arising from the different configurations of different peoples’ computers. The code worked fine for me, of course, but someone else may have their directory tree or default file locations arranged differently.

    I can’t be sure without looking at Ian’s computer, but I think putting “main.h” in the same directory as the sketch itself should take care of this…

    1. aaron says:

      i tried that and it just said “error compiling” can you help?

  4. jalela balkrushna says:

    show some other project

  5. jalela balkrushna says:

    give information about arduino based home automation project

  6. Dmitriy Kovalenko says:

    Can’t compile the code for Arduino Mega 2560… Compiler gives an error “Huh?..Bootloader” and it seems it won;t compile nothing until I change the Arduino board… Please help…

    1. Tom Rodgers says:

      Hmmm – I would like to help, but I’ve never had this problem…

      I’ve seen the program work on a Duemilanove, an Uno, a Mega, and an Ardweeny, and a stand-alone ATMega 328 (which is more-ore-less the same thing as an Ardweeny).

      As you probably know, it sometimes takes some trial and error to get the right combination of board, com-port, and baud rate. Have you used this specific board before, or is it possible that the problem is actually with the hardware?

      Are you getting a message that there is a problem with your bootloader or with the avrdude?

  7. Catwalk803 says:

    This item could solve a lot of problems in our house. However, we are not techies and don’t pretend to be. Bottom line, can you sell me one premade? Boyfriend refuses to purchase a new tv because the SLEEP button is too many steps for him and he uses it on/of during sleep periods. Help please!

    1. aaron says:

      sure how much we talking?

In the Maker Shed