Super simple question

GreenFTWs

Member
I am trying to follow a simple tutorial: https://www.pjrc.com/teensy/tutorial3.html

Here's the code I'm trying to run:
void setup() {
Serial.begin(38400);
pinMode(7, INPUT);
}

void loop()
{
if (digitalRead(7) == HIGH) {
Serial.println("Button is not pressed...");
} else {
Serial.println("Button pressed!!!");
}
delay(250);
}

My serial monitor spams "Button pressed!!!"
and my buttons do nothing... what am I missing?
 

Attachments

  • 1000004835 (1).jpg
    1000004835 (1).jpg
    217.6 KB · Views: 29
Try rotating the pushbuttons 90 degrees.

Or use a multimeter in ohms or beeper mode to check which pins actually connect when you press the button. But usually it's the 2 close together, not the ones on opposite sides as you might intuitively expect.
 
Try rotating the pushbuttons 90 degrees.

Or use a multimeter in ohms or beeper mode to check which pins actually connect when you press the button. But usually it's the 2 close together, not the ones on opposite sides as you might intuitively expect.

Thank you for the response! I'm still not quite sure I understand you though. I don't have a multimeter unfortunately, and I'm not quite sure what beeper mode means. When I rotate the button, it doesn't seem to fit unless I bend the pins, and if I do I'm not quite sure where I should test the cables from as it seems I wont have anywhere to put them within the same row.

I'm attaching two pictures, the one with the pins left and right, are how I had it initially, after turning it 90 degrees is the other picture.
 

Attachments

  • 1000004837 (1).jpg
    1000004837 (1).jpg
    137.6 KB · Views: 19
  • 1000004836 (1).jpg
    1000004836 (1).jpg
    109 KB · Views: 22
Thank you for the response! I'm still not quite sure I understand you though. I don't have a multimeter unfortunately, and I'm not quite sure what beeper mode means. When I rotate the button, it doesn't seem to fit unless I bend the pins, and if I do I'm not quite sure where I should test the cables from as it seems I wont have anywhere to put them within the same row.

I'm attaching two pictures, the one with the pins left and right, are how I had it initially, after turning it 90 degrees is the other picture.
By left and right, I mean relative to how I took the picture.
 
In your Left picture (with the switch raised up), the breadboard short rows are connected top to bottom.
The Yellow wire to one side and the Orange wire to the other side are no longer connected to the switch pins.

That left picture - according to Paul p#2 and a switch just tested here - is the proper orientation to get the needed two pins. The right side picture will have the breadboard connect the needed two pins.

To use that switch given its size, center it over the middle of the breadboard with two pins on each side as oriented in that Left picture. Then on the one side with the wires currently shown, move the wires into the same row as the pins of the switch on that same side.

Then do the same for the second switch to use it.

Not clear what that resistor is doing? If the orange wire is Ground then the pin can be used as INPUT_PULLUP, and will go 0 when pressed.
If the switch is PULLDOWN then remove the Orange GND wire and put the resistor to 3.3V in place of it and it will go to 1 when pressed.
 
In your Left picture (with the switch raised up), the breadboard short rows are connected top to bottom.
The Yellow wire to one side and the Orange wire to the other side are no longer connected to the switch pins.

That left picture - according to Paul p#2 and a switch just tested here - is the proper orientation to get the needed two pins. The right side picture will have the breadboard connect the needed two pins.

To use that switch given its size, center it over the middle of the breadboard with two pins on each side as oriented in that Left picture. Then on the one side with the wires currently shown, move the wires into the same row as the pins of the switch on that same side.

Then do the same for the second switch to use it.

Not clear what that resistor is doing? If the orange wire is Ground then the pin can be used as INPUT_PULLUP, and will go 0 when pressed.
If the switch is PULLDOWN then remove the Orange GND wire and put the resistor to 3.3V in place of it and it will go to 1 when pressed.
Thank you for the response! :) The problem with the first switch is that I need to use the resistor. No other option... I won't get full marks at school. The second switch is using INPUT_PULLUP though... If I continue to use the resistor will it work? I'm scared of testing because I don't want to fry my teensy.
 
Quick update! Well, the light function a part of the tutorial now works. Rotating my button was the solution. I'm not sure how to incorporate the rotated button with the resistor though considering it's too big. Any suggestions? :D

Thanks everyone!
 
Try moving the button up, so it's placed across the center of the breadboard. You'll of course need to also move the resistor.
 
If the switch is PULLDOWN then remove the Orange GND wire and put the resistor to 3.3V in place of it and it will go to 1 when pressed.
It should work like above? The physical 3.3V pullup resistor could go to that right side switch pin on the far side - diagonal to the pin to the Teensy.
 
Back
Top