How to combine an Servo and Ultrasonic Sensor and code
Автор: DreThePlug
Загружено: 2023-02-06
Просмотров: 284
Описание:
This video was created to help people create a Servo and Ultrasonic Sensor
Other Youtube channel Andre ClassicCuts
/ @andreclassiccuts
DreThePlug IG: DreThePlug123
/ dretheplug123
Add me on Linkedin
/ andre-brown-194918103
How to Control the Ultra Sonic Sensor Ranges with Sound/Music Arduino
• Ultra Sonic Sensor with Sound Music Arduino
Music provided by isthatCaydo?.
Instrumental: Reprod. by Caydo
Channel: • Future - Same Accord Instrumental | Reprod...
The Treasure Chest
int trigPin = 3;
int echoPin = 2;
#include (less than sign)Servo.h(greater than sign)
Servo servo1;
Servo servo2;
int angle = 0;
void setup() {
Serial.begin(9600);
pinMode(trigPin, OUTPUT);
pinMode(echoPin, INPUT); // put your setup code here, to run once:
servo1.attach(4);
servo1.write(angle);
servo2.attach(12);
servo2.write(angle);
}
void loop() {
long duration, distance;
digitalWrite(trigPin,HIGH);
delayMicroseconds(1000);
digitalWrite(trigPin, LOW);
duration=pulseIn(echoPin, HIGH);
distance =(duration/2)/29.1;
Serial.print(distance);
Serial.println("CM");
delay(10);
if (distance (less than sign) 30) {
servo1.write(90);
servo2.write(0);
}
else {
servo1.write(0);
servo2.write(90);
}
}
Повторяем попытку...
Доступные форматы для скачивания:
Скачать видео
-
Информация по загрузке: