Arduino UNO Rev3 code not working.

I have loaded a code from a YouTube Video lesson #27 from Paul McWhorter and it doesn't work, all I get is LED turns on after upload and won't change with the button being pressed. In the code the LED shouldn't light until the button is pressed, the serial monitor shows the switch responding with 1 or 0 like it should but that is the only part that is working. Could it be the IDE not working or the arduino uno?

int LEDPin = 3;
int buttonPin = 11;
int buttonRead;
int dt = 100;

void setup() {
  Serial.begin (9600);
  pinMode (LEDPin, OUTPUT);
  pinMode (buttonPin, INPUT);

  // put your setup code here, to run once:

}

void loop() {
  buttonRead = digitalRead(buttonPin);
  Serial.println (buttonRead);
  delay (100);
  if (buttonRead == 1); {
    digitalWrite(LEDPin, LOW );
  }
  if (buttonRead == 0); {
    digitalWrite(LEDPin, HIGH);

  }

Paul McWhorter

Please provide us with a diagram or detailed description of how you have the button wired.

A 10K resistor is connected to 5v, On the Arduino, the other end is connected to pin 11. At pin 11 one side of the switch is wired to pin11, the other side is to ground, when pressed pin 11 will go from 5v to 0v. I have also use a jumper wire to ground to make the voltage drop so I could remove the switch from the circuit to see if it was the problem I end up with the same results LED stays lit and no change when pin 11 goes from 1 to 0 volts.

Some more information, I went on YouTube to the Arduino lesson #27 and followed the tutorial,1st put in the code for the button read, compile and upload was good. The serial monitor shows the switch reading 1 until the button is pushed then reads 0, until released then reads 1 again, so I continued to put the code in to control the LED compile and upload was good, but the LED turned on when it should be off and stays on I even tried other pins for the LED and switch but the same thing happens so I re downloaded the Arduino IDE to make sure it was working same thing happens at this point I think my Arduino uno is faulty because I see the code work in the tutorial but wont work for me.

Keep working at it. It’s very unlikely that the problem is with your Uno.

You have a semi colon after the if statements. Remove them.

As a result, the blocks between { and } will always be executed.

Thank You Sterretje that was the problem also My blindness to the obvious, It works now.

This topic was automatically closed 120 days after the last reply. New replies are no longer allowed.