Posts

Showing posts from October, 2021

How to control servo motor with ultrasonic Sensor using Arduino

Image
 How to control servo motor with ultrasonic Sensor using Arduino Arduino tutorial #5 This is the the Circut diagram of this tutorial This is the code of this tutorial #include <Servo.h> Servo servo1; int trigPin = 9; int echoPin = 8; long distance; long duration; void setup()  { servo1.attach(7);   pinMode(trigPin, OUTPUT);  pinMode(echoPin, INPUT); } void loop() {   ultra_sonic();   servo1.write(90);   if(distance <=9)   {   servo1.write(270);   } } void ultra_sonic() {   digitalWrite(trigPin, LOW);   delayMicroseconds(2);   digitalWrite(trigPin, HIGH);   delayMicroseconds(10);   digitalWrite(trigPin, LOW);   duration = pulseIn(echoPin, HIGH);   distance = duration*0.034/2;   } Thank you for watching the video and the visiting this blog . if you have any  quarries  kindly type  it in the comments Thank you