Digital pin value

Im very new to Arduino and programming and electricity in itself. To some this will be a basic and obvious question but i am new so bare with me. I am trying to have a button light up this led when it is pressed down. have successfully made the code and circuit while my button pin reads 1 or HIGH default in the serial monitor. How ever, posting the same code into another sketch, using the same circuit my button pin value is default LOW or 0 in the serial monitor. The value won't change regardless of my code. My full goal was to make a button for a buzzer and an LED so there will also be code for a buzzer in my work.

Hello carlosbarros
Post your current sketch, well formated, with comments and in so called code tags "</>" and a schematic, not a Fritzy diagram, to see how we can help.
Have a nice day and enjoy coding in C++.

Your screenshot is unreadable on my tablet. Not the best way to get help.

Read the forum guidelines to see how to properly post code and some information on how to get the most from this forum.
Use the IDE autoformat tool (ctrl-t or Tools, Auto format) before posting code in code tags.

Or more specifically, this part.

After uploading the new sketch, when you press the switch, what do you see in the serial monitor? Always 0?

Thank you guys for replying to me I honestly wasn't sure if I would get any cause it seems like a simple issue lol.
When the state of my buttonA is displayed on the serial monitor, it should come up as a 1 since it should be default high right? but neither 1 or 0's come up just symbols like !6 or (0!6. it would just give me a line or two of those symbols and stop.

//Led Pins Defined
#define Led 11
#define ButtonA 5

//Buzzer pins Defined
// #define Buzzer 6
// #define ButtonB 3

//buttonstates variable defined
int buttonStateA = 0;
//int buttonStateB = 2;

void setup() {
  //Begin Serial Connection
  Serial.begin(9600);
  //Led Pin Modes
  pinMode(ButtonA, INPUT_PULLUP);
  pinMode(Led, OUTPUT);

  //Buzzer Pin Modes
  //pinMode(Buzzer,OUTPUT);
  //pinMode(ButtonB,INPUT,PULLUP);

}

void loop() {

  //digital read of button pin (5) value defined
  buttonStateA == digitalRead(ButtonA);

  //Serial view of button state
  Serial.println(buttonStateA);

  // if button is pressed led will turn on
  {
    if (buttonStateA == HIGH)
    {
      digitalWrite (Led, LOW);
    }
    else
    {
      digitalWrite(Led, HIGH);
    }


  }
}

= for assignment, == for comparison.

If you had warnings enabled in the IDE (File, Preferences, Compiler Warnings All) you would have see this warning.

... \AppData\Local\Temp\arduino_modified_sketch_619019\sketch_mar26a.ino:31:17: warning: value computed is not used [-Wunused-value]
buttonStateA == digitalRead(ButtonA);

You should enable warnings and make sure to deal with them.

thank you so much, i dont have many engineering friends yet to ask these questions to, i enabled the warnings (they're so useful). I was able to make my button work on the buzzer and the led on the same circuit which ive been trying to do a day or so lol. It was a simple fix i 100% wouldve taken so long to pick out. Once again thank you

It would be nice if you would mark this thread as solved so others don't waste their time trying to help with a solved problem.

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