Популярное

Arduino Tutorial 07||| Ultrasonic Sensor

148 Просмотры
Размещено
Hi guys!!! TECH BOOSTER here..... Today I taught you about the Ultrasonic Sensor and how to work with it. So enjoy the video and help me to get 200 subs... I will insert the code right below....

#define trig 2
#define echo 4
void setup() {
pinMode(trig,OUTPUT);
pinMode(echo,INPUT);
Serial.begin(9600);
}

void loop() {
digitalWrite(trig,LOW);
delayMicroseconds(2);
digitalWrite(trig,HIGH);
delayMicroseconds(10);
digitalWrite(trig,LOW);

long t= pulseIn(echo,HIGH);

long inches = t / 74 / 2;
long cm = t / 29 / 2;

Serial.print(inches); // 6in 15cm
Serial.print("in \t ");
Serial.print(cm);
Serial.println("cm");
delay(100);

}

Join our WhatsApp group and you can solve all your tech and Arduino problems.......
Link: https://chat.whatsapp.com/E4CrDordxN083y1X4OtCLU
Категория
Ардуино
Комментариев нет.