Go Down

Topic: DIY TV-B-Gone Test not working (Read 784 times) previous topic - next topic

shman613

      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:
     
     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!!!!

DrAzzy

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.
ATTinyCore for x4/x5/x61/x7/x8/x41/1634/828/x313 megaTinyCore for the megaavr ATtinies - Board Manager:
http://drazzy.com/package_drazzy.com_index.json
ATtiny breakouts, mosfets, awesome prototyping board in my store http://tindie.com/stores/DrAzzy

MarkT

Code: [Select]
    digitalWrite(ledPin, 255); 

255?  HIGH surely? 255 suggests analogWrite, not digitalWrite...
[ I will NOT respond to personal messages, I WILL delete them, use the forum please ]

Go Up