int duration, distance;
digitalWrite(trigPin, HIGH);
delayMicroseconds(1000);
digitalWrite(trigPin, LOW);
duration = pulseIn(echoPin, HIGH);
distance = (duration/2) / 29.1;
if (distance >= 200 || distance <= 0){
Serial.println("Out of range");
}
else {
Serial.print(distance);
Serial.println(" cm");
}
You're reading the sensor, even though you may not need to. Why?
You are not reading the switch state, even though you DO need to. Why not?
if (High or low, from distance > 10 && SwitchPin)
Pure gibberish. If you can't even phrase your question properly, you'll never get it coded correctly.