Arduino Forum

Using Arduino => General Electronics => Topic started by: shman613 on Oct 06, 2014, 04:28 am

Title: DIY TV-B-Gone Test not working
Post by: shman613 on Oct 06, 2014, 04:28 am
      The TV b gone, for those who do not know, is an ingenious device that uses an infrared led to turn off TV's, since virtually all TV remotes use infrared leds.
      I made a simplified version on my arduino:
      (http://cdn.instructables.com/FAW/L2T0/H1JUHLSY/FAWL2T0H1JUHLSY.LARGE.jpg)
     I wanted to test the IR led, so I used this code:
     
Code: [Select]
const int buttonPin = 2;     // the number of the pushbutton pin
const int ledPin =  3;      // the number of the LED pin

// variables will change:
int buttonState = 0;         // variable for reading the pushbutton status

void setup() {
  // initialize the LED pin as an output:
  pinMode(ledPin, OUTPUT);     
  // initialize the pushbutton pin as an input:
  pinMode(buttonPin, INPUT);


}

void loop(){
  // read the state of the pushbutton value:
  buttonState = digitalRead(buttonPin);

  // check if the pushbutton is pressed.
  // if it is, the buttonState is HIGH:
  if (buttonState == HIGH) {     
    // turn LED on:   
    digitalWrite(ledPin, 255); 
   

   
  }
  else {
    // turn LED off:
   
    digitalWrite(ledPin, 0);
   
  }
}

This is basically the arduino pushbutton code, given on this website, with minor tweaks.
However, when I run the code, the LED doesn't light up!!! Not when I release the button, or when I push the button!!! Frustrating!!!!
Title: Re: DIY TV-B-Gone Test not working
Post by: DrAzzy on Oct 06, 2014, 06:07 am
If it's wired as you show, you're getting the results you are because it's not seeing that the button is pushed

Assuming the button is normally closed, when button is not pressed, the pin is connected to ground... But when the button is pressed, the pin is... not connected to anything, and has no reason to go high. You need a pullup - you could use an external one, but it's easier to use the built-in pullup on the Arduino. Instead of INPUT, use INPUT_PULLUP mode.
Title: Re: DIY TV-B-Gone Test not working
Post by: MarkT on Oct 06, 2014, 12:36 pm
Code: [Select]
    digitalWrite(ledPin, 255); 

255?  HIGH surely? 255 suggests analogWrite, not digitalWrite...