Beginner question: stuck with a problem

Hi everyone,
Im following a book called Arduino Workshop and realised that it had some mistakes in it.
Im stuck at project 4 Page 65 (http://www.nostarch.com/download/samples/Arduinows_ch4.pdf) .
There’s a correction released by the author saying:

"Page 67: The text for section 3 should read, “Connect one wire from the Arduino 5 V pin to the leftmost vertical column on the breadboard, and connect another wire from the Arduino GND pin to the vertical row to the right of the 5 V column, and another horizontal wire between the vertical GND column and the bottom-left pin of the button, as shown in Figure 4-22.”

However, I still can’t get the LED to light up.
Ive attached the image below. Hopefully you can help me! Thanks!

Program code:

#define LED 12
#define BUTTON 7

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

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

Can't really tell how it's wired from that photo: but the obvious thing to check is that the LED is the right way round? The wire on the flat side of the red blob must be to negative. (Alternatively, check the LED wires: the longer one must go to positive.)

try

define LED 13

LED is connected: shorter side to ground, longer side to resistor and then to pin 12. 12th pin is connected to the LED, so no point in changing LED value to 13 i think.

13 is the on board led, it is always connected right

The other thing to check is that the 4-pin button is correctly oriented: it may need a 90degree turn. See attached for how the pins connect internally.

push button.PNG

I believe the button is sitting correctly, nothing happens when i try to turn it 90degrees. I tried Robtillaart's advice, but still nothing. However, when i remove the button or disconnect a wire that goes to pin 7 (button -> pin7), my LED lights up. JohnLincoln, i think you meant pinMode(BUTTON, INPUT_PULLUP), because pinMode(BUTTON, PULLUP) doesn't compile. I tried it, but still nothing. I'm lost here :/

Can you do a drawing of your circuit and take a photo to post? Very difficult to see the details from your photo.

Theres the visual scheme.
I’m using all the parts as listed in the book.

That looks like a pull-down resistor with a pull-down switch. So it will always look like the switch is pressed. Remove the 10k resistor that is on the pushbutton switch, and use the internal Pullup resistor as suggested.

Or connect the right side of the pushbutton to 5V.

The fact that the LED lights up when you remove the button would seem to indicate that you have the switch turned 90 degrees.

If i just connect 5V to top right corner of the button, whole Arduino board shuts down until I remove the wire. If instead of that, I disconnect 10k resistor and set pinMode(BUTTON,INPUT_PULLUP); the LED lights up and stays on.

It's very difficult to connect the button to breadboard other way, I have to really bend the metal legs of the button and it still doesnt quite fit.

I think you have a wiring error. It looks like from the photo you attached, you have one of the pins of the pushbutton switch (lower righhand corner) connected to ground. Yet Figure 4-19 none of the pins of the switchbutton is connected to ground.

Author of the book later wrote that this was mistake, and added:

Page 67:
The text for section 3 should read, “Connect one wire from the Arduino 5 V pin to the leftmost vertical column on the breadboard, and connect another wire from the Arduino GND pin to the vertical row to the right of the 5 V column, and another horizontal wire between the vertical GND column and the bottom-left pin of the button, as shown in Figure 4-22.”

.

To start, you need to post a BETTER of your current breadboard. From there, when can go on to understand what circuit the author intends.

But as it stands now, you have one of the pins of the pushbutton connected to GROUND. That is what I see in your photo. Please crop photos to proper size.

Edit: That pin on the pushbutton that you have connected to ground should be connected to +5V. The author's schematic in Figure 4-19 shows it, he does not have any photos showing it in the step-by-step 1 to 6.

The author using phrases like "bottom-left pin of the button" only works if the button's the right way round in the first place.

Do you see from the pic I posted of the insides of buttons like that, that 2 pairs of pins are always connected, and the button connects one pair to the other. If you have an ohm-meter it's easy to verify, and it would be worth your while to figure it out. Even if it's right this time, it's good to know for the future.

And regarding it not fitting in the breadboard nicely: they're not meant for breadboard, so yep you may well have to straighten or otherwise mangle the pins a bit.

Finally, managed to make it work. Indeed, the wire button->GND should've been button->5V. The instructions in the book and even in errata we're a bit misguiding.

JimboZA, I see what you are saying. But now the button works either way. My question is, do I want the 5V to reach the capacitor before or after the button is pressed? Because the way it is now, that is only thing that changes if I put the button other way round.

Thanks!

What do you mean your button works either way?

It should not.

When you have the circuit wired correctly, pin 7 is at 0 volts. The capacitor is completely discharged.

When you push the button to close it, the capacitor starts charging and the voltage at pin 7 eventually reaches 5V.

The resistor and the capacitor are acting together as a switch debouncer.

Pardon me, I just reassembled it and when I have the button turned 90 degrees, the LED stays on all the time. AIthough, in that case, Im not sure why Arduino thinks that the button is being pressed.

SarunasK:
AIthough, in that case, Im not sure why Arduino thinks that the button is being pressed.

The way you have it now, you probably have two wires or Arduino pins or whatever, on the two ends of the “bar” thingy inside the switch, so they’re joined together by that, not by the switch. Like T1 and T2 in the attached…

You need to get your meter and beep the pins out so you know what’s connected and what’s switched.

Fwiw, I hate those things.

short.PNG