The if is always true
- Arduino C++
- JavaScript
- PictoBlox blocks don't have this
Why it happens
if (x = 1)was typed instead ofif (x == 1). It compiles with no error.
How to fix it
- Use
==inside everyif. - Also check there's no
;straight afterif (…): it ends the if before its block.
It worked if: Change the input: the code now does both things, one for yes and one for no.
Tutorials where it can happen
- Automatic Pet Feeder with Arduino and Servo
- Building a Motion Detection System Using ESP32 and ESP-NOW
- Building an Intruder Detection System with LCD and Alarm using Arduino
- Creating a Touchless Hand Sanitizer Dispenser with LCD Display
- Digital Input and Output with the ESP32
- Digital Inputs and Digital Outputs on the NodeMCU ESP8266
8 more
- ESP32 PIR Motion Sensor with Interrupts and Timers
- Home Security Alarm with Arduino and PIR Sensor
- Home Security System with Motion Detection and LCD Feedback
- Human Presence Detection and Lighting Control with LCD Output
- Motion-Activated Security Camera with LCD Feedback
- Object Detection and Sorting System Using IR Sensors with LCD Feedback
- PIR Motion Sensor Alarm with Arduino (HC-SR501 and Buzzer)
- Smart Traffic Light System with Arduino
From how the part works. A C++ language rule; it gives no error message.
Didn't help? Search another error or ask us.

