Arduino Tutorial #10 Ultrasonic sensor as a counter with Arduino

preview_player
Показать описание
Arduino Tutorial #10 Ultrasonic sensor as a counter with arduino
Scroll down for code.....
Please like & Subscribe for more videos

If you want to support my video please buy any product through my amazon affiliate link. I will receive a commission, at no extra cost to you.

LIST OF COMPONENT (affiliate links)

#define trigPin 13
#define echoPin 12
int counter = 0;
int currentState = 0;
int previousState = 0;
void setup() {
pinMode(trigPin, OUTPUT);
pinMode(echoPin, INPUT);
}

void loop() {
long duration, distance;
digitalWrite(trigPin, LOW);
delayMicroseconds(2);
digitalWrite(trigPin, HIGH);
delayMicroseconds(10);
digitalWrite(trigPin, LOW);
duration = pulseIn(echoPin, HIGH);
distance = (duration/2) / 29.1;
//instead of parenthesis () put angle bracket as YouTube description does not allow angle bracket
if (distance (= 10){
currentState = 1;
}
else {
currentState = 0;
}
delay(100);
if(currentState != previousState){
if(currentState == 1){
counter = counter + 1;
}
}
}
Рекомендации по теме
Комментарии
Автор

if the object stays in front of the sensor it will continue counting, can you give me a lead to resolve this issue?

cristianosoares
Автор

Thank you for sharing this knowing! I was wondering how I can increase the distance to 10ft?

echang
Автор

good job hermano!!!! bendiciones a la familia- Bless You

santiagoabregu
Автор

I like the Off the ranch music at the beginning 🤣

gflaig
Автор

Hi Serdar

thanks for sharing this amazing tutorial, iwas wondering if you know how we can use this sensor to count visitors in and out. is it possible to use just this sensor to count visitors who enters a room and who leaves the room?

many thanks

rabiibrahimi
Автор

I done this but circuit is not working

kishorekumars
visit shbcf.ru