Improved Arduino TV-B-Gone

Oct 2016: An updated version of the code is on github, thanks to Gabriel Staples.

The TV-B-Gone is a tiny infrared remote that can turn off almost any TV. A while ago, I ported the TV-B-Gone software to the Arduino; for details on the port and how it works see my previous post on the Arduino TV-B-Gone.

Mitch Altman, the inventor of the TV-B-Gone, made some improvements to the code for a weekly TV-B-Gone constructing workshop in San Francisco at Noisebridge. If you're in the San Francisco area and are interested in the TV-B-Gone, you might want to check it out.

The main bug fix in the new version is the European codes will now work (if you ground pin 5). (The problem was a bunch of #ifdefs to fit the codes into the ATtiny's limited memory; taking out the #ifdefs fixed the problems.) Pressing the trigger button during transmission will now restart the codes. The delay between codes was increased, which should make transmission more reliable. The Arduino's processor will now sleep when not transmitting (thanks to ka1kjz). (Unfortunately, the rest of the Arduino components are still draining power, so sleep mode will be more useful with stripped-down Arduino variants.)

Important: the pins have been changed around in the new version (to avoid conflicts with the serial port). Pin 2 is now the trigger switch, Pin 3 is the IR output, and Pin 5 is grounded if you want European codes. If you built an Arduino TV-B-Gone before and want to use the new code, make sure you connect to the right pins.

Here's Mitch Altman's schematic for the Arduino TV-B-Gone (click for larger): Arduino TV-B-Gone schematic

To build the Arduino TV-B-Gone, follow the above schematic and download the sketch from github. My previous post on the Arduino TV-B-Gone has more information on wiring it up, if you need it.

58 comments:

  1. Nice article, thanks for the information.

    ReplyDelete
  2. I've tried several different IrLED's but they all do the same.
    They do a fade blink every now and then while it's spamming the codes.

    Any idea why? I have the Arduino Mega.

    ReplyDelete
  3. Thx for the nice conversion and upgrade. Version 1.2 runs fine on my arduino nano.

    (TV-B-Gone for Arduino version 0.001
    Ported to Arduino by Ken Shirriff, Dec 3, 2009
    http://arcfn.com
    The original code is:
    TV-B-Gone Firmware version 1.2)

    But :
    I have to set digital pin 5 floating to to turn my european phi**ips tv on and off (place germany/eu ;-); the tv was bought in germany). If i ground digital pin 5 my tv just switches channels several times during a single run.
    I tried this with a fet and a MOSFET (IRLU 2905) as driver for my IR LED ->no changes.
    Hardware for IRLU 2905:
    Source connected to GND,
    Gate connected to arduino out (digital pin 3) with 10 KOhm to ground to get a proper not floating MOSFET gate and
    Drain connected to IR-LED with 39 Ohm in series to VCC/+5Volt).
    This works for a distance of several meters and really large IR LEDs or several ;-).
    With a floating digital pin 5 everything works like it should. It toggles tv off or on with every single run, no channel switching. Just one single action per run.

    turbo_b. 28th of dec.2010

    ReplyDelete
  4. Thanks Ken

    Arduino TV B-Gone v 1.2 is running fine.

    I noticed that the "region blink", that the LED runs at first power up, is delayed by 3 seconds.

    I will report back the current draw on the ATmega in a few days.

    cheers!

    ReplyDelete
  5. How hard would this be to adapt to use Ladyada's setup with two narrow beams and two wide beams?

    ReplyDelete
  6. Do I have to use three AA batteries or can i just use a 9v? Thanks!

    ReplyDelete
  7. Anonymous1: the Arduino can take up to 12 volts input voltage: http://www.arduino.cc/en/Main/ArduinoBoardDiecimila

    Anonymous2: you can easily add 4 LEDs, but you'll need 5 transistors. See Ladyada's schematic for how to hook it up: http://www.ladyada.net/make/tvbgone/design.html

    ReplyDelete
  8. don't work i got error:
    TVB\WORLDcodes.cpp.o:(.progmem.data+0x0): multiple definition of `NApowerCodes'
    WORLDcodes.cpp.o:(.progmem.data+0x0): first defined here
    TVB\WORLDcodes.cpp.o:(.progmem.data+0x112): multiple definition of `EUpowerCodes'
    WORLDcodes.cpp.o:(.progmem.data+0x112): first defined here
    TVB\WORLDcodes.cpp.o:(.data.num_NAcodes+0x0): multiple definition of `num_NAcodes'
    WORLDcodes.cpp.o:(.data.num_NAcodes+0x0): first defined here
    TVB\WORLDcodes.cpp.o:(.data.num_EUcodes+0x0): multiple definition of `num_EUcodes'
    WORLDcodes.cpp.o:(.data.num_EUcodes+0x0): first defined here


    Please help this is so cool

    ReplyDelete
  9. @hippi97
    I get those errors if I (mistakenly) unzip to sketchbook/libraries. Moved it to just sketchbook and the errors went away. Maybe your problem?

    ReplyDelete
  10. Hey thank you for this port. I followed your design using a seeduino and it worked out better than expected. I get ~10m range at night. I built it into an old eyeglasses case and took it to the bars and had a lot of fun. Im using 4 AA's curently but a 9V doesnt seem to have enough (amps maybe?) to run the setup because the onboard led only flickers dimly and it doesnt seem to function. In order to make the whole thing smaller im probably going to use a smaller arduino and some AAA's.

    ReplyDelete
  11. please execuse me b/c i'm a newbie. in your hand sketch, there's a value of "47" above the resistor connecting to pin 3 of arduino and another of "10" connecting to IR LED. are they 47 ohm and 10 ohm respectively ?

    ReplyDelete
  12. Just a note for Mega users, use pin 9 instead of 3 for connecting of the LED driver circuit. Also change "#define IRLED 3" in "main.h" to 9.
    Mega uses different timers for the pins. Ref: http://www.mythic-beasts.com/~markt/ATmega-timers.html

    ReplyDelete
  13. Hi,

    I built the circuit (a bit differently than suggested) and it works as it should. :-)

    I have some questions:
    What currents Ib and Ic are occuring in the suggested circuit?

    Isn't the value of the 47 Ohms resistor too low?

    I just want to make sure that no critical currents are exceeded and the Arduino does not get damaged...

    Or is everything o.k., because the IR Led is only pulsed?

    Thanks!

    Josef

    ReplyDelete
  14. nice! and thanx. when saw this and directly made one! : http://youtu.be/KGvcM2i-P4o

    ReplyDelete
  15. No luck with mine programmed with a 5V/16Mhz Arduino Nano and Pin 5 is floating. I can replace the IR led with a green one and see it blink the codes but the TV never goes off. I'll try another IR led and use a 5 volt power supply.

    ReplyDelete
  16. Hi,
    thanks! This is great!
    But first, it didn't work with my Panasonic TV. The signal has to take about 2 seconds to turn off the TV, so I added a for-loop (3 times) for every POWER code. Now it works!

    ReplyDelete
  17. no matter what i do my arduino uno and the sketchbook keeps getting errors with irremote sketches what do i do?

    ReplyDelete
  18. This project is so cool, so I want to use this code. but, there are some problems
    I got some errors.


    TVB.cpp: In function 'void xmitCodeElement(uint16_t, uint16_t, uint8_t)':
    TVB:91: error: 'TCCR2A' was not declared in this scope
    TVB:91: error: 'COM2A0' was not declared in this scope
    TVB:91: error: 'COM2B1' was not declared in this scope
    TVB:92: error: 'TCCR2B' was not declared in this scope
    TVB:92: error: 'WGM22' was not declared in this scope
    TVB:105: error: 'TCCR2A' was not declared in this scope
    TVB:106: error: 'TCCR2B' was not declared in this scope
    TVB.cpp: In function 'void setup()':
    TVB:190: error: 'TCCR2A' was not declared in this scope
    TVB:191: error: 'TCCR2B' was not declared in this scope
    TVB.cpp: In function 'void sendAllCodes()':
    TVB:273: error: 'OCR2A' was not declared in this scope
    TVB:274: error: 'OCR2B' was not declared in this scope


    please help me. please

    ReplyDelete
  19. So nice article

    excuse me, but I have some errors.
    please help me.


    TVB.cpp: In function 'void xmitCodeElement(uint16_t, uint16_t, uint8_t)':
    TVB:91: error: 'TCCR2A' was not declared in this scope
    TVB:91: error: 'COM2A0' was not declared in this scope
    TVB:91: error: 'COM2B1' was not declared in this scope
    TVB:92: error: 'TCCR2B' was not declared in this scope
    TVB:92: error: 'WGM22' was not declared in this scope
    TVB:105: error: 'TCCR2A' was not declared in this scope
    TVB:106: error: 'TCCR2B' was not declared in this scope
    TVB.cpp: In function 'void setup()':
    TVB:190: error: 'TCCR2A' was not declared in this scope
    TVB:191: error: 'TCCR2B' was not declared in this scope
    TVB.cpp: In function 'void sendAllCodes()':
    TVB:273: error: 'OCR2A' was not declared in this scope
    TVB:274: error: 'OCR2B' was not declared in this scope

    ReplyDelete
  20. So nice article

    excuse me, but I have some errors.
    please help me.


    TVB.cpp: In function 'void xmitCodeElement(uint16_t, uint16_t, uint8_t)':
    TVB:91: error: 'TCCR2A' was not declared in this scope
    TVB:91: error: 'COM2A0' was not declared in this scope
    TVB:91: error: 'COM2B1' was not declared in this scope
    TVB:92: error: 'TCCR2B' was not declared in this scope
    TVB:92: error: 'WGM22' was not declared in this scope
    TVB:105: error: 'TCCR2A' was not declared in this scope
    TVB:106: error: 'TCCR2B' was not declared in this scope
    TVB.cpp: In function 'void setup()':
    TVB:190: error: 'TCCR2A' was not declared in this scope
    TVB:191: error: 'TCCR2B' was not declared in this scope
    TVB.cpp: In function 'void sendAllCodes()':
    TVB:273: error: 'OCR2A' was not declared in this scope
    TVB:274: error: 'OCR2B' was not declared in this scope

    ReplyDelete
  21. So nice article

    excuse me, but I have some errors.
    please help me.


    TVB.cpp: In function 'void xmitCodeElement(uint16_t, uint16_t, uint8_t)':
    TVB:91: error: 'TCCR2A' was not declared in this scope
    TVB:91: error: 'COM2A0' was not declared in this scope
    TVB:91: error: 'COM2B1' was not declared in this scope
    TVB:92: error: 'TCCR2B' was not declared in this scope
    TVB:92: error: 'WGM22' was not declared in this scope
    TVB:105: error: 'TCCR2A' was not declared in this scope
    TVB:106: error: 'TCCR2B' was not declared in this scope
    TVB.cpp: In function 'void setup()':
    TVB:190: error: 'TCCR2A' was not declared in this scope
    TVB:191: error: 'TCCR2B' was not declared in this scope
    TVB.cpp: In function 'void sendAllCodes()':
    TVB:273: error: 'OCR2A' was not declared in this scope
    TVB:274: error: 'OCR2B' was not declared in this scope

    ReplyDelete
  22. So nice article

    excuse me, but I have some errors.
    please help me.


    TVB.cpp: In function 'void xmitCodeElement(uint16_t, uint16_t, uint8_t)':
    TVB:91: error: 'TCCR2A' was not declared in this scope
    TVB:91: error: 'COM2A0' was not declared in this scope
    TVB:91: error: 'COM2B1' was not declared in this scope
    TVB:92: error: 'TCCR2B' was not declared in this scope
    TVB:92: error: 'WGM22' was not declared in this scope
    TVB:105: error: 'TCCR2A' was not declared in this scope
    TVB:106: error: 'TCCR2B' was not declared in this scope
    TVB.cpp: In function 'void setup()':
    TVB:190: error: 'TCCR2A' was not declared in this scope
    TVB:191: error: 'TCCR2B' was not declared in this scope
    TVB.cpp: In function 'void sendAllCodes()':
    TVB:273: error: 'OCR2A' was not declared in this scope
    TVB:274: error: 'OCR2B' was not declared in this scope

    ReplyDelete
  23. hmm im curious. Would I be able to run this code properly on an arduino lillypad 8Mhz. I ask because I remember in the TV b gone the schematic referenced such an oscillator.

    ReplyDelete
  24. This comment has been removed by the author.

    ReplyDelete
  25. This comment has been removed by the author.

    ReplyDelete
  26. I had the same errors as hippi97, and they went away when I moved the TVB folder out of libraries. Now I have a different error:
    avrdude: stk500_getsync(): not in sync: resp=0x00

    thanks for your advice,
    Hilary
    [email protected]

    ReplyDelete
  27. I'm using an adafruit flora , but there isn't a pin 5 ,in it and this is the same code as provided by adafruit. ineed to change the region to EU for south america codes , the circuit looks and works but for the NA , how can i change it?

    ReplyDelete
  28. I also tried several different IrLED's but they all do the same.

    ReplyDelete
  29. Ken, thanks for all your super hard work on this, and to Mitch Altman and Limor Fried (LadyAda) of course too! I finally got around to making my first ever TV B Gone, which is something I've wanted for over 6 months now! :) Here's a picture:

    1) http://bit.ly/1diFnqp
    2) http://bit.ly/1pXmoad

    Thanks again!
    Sincerely,
    Gabriel
    http://electricrcaircraftguy.blogspot.com/

    ReplyDelete
  30. The resistors are of 10K and 47K or 10ohms and 47ohms??

    thanks!

    ReplyDelete
  31. Could someone do the same but to work on Atmega8A? Is it possible? I've got lots of these. PLEASE

    ReplyDelete
  32. i have tested the code and i have some problems :


    TVB\WORLDcodes.cpp.o:(.progmem.data+0x0): multiple definition of `NApowerCodes'
    WORLDcodes.cpp.o:(.progmem.data+0x0): first defined here
    TVB\WORLDcodes.cpp.o:(.progmem.data+0x112): multiple definition of `EUpowerCodes'
    WORLDcodes.cpp.o:(.progmem.data+0x112): first defined here
    TVB\WORLDcodes.cpp.o:(.data.num_NAcodes+0x0): multiple definition of `num_NAcodes'
    WORLDcodes.cpp.o:(.data.num_NAcodes+0x0): first defined here
    TVB\WORLDcodes.cpp.o:(.data.num_EUcodes+0x0): multiple definition of `num_EUcodes'
    WORLDcodes.cpp.o:(.data.num_EUcodes+0x0): first defined here




    Tested with arduino 1.0.5 for an atmega 168.

    ReplyDelete
  33. I try my chance here with not much hope :D
    I want to run this on a 12Mhz clock.
    I tried changing DELAY_CTN to 11 but it doesn't seem to work.

    Would you have any advice on how to i could make it work for such a device (a Pro Trinket 3V/12Mhz from adafruit).

    Thanks for sharing that work :) !!

    ReplyDelete
  34. This comment has been removed by the author.

    ReplyDelete
  35. (referring to these 2 pictures):
    My 1st TVBGone, pic1
    My 1st TVBGone, pic2

    Alex,

    if that comment was for me, about the resistors, here's my answer: I can't vouch for that picture with 100% certainty anymore because I made that device a long time ago and have since permanently moved it to a PCB somewhere, but I have since then built another 6 or 8 or so TVBGones (as gifts) and I am most often using the following:
    Transistor: 2N3904
    R_base = 510 Ohms
    R_collector = 10 Ohms

    The Arduino I'm using in the picture is a cheapo 5V Pro Mini, and I'm running the regulated 5V to the transistor Collector (though you could probably pull more power and get better IR range if you resized the resistors and ran power straight from the 9V battery to the Collector instead).

    My range is ~15 ft. Maybe a touch more if you have good aim.

    Sincerely,
    Gabriel Staples
    http://electricrcaircraftguy.blogspot.com/

    ReplyDelete
  36. I am getting a compiling error:

    TVB/WORLDcodes.cpp.o:(.progmem.data+0x0): multiple definition of `NApowerCodes'
    WORLDcodes.cpp.o:(.progmem.data+0x0): first defined here
    TVB/WORLDcodes.cpp.o:(.progmem.data+0x112): multiple definition of `EUpowerCodes'
    WORLDcodes.cpp.o:(.progmem.data+0x112): first defined here
    TVB/WORLDcodes.cpp.o:(.data.num_NAcodes+0x0): multiple definition of `num_NAcodes'
    WORLDcodes.cpp.o:(.data.num_NAcodes+0x0): first defined here
    TVB/WORLDcodes.cpp.o:(.data.num_EUcodes+0x0): multiple definition of `num_EUcodes'
    WORLDcodes.cpp.o:(.data.num_EUcodes+0x0): first defined here

    What's up?

    ReplyDelete
  37. Ken, I want to let you know I have put your code on Github, here: https://github.com/ElectricRCAircraftGuy/TVBGone. This will hopefully make it easier for people to add to it if they wish, or edit it to port to other devices if they wish. I have made only very minor changes to it. I may have changed some pins or something (it was a long time ago I worked on it), and I added debouncing to the button (prob. not necessary, but I did it anyway to be thorough). Anyway, just wanted to let you know. For complete info people can read the readme at my link above.

    ~Gabriel Staples
    http://electricrcaircraftguy.blogspot.com/

    ReplyDelete
  38. FYI Everyone, this code will NOT compile in Arduino 1.5.7 or later, due to the newer Arduino IDEs using a newer version of the gcc compiler, which has changed the way progmem is handled. I am using Arduino 1.5.6-r2 Beta to compile and upload this code to my Arduino.

    ~Gabriel Staples

    ReplyDelete
  39. Thanks gabe, please update your code Ken i really wanna make this dope device

    ReplyDelete
  40. I keep getting an error saying StructIrCode is already defined or something, even when using the older software. (1.5.2 rev 2 beta). Please help me out with this i need to get this in for science fair asap.

    ReplyDelete
  41. Ken, sorry for posting a slightly modified version of your code on GitHub without properly forking it. Somehow I overlooked your GitHub link at the bottom of your article above, or I would have forked from there. In either case, when I get the chance I'll help update to update your root version of the code to make it compatible with the current Arduino IDE, so that will be something I get to sometime.

    ReplyDelete
  42. Gabriel, I will be checking this website frequently. Please let me know when you fix the code and how i can access it. Thanks,

    Evan

    ReplyDelete
  43. Hi ken, im doing the tv b gone and when i compile the project i get this error comment, if u can hlep me, i would be very pleased. Thanks for your time


    In file included from main.h:1:0,
    from TVB.ino:33:
    TVB:78: error: variable 'NApowerCodes' must be const in order to be put into read-only section by means of '__attribute__((progmem))'
    TVB:79: error: variable 'EUpowerCodes' must be const in order to be put into read-only section by means of '__attribute__((progmem))'
    variable 'NApowerCodes' must be const in order to be put into read-only section by means of '__attribute__((progmem))'

    ReplyDelete
  44. Any fix for:

    "undefined reference to 'NApowerCodes'"

    ... and ...

    "undefined reference to 'EUpowerCodes'"

    after const has been added?

    ReplyDelete
  45. i have got these error codes:

    In file included from main.h:1:0,
    from TVB.pde:33:
    TVB.pde:78:30: error: variable 'NApowerCodes' must be const in order to be put into read-only section by means of '__attribute__((progmem))'
    TVB.pde:79:30: error: variable 'EUpowerCodes' must be const in order to be put into read-only section by means of '__attribute__((progmem))'
    Error compiling.


    can someone help me please?

    ReplyDelete
  46. IF YOU GET NAPOWERCODES OR EUPOWERCODES MUST BE CONST,DOWNGRADE YOUR ARDUINO IDE. TEST IT. IT WORKS.

    ReplyDelete
  47. Here is a link to the TV-B-Gone sketch which has been corrected and WILL COMPILE/RUN on an Arduino Uno @ 16Mhz, AND BUILDS IN THE NEW ARDUINO SOFTWARE. If you have been an able to build the sketch and run it on your Arduino UNO, TRY THIS -- IT WORKS!

    DOWNLOAD HERE:
    http://cornfieldelectronics.com/cfe/projects/tvbg_arduino/arduino_sketches/TVBGone_Sketch.zip

    The above URL, to that sketch, can be found here:
    http://cornfieldelectronics.com/cfe/projects/tvbg_arduino/tvbg_arduino_workshop.php
    Just look, on the page, for, "3) You also need the TV-B-Gone Arduino Sketch"

    ReplyDelete
  48. I also have the problem of that when I try to compile it broadcasts these errors:
    TVB/WORLDcodes.cpp.o:(.progmem.data+0x0): multiple definition of `NApowerCodes'
    WORLDcodes.cpp.o:(.progmem.data+0x0): first defined here
    TVB/WORLDcodes.cpp.o:(.progmem.data+0x112): multiple definition of `EUpowerCodes'
    WORLDcodes.cpp.o:(.progmem.data+0x112): first defined here
    TVB/WORLDcodes.cpp.o:(.data.num_NAcodes+0x0): multiple definition of `num_NAcodes'
    WORLDcodes.cpp.o:(.data.num_NAcodes+0x0): first defined here
    TVB/WORLDcodes.cpp.o:(.data.num_EUcodes+0x0): multiple definition of `num_EUcodes'
    WORLDcodes.cpp.o:(.data.num_EUcodes+0x0): first defined here
    And can't figure out how to fix them with my limited knowledge of coding, any ideas?
    Please help its a cool project but I cant get it to Work.

    ReplyDelete
  49. Ok, so now I fixed those errors with a version after 1.5.7, but Im getting diffrent errors like:
    In file included from main.h:1:0,
    from TVB.ino:33:
    TVB.ino:78:30: error: variable 'NApowerCodes' must be const in order to be put into read-only section by means of '__attribute__((progmem))'
    TVB.ino:79:30: error: variable 'EUpowerCodes' must be const in order to be put into read-only section by means of '__attribute__((progmem))'
    Error compiling.
    Please help.

    ReplyDelete
  50. Hi all. for those who encountered errors:
    i had the same problem with all of you, every few lines some error occurs, after a few hours of playing with the code and the libraries and reading the Ken's method (http://www.righto.com/) of coding for hundreds of times, i found that the problem is not the code itself, I've tried fixing every error, changing every port and finally came to this:
    version 1.0.3 (http://arduino.googlecode.com/files/arduino-1.0.3-windows.zip) of arduino IDE for windows, just uploaded it to my UNO R3 without any errors and it works great. i have used no transistors or resistors, just pinned anode of the IR LED to pin 3 and then grounded the LED cathode to GND right next to pin 13. turns every single TV that i have tested so far off, 30 years olds from sony to toshiba and high end samsung TVs.

    ReplyDelete
  51. I try your version Amir but i have the same problem :/

    ReplyDelete
  52. Evan, Marti, Brett, Michel, Joseph, Amir, Mistifyer, and anyone else who couldn't get the code to compile, please see my link just above. I just updated the code on GitHub. Let me know via the GitHub Issues page if you have any problems.
    ~Gabriel, www.ElectricRCAircraftGuy.com

    ReplyDelete
  53. I tried this project a few months ago but came across many of the same errors as the people above.
    This new code works excellently and without any problems.

    Although I did have a question, inside the new code you give instructions on how to build it:

    The hardware for this project uses an Arduino:
    Connect an IR LED to pin 3 (IRLED).
    Connect a visible LED to the pin 13 (or use the built-in LED in many Arduinos).
    Connect a push-button between pin 2 (TRIGGER) and ground.
    Pin 5 (REGIONSWITCH) must be left floating for North America, or wire it to ground to have it output European codes.


    I was interested in whether there is still benefit to using a transistor and resistor attached to the IR led?
    What is your experience?

    ReplyDelete
  54. Can I use only microcontroller only of Arduino Uno?

    ReplyDelete
  55. Hello

    I made your modified project, and it works.
    I am in Europe, and the Europe link is in place. Until now, I only try it on my own TV, but sadly it doesn't work on it.

    I adjusted the resistor quite low to get a strong power on the IR's leds. They looks to work well (looking with a camera on it)

    Will try again on other TV's

    The goal going this hack was to be able to shut off TV in front of us, because my 2 years old girl never see TV's and I don't want her to see until older. By the way now our gov. recognize Child under 3 should never see TV, but it's not yet illegal to let them see.

    Bring some addition and affect at lot child's brain enhancement.


    Thanks a lot for your work. Previous versions were not possible anymore to use on arduinos !

    ReplyDelete