generate functionSun, 12 Feb 2023

write a code for ardino uno whenever someone is 10 meters away from the ultrasonic sensor then reduce the speed of the moter and if it is not 10 meters away then let it run at normal speed

#include <Servo.h> #include <Ultrasonic.h> Ultrasonic ultrasonic(12, 13); Servo myservo; void setup() { Serial.begin(9600); myservo.attach(9); } void loop() { long RangeInInches; myservo.write(90); delay(250); RangeInInches = ultrasonic.Ranging(CM); Serial.print(RangeInInches); delay(250); if(RangeInInches < 10){ //set servo angle myservo.write(0); } else{ myservo.write(90); } }

Questions about programming?Chat with your personal AI assistant