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
the circut for the talking robot code for the talking robot int motorPlus = 5; int motorMinus = 4; void setup() { pinMode(motorPlus,OUTPUT); pinMode(motorMinus,OUTPUT); } void loop() { digitalWrite(motorPlus,HIGH); digitalWrite(motorMinus,LOW); delay(500); digitalWrite(motorPlus,LOW); digitalWrite(motorMinus,HIGH); delay(500); } copy and past this code to arduino and upload it channel link : https://www.youtube.com/channel/UCOgVFoF3Vkw3aicoAjDfRng meet u in next blog
Comments
Post a Comment