Pages: [1]   Go Down
Author Topic: Blink led with a button  (Read 335 times)
0 Members and 1 Guest are viewing this topic.
Offline Offline
Karma: 0
Posts: 6
Arduino rocks
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

I want to put the led on when the button is pushed...But I have some problem with the language on the software...

If I write in void loop

val= digitalread (inpin); // read input value
if (val== HIGH) // check if the input is HIGH (Button released)
digitalwrite (ledpin, LOW); // Turn LED off
digitalwrite (ledpin, HIGH); // turn LED on

I have the opposite that I want... The led Turns on always and it turns off when I push the button...
Where do I change the value HIGH and LOW??
Please somebody answer me........ smiley-razz

Offline Offline
Faraday Member
Karma: 8
Posts: 2526
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

It depends on what your circuit looks like, but usually pushbuttons are inverted logic, because they are pulled up to VCC using a resistor and shorted temporarily to ground when the button is pressed.  In such a configuration, the switch is "active low", e.g. it's 0V when pressed and 5V otherwise.


Pages: [1]   Go Up
Jump to: