Arduino Tutorial #22 Ultrasonic sensor counter with LCD display

preview_player
Показать описание
Arduino Tutorial #22 Ultrasonic sensor counter with LCD display
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)

#include (LiquidCrystal.h) // instead of parenthesis () put angle bracket as YouTube description does not allow angle bracket
#define trigPin 13
#define echoPin 8
// initialize the library with the numbers of the interface pins
LiquidCrystal lcd(12, 11, 5, 4, 3, 2);
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;
if (distance (= 10){
currentState = 1;
}
else {
currentState = 0;
}
delay(200);
if(currentState != previousState){
if(currentState == 1){
counter = counter + 1;
}
}
}
Рекомендации по теме
Комментарии
Автор

Hello, thank you for sharing, I was wondering how would it be to "translate" this to mBlock so children can implement this to Arduino.

GreenBoyPocket
Автор

Please make winding machines counting meter digital ya tips do

MusatechU
Автор

how about the display that have I2C backpack attach to it, how do you connect the wire ?(if possible with no variable resistor include)
oh and one more thing, can you have led blink when the counter count the object passing through . i really wanna know how to make it because it my final project . please can you make a video about it . thanks

heyuthea
Автор

Can i use Arduino Nano for this project ??

hsyweightlossdiet
Автор

Robotica DIY
Thanks for your project.
do you know how to make it unidirectional with the HC SR04? for example: only enter.

dayannechilatra
Автор

i think u forgot about to change the previousState value each loop, because it keep increasing the counter value if u stand still in front of the sensor

haikalakbar
Автор

can you create a video with reset button thanks
or using infrared sensor

jay-cgonzales
Автор

when you keep something before the sensor, it just adds on....please someone give me a code so that it counts 1 even if the object stands before it

andrewgeeks
Автор

Thank You dude. This video was of great help.

divyakharg
Автор

can we use 7 segment display instead of lcd??

deeanafamily
Автор

can you give program for bidirectional counter using LCD and ultrasonic sensor

vrushalikatta
Автор

Shall we do this project without potentiometer

Jungkook_luv
Автор

My ping sensor always count. How i can resolve it?

briyansitinjak
Автор

What will happens if the object stays in front of the sensor, if it will keep on increasing what should be done to avoid

abassahmed
Автор

good work, but the problem is what if an object stops in front of the sensor, the sensor is still counting ;)

ahmedcataloglu
Автор

Good hope it's work when I will made it

mohammadubed