Go Down

Topic: LED/Pressbutton woes (Read 2042 times) previous topic - next topic

Wildsky

In Chapter 4, Example 2, I've got my code and wiring exactly like the book describes, but my LED stays lit, and won't change whether I press the button or not. This seems really straightforward, other than the fact it doesn't work as expected. Any ideas what I'm doing wrong?

Chris

JimboZA

Quote
I've got my code and wiring exactly like the book describes


Perhaps you haven't....  8)

You should post the actual code here, copied from the ide not the book. Also post a diagram or clear photo of the actual circuit.
Arduino ethernet server here.... http://jimboza.gotdns.com:8085/

No PMs for help please

Wildsky

Absolutely, thank you!


// Hello world

const int LED = 13;
const int BUTTON = 7;
int val = 0;


void setup() {
  pinMode(LED, OUTPUT);
  pinMode(BUTTON, INPUT);
 
}

void loop() {
 
  val = digitalRead(BUTTON);
 
  if (val == HIGH) {
    digitalWrite(LED, HIGH);
  }
  else {
    digitalWrite(LED, LOW);
  }
 
}



JimboZA

I'm not at home where I have access to one of those switches and my multi-meter, but you might have that switch rotated by 90 degrees.

The wires might be on the links that are always connected, not across the "open" part which the switch closes. If you have a meter you can check, but in anycase just re-orientate it and see if that works.
Arduino ethernet server here.... http://jimboza.gotdns.com:8085/

No PMs for help please

JimboZA

#4
Feb 08, 2013, 02:05 pm Last Edit: Feb 08, 2013, 02:39 pm by JimboZA Reason: 1
I don't have one of those switches... thought I did  :smiley-yell:

But if you have a look at the Fritzing pic on this tut, it looks to me like your switch is the wrong way round?

The switch joins the pins on the same side when it's pushed, not the opposite pins which is more intuitive and is the way you have yours: if I'm right then your red and yellow are always joined, not switched.

Edit.... I dug around and these switches seem to be (or are similar to) Omron B3Fs. Have a look at the pic attached from their datasheet, which indeed shows that opposite pins are always connected, and pushing the button connects the pins on the same side; in fact connects all 4 pins.
Arduino ethernet server here.... http://jimboza.gotdns.com:8085/

No PMs for help please

hiduino

A good quick test to see if you have the switch the wrong way is to just pull it out and see if the LED goes out.  If it does go out then just rotate your switch 90 deg.

Wildsky

Yep, that was it! :)

Thank you!

JimboZA

Switch pin layout level: FAIL
Arduino ethernet server here.... http://jimboza.gotdns.com:8085/

No PMs for help please

Go Up