Created
March 11, 2020 12:53
-
-
Save rafalw/b0d2cbe9ccc658d57373e1c910886b22 to your computer and use it in GitHub Desktop.
Obsługa czujnika HC-SR04
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#include <LiquidCrystal.h> | |
const int trigPin = 8; | |
const int echoPin = 9; | |
const int rs = 12, en = 11, d4 = 5, d5 = 4, d6 = 3, d7 = 2; | |
LiquidCrystal lcd(rs, en, d4, d5, d6, d7); | |
void setup() { | |
lcd.begin(16, 2); | |
lcd.noCursor(); | |
lcd.setCursor(0, 0); | |
pinMode(trigPin, OUTPUT); //Pin, do którego podłączymy trig jako wyjście | |
pinMode(echoPin, INPUT); //a echo, jako wejście | |
} | |
void loop() { | |
long czas, dystans; | |
digitalWrite(trigPin, LOW); | |
delayMicroseconds(2); | |
digitalWrite(trigPin, HIGH); | |
delayMicroseconds(10); | |
digitalWrite(trigPin, LOW); | |
czas = pulseIn(echoPin, HIGH); | |
dystans = czas / 58; | |
lcd.clear(); | |
lcd.print(dystans); | |
lcd.print(" cm"); | |
delay(2000); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment