filmov
tv
Arduino Tutorial #22 Ultrasonic sensor counter with LCD display

Показать описание
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;
}
}
}
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;
}
}
}
Комментарии