Официальный сайт компании Arduino по адресу arduino.cc
HC-SR04 и LCD 1602
- Войдите или зарегистрируйтесь, чтобы получить возможность отправлять комментарии
Пнд, 06/07/2015 - 19:36
HC-SR04 вывести показания на LCD 1602 почему-то ошибок нту а на экране пусто
может есть мысли из за чего так ?
#include <LiquidCrystal.h> #include <Wire.h> LiquidCrystal lcd(12, 11, 5, 4, 3, 2); int pingPin = 7; //output 10us pulse to this pin int inPin = 6; //measure return pulse width from this pin long duration, inches, cm; int indec, cmdec; int inchconv = 147; // ratio between puls width and inches int cmconv = 59; // ratio between pulse width and cm String s1, s2; // initialise LCD library and pins void setup() { lcd.begin(16, 2); pinMode(pingPin, OUTPUT); pinMode(inPin, INPUT); } void loop() { // Send a short LOW followed by HIGH pulse to Trigger input: digitalWrite(pingPin, LOW); delayMicroseconds(2); digitalWrite(pingPin, HIGH); delayMicroseconds(10); digitalWrite(pingPin, LOW); // read the length of the return pulse on Echo output duration = pulseIn(inPin, HIGH); // convert the time into a distance (non-floating point with decimals inches = microsecondsToInches(duration); indec = (duration - inches * inchconv) * 10 / inchconv; cm = microsecondsToCentimeters(duration); cmdec = (duration - cm * cmconv) * 10 / cmconv; s1 = String(inches) + "." + String(indec) + "in" + " "; s2 = String(cm) + "." + String(cmdec) + "cm" + " "; lcd.setCursor(0, 0); // print inches on top line of LCD lcd.print(s1); lcd.setCursor(0,1); // print cm on second line of LCD lcd.print(s2); delay(100); } long microsecondsToInches(long microseconds) { return microseconds / inchconv; } long microsecondsToCentimeters(long microseconds) { return microseconds / cmconv; }
Источник вот : http://www.4tronix.co.uk/arduino/Ultra-Sonic.php
в строку 18: lcd.print("Display test"); delay (5000);
Работает?
нет
Попробуйте этот вариант. Я так у себя калибровал HC-SR04. Почему-то делить пришлось не на 59 как везде а на 76. Это для Меги. Ножки - выставьте свои.
1. Верхняя строка индикатора тёмная, а нижняя светлая?
Тогда не прошла инициализация из-за неправильного подключения.
2. Если нет- крутите потенциометр. И дальше пункт 1.
А вот этим кодом проверялась связка этого датчика с LCD1602. Тоже для Меги 2560. У меня дисплей на шине I2C (scl, sda - ножки).
Спасибо с последнем примером хорошо а состальными ругается мол библиотека не та для lcd а с последним все гуд ( фантастика какая то
В скетче из оппоста дисплей надо подключать к указанным ногам 3 строки. В #6 код для i2c.
всеь спасибо))
https://www.youtube.com/watch?v=oOdoP3dniYA