I have a ESP8266 nodeMCU which is connected to a IR sensor at pin D2,
I do not get any error while compiling just it does not change its value when any object is detected, The serial moniter just shows the value 0 and builtin led is always at high. But the ir builtin led changes its state when objevt is detected.
Below is my code for the same:
// C++ code
//
int buttonState = 0;
//int freq = 100;
void setup()
{
pinMode(2, INPUT);
//pinMode(12, OUTPUT);
pinMode(LED_BUILTIN, OUTPUT);
Serial.begin(115200);
}
void loop()
{
// read the state of the pushbutton
buttonState = digitalRead(2);
Serial.print(buttonState);
// check if pushbutton is pressed. if it is, the
// button state is HIGH
if (buttonState == HIGH) {
Serial.print(buttonState);
digitalWrite(LED_BUILTIN, HIGH);
//tone(12,freq);
} else {
Serial.print(buttonState);
digitalWrite(LED_BUILTIN, LOW);
//noTone(12);
}
// Delay a little bit to improve simulation performance
delay(10);
}
And when I change this statement if (buttonState == HIGH) to if (buttonState == LOW) serial moniter shows value 001100110011......
When I connected the pin to D0 instead of D2 then the if-else block is working properly. i.e. builtin led is high when its on gnd and low when its on 3.3v. But the serial moniter show all the value as 111111.....
Hi,
Is that the code on the code screen in post #16 ?
If so it isn't the code in post #1.
Which code are you running?
If it is post#1 code, then you print the state twice.
So 0011001100110011 means that the input pin is regularly changing from LOW to HIGH.
Can you do @LarryD test again, but put the end of the jumper on the actual input solder joint, and then the other end to 3V3 then gnd solder joints?
That is don't use the protoboard connections.