Hi. I want to create a program with an ultrasonic sensor, a LED, a buzzer, and a push button. I want that if the ultrasonic sensor detects someone within 10 cm, the buzzer sounds and the LED lights up. However, if I press the push button, the LED and the buzzer should turn off. I can't get the push button to work. I'll copy the code. Any idea where the mistake might be? I am using arduinoblocks but I copy the blocks translated. #include <ABLocks_TimerFreeTone.h>
Read sticky notes? check
Content of sticky notes clearly understood check
Current sketch posted well formatted with comments and in-code tags check
Current wiring and connection diagram posted check
Detailed task and error description posted check
Needed data sheets posted check
Can you please tell us your electronics, programming, arduino, hardware experience?
Sorry, your code is almost unreadable if posted this way.
So, help us help you: please edit your post, select all the code (assuming it's well formatted/indented, otherwise replace it with the one you have in your IDE or Blocks) then press the "<CODE/>" button above your text area and save it. Thanks.
PS: codeblocks code is not easy to be checked and any change we could suggest you is related to the code, not the blocks. it's up to you to "translate" our hints into blocks. Or, better, avoid using Blocks and start learning the use of Arudino's C programming: it will probably be less simple at the beginning but you will then have great advantages and greater freedom.
How are your switches wired. The most common way to wire switches is to wire one terminal to ground and the other terminal to an input with its pinMode set to INPUT_PULLUP. The switch will read HIGH when not pressed and LOW when pressed. Adjust the code accordingly. If using the popular 6mm tactile pushbutton, make sure to wire to diagonal terminals.