How to stop a servo using conditional if? Answered
I'm using an Arduino Uno, Ultrasonic sensor (HC-SR04) a Servo motor (SG90 Tower Pro).
I would like to rotate the servo continuously from 0 to 180 and back to 0.
I would like to stop the servo whenever the ultrasonic sensor detects an object at a distance of 40 cm or less.
I know how to rotate the servo and how to detect an object using the ultrasonic sensor, but I couldn't combine the two.
Can you kindly help me on how to do so?