int out = LED_BUILTIN;
int strt = 3;
int stp = 9;
void setup() {

void loop() {
  while(true) {  
    if(digitalRead(strt) == LOW) {
    if(digitalRead(stp) == HIGH) {
      digitalWrite(out, LOW);

I'm a beginner so I believe someone would help me out. Actually the mechanism I'm using for turning the state of Pin 3 & 9 is through 3 wires connected to the Pins D3,D9 & 5V in the nano board. Where 5 V is immersed in water and Pin 3 does not touch water Nano's Built in LED is turned on and if the water reaches Pin 9 (while the Pin 3 wire is still submerged under water) the LED goes Off.

In the above code, the Built in LED turns High just fine if Input Pin 3 Reads Low. Although as soon as Pin 3 goes High the LED turns Low and does not wait for Reading input pin 9 which is when the LED should actually turn Off.

In the first IF Clause (For Reading Pin 3(strt) to LOW) I want that part of the code to only set the OUTPUT pin LED_BUILTIN to be set to HIGH & not revert back to LOW if pin 3 is turned to HIGH. But only if the INPUT pin 9 in the second IF Clause reads HIGH then only should the OUTPUT Pin LED_BUILTIN be set to LOW.

Thank You for the helping hand.

This is the Link for the Code that I used(I Modified the code to have two input Wires) : https://www.instructables.com/Water-Level-Alarm-Using-Arduino/

  • as soon as Pin 3 goes High the LED turns Low - that makes no sense. The only way the LED can go LOW is if pin 9 reads high.
    – Majenko
    Nov 1, 2020 at 11:29
  • That is right . That's what was supposed to happen. But as I said earlier when the wire connected to Pin 3 touches the water (ie Pin 3 Goes High) LED goes LOW. But I want nothing to happen if Pin 3 goes High. Only if Pin 3 goes Low should the LED turn on. I hope I'm clear. Please help me!
    – Saagar G
    Nov 1, 2020 at 12:52
  • the while(true){ is redundant .... loop() already does that
    – jsotola
    Nov 1, 2020 at 16:56
  • change your code so that the led is controled by pin 3 only ... verify that the harware responds as expected by repeatedy dipping pin 3 wire in water (shorten the delay for this)
    – jsotola
    Nov 1, 2020 at 18:03


Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.