I'm trying to work through the projects in the Starter Kit (uno) box but I have a problem with the digitalRead pins always reading HIGH.
This continues even with the addition of what I understand to be a "pull down" resistor connecting the digitalRead pin to ground for when the switch is open.
I found a tutorial that allows me to 'Serial.print' the 'digitalRead' state and it seems to work fine, showing 0's when I don't press the button and 1's when I supply the pin with current.
When I add an "IF" statement to light an LED using a digitalWrite pin, the Serial.print shows that the digital.Read pin is now always HIGH and the LED is always on, whether I press the button or not!
/*
DigitalReadSerial
Reads a digital input on pin 2, prints the result to the serial monitor
This example code is in the public domain.
*/
// digital pin 2 has a pushbutton attached to it. Give it a name:
int pushButton = 2;
int led = 6;
// the setup routine runs once when you press reset:
void setup() {
// initialize serial communication at 9600 bits per second:
Serial.begin(9600);
// make the pushbutton's pin an input:
pinMode(pushButton, INPUT);
pinMode (led, OUTPUT);
}
// the loop routine runs over and over again forever:
void loop() {
// read the input pin:
int buttonState = digitalRead(pushButton);
if (pushButton = HIGH) {
digitalWrite (led, HIGH);
}
else {
digitalWrite (led, LOW);
}
// print out the state of the button:
Serial.print(buttonState);
delay(100); // delay in between reads for stability
}
Any help would be greatly appreciated,
Thanks