If() sets all digitalRead = 1

Title says a lot here, very weird issue that i have never experienced before,
Basically i have my code reading the value of a switch, Works perfectly fine, switch is on, get a serial print of 1, off is 0...

Until i include any if statements.. then it reads the switch as 1, no matter what i do, even grounding the pin still gives the same reading..

I figured this was an issue with my board so i borrowed my friends and rebuilt the circuit independently, same issue, I literally have no idea where to start with this one, what am i doing wrong?

i figure it is an error in the bootloader since i have tried a separate arduino but could be wrong.

Any advice is sincerely appreciated

#define engine_idle_switch 3
#define engine_arm_switch 5


void setup() {
  Serial.begin(9600);
  pinMode(engine_idle_switch, INPUT);
  pinMode(engine_arm_switch, INPUT);

  
//  pinMode(30, OUTPUT);
//  M1.attach(8);
//  startup_ready = false;
}

void loop() {
  
    int engine_arm_switch_state = digitalRead(engine_arm_switch);
    int engine_idle_switch_state = digitalRead(engine_idle_switch);

    if(engine_arm_switch_state = 1){
      Serial.println("hmm");
      }
      
    Serial.println(engine_arm_switch_state);

    }

Single "=" sets the variable to the value "1". Use "==" to test for equality.

If (engine_arm_switch_state = 1){

[/quote]

Oh god :o Hahaha embarrassing, well thank you for pointing it out, really appreciate

i figure it is an error in the bootloader since i have tried a separate arduino but could be wrong.

The only thing that the bootloader does is check for a few seconds if you want to upload code. If so, it will write the code that it receives from the PC to the flash memory of the processor. If not, it will hand the control over to the code that is saved in the flash memory of the processor.

You can compare it a little bit with the BIOS of a PC. It waits a little so you can do certain configurations (after e.g. pressing F2 or DEL) and next hands over control to the operating system stored on the harddisk (or other bootable medium like CD or USB).

As you have found out, it's not a problem with the bootloder :slight_smile:

i figure it is an error in the bootloader

Have you been introduced to Mr Occam, and his handy shaving implement?