If then else conditon

how to write the if then else condition using the pin numbers and pin value for ultrasonic sensor

//Assuming that you're receiving input on pin3
var inputPin = "A3";
//...and that you're actuating pin is pin7'
//var outputPin = "7";
//But lets have some fun...
var dimLED = "4";  //connect Red LED
var medLED = "5"; //connect Blue LED
var highLED = "6"; //connect Green LED

//Now I'm not sure how an ultrasonic sensor works in detail.
//But I guess it gives out analog signals, so...
if ( inputPin < 100 ) {
    //Light up the dim LED
    digitalMultiWrite( [dimLED, medLED, highLED], ["HIGH", LOW, LOW] );
} else if ( inputPin < 180 ) {
    //Light up the med LED
    digitalMultiWrite( [dimLED, medLED, highLED], [LOW, "HIGH", LOW] );
} else {
    //similarily...
    digitalMultiWrite( [dimLED, medLED, highLED], [LOW, LOW. "HIGH"] );
}

That’s it. It’s the same every time you use an if-else clause.
Choose a control variable, use if|else if|else to make magic.

1 Like

DISCLAIMER:
THIS IS NOT HOW AN ULTRASONIC SENSOR WORKS!!!
The code is valid for simple analog sensors like LDRs but Ultrasonic Sensors need more working out, before their output can be used.
(Thanks to @hitesh.poddar2013 for pointing this out.)