Lis ya 71: Pesa mosika mpe lakisa na ekrani ya LCD | Eteyelo ya Arduino Etap na Etap
Projet oyo elakisaki ndenge ya kosangisa sensor ya ultrason ya HC-SR04 na display ya LCD1602 mpo na komeka mpe kolakisa boni mosika na Arduino. Bokengi boye ezali na tina mpo na misala ebele oyo esengaka koyeba soki eloko ezali pene to mosika mpe kotala yango na miso.
Misala ya ntina:
- Robotiki: Komeka mosika mpo na kokima eloko to kotambola.
- Lisalisi ya Parking: Kosala sensor ya mosika ya parking oyo ezali pete.
- Automation ya Ndako: Kotonga système ya bongengi oyo etalelaka pene ya eloko.
- Automation ya Industrie: Kotalela mosika na mikano ya kosala biloko.
Biloko ya Matériel
Mpo na kosala projet oyo, okosengela biloko oyo:
- Arduino Uno (to carte oyo ekokani na yango)
- Sensor ya Ultrason HC-SR04
- Display LCD 1602 (version I2C ezali malamu)
- Banzela ya Jumper
Mokambi ya Bokangisi
Bokangisi bomonani na vidéo (na vidéo na 00:31). Bokeseni ya minene ezali:
- Sensor ya Ultrason: VCC na 5V, GND na GND, TRIG na pin 12, ECHO na pin 11.
- LCD 1602: VCC na 5V, GND na GND, SDA na pin A4, SCL na pin A5.
%%WIRING%%
Bokambi ya Code
Code yango esalelaka bibliothèque ya NewPing mpo na komeka mosika ya ultrason mpe bibliothèque ya LiquidCrystal_I2C mpo na kokamba LCD (na vidéo na 02:15). Baparamètres ya minene oyo bakoki kobongisama ezali:
#define TRIGGER_PIN 12 // Pin ya Arduino oyo ekangami na pin ya trigger na sensor ya ultrason.
#define ECHO_PIN 11 // Pin ya Arduino oyo ekangami na pin ya echo na sensor ya ultrason.
#define MAX_DISTANCE 200 // Mosika ya suka oyo tolingi komeka (na centimètres).
// Tia adresse ya LCD na 0x3F mpo na display ya 16 bapaya mpe 2 milɔngɔ
LiquidCrystal_I2C lcd(0x3F, 16, 2);
int VCC2 = 2; //VCC ya kobakisela LCD
TRIGGER_PIN mpe ECHO_PIN balobaka bapin ya Arduino oyo ekangami na sensor ya ultrason. MAX_DISTANCE etiyaka mosika ya suka oyo ekoki komekama. Adresse ya LCD (0x3F) ekoki kosenga kobongisama kolanda module ya LCD na yo. Pin ya VCC2 epesaka 5V ya kobakisela LCD.
Bisaleli sonar.ping_cm() mpe sonar.ping_in() esalelamaka mpo na kozwa bomekeli ya mosika na centimètres mpe na pouces (na vidéo na 05:27 mpe 06:01).
Projet/Démonstration ya Bomoi
Démonstration ya projet oyo emonani na vidéo (na vidéo na 06:42). Vidéo yango elakisaka sensor oyo ezali komeka mosika na biloko ndenge na ndenge mpe kolakisa bafololo na centimètres mpe na pouces na écran ya LCD. Moniteur ya série elakisaka bomekeli yango moko, mpo na kotalela soki bafololo ezali semba.
Baparties
- [00:04] Introduction mpe Botali ya Projet
- [00:31] Diagramme ya Bokangisi mpe Bokeseni
- [02:15] Bokanisi ya Code: Bokengi ya Sensor ya Ultrason
- [03:19] Bokanisi ya Code: Bokengi ya LCD1602
- [04:21] Bokanisi ya Code: Bokengi ya Arduino
- [04:46] Bokanisi ya Code: Boucle ya Minene mpe Display
- [06:42] Démonstration ya Bomoi
- [07:26] Sukisa
/*
* S08-03
* Using LCD1602-I2C and HC-SR04 Ultrasonic Sensor with Arduino
* Written/updated by Ahmad Shamshiri for Robojax (Robojax.com)
* on January 16, 2019 at 15:51 in Ajax, Ontario, Canada
* This code is "AS IS" without warranty or liability. Free to be used as long as you keep this note intact.*
* This code has been download from Robojax.com
This program is free software: you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation, either version 3 of the License, or
(at your option) any later version.
This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.
You should have received a copy of the GNU General Public License
along with this program. If not, see <https://www.gnu.org/licenses/>.
*/
#include <NewPing.h>
#define TRIGGER_PIN 12 // Arduino pin tied to trigger pin on the ultrasonic sensor.
#define ECHO_PIN 11 // Arduino pin tied to echo pin on the ultrasonic sensor.
#define MAX_DISTANCE 200 // Maximum distance we want to ping for (in centimeters). Maximum sensor distance is rated at 400-500cm.
NewPing sonar(TRIGGER_PIN, ECHO_PIN, MAX_DISTANCE); // NewPing setup of pins and maximum distance.
// start of settings for LCD1602-I2C
#include <Wire.h>
#include <LiquidCrystal_I2C.h>
// Set the LCD address to 0x3F for a 16 chars and 2 line display
LiquidCrystal_I2C lcd(0x3F, 16, 2);
int VCC2 = 2;
// end of settings for LCD1602-I2C
void setup() {
Serial.begin(9600); // Open serial monitor at 19600 baud to see ping results.
pinMode(VCC2, OUTPUT);// extra VCC for LCD
digitalWrite(VCC2, HIGH);//extra VCC is now HIGH (5V)
// initialize the LCD,
lcd.begin();
// Turn on the blacklight and print a message.
lcd.backlight();
lcd.clear();
lcd.setCursor (0,0); //
lcd.print("Robojax LCD1602");
}
void loop() {
delay(50); // Wait 50ms between pings (about 20 pings/sec). 29ms should be the shortest delay between pings.
lcd.clear();// clearn previous values from screen
lcd.setCursor (0,0); //character zero, line 1
lcd.print("LCD1602 HC-SR04"); // print text
// print distance in cm
lcd.setCursor (0,1); //character 0, line 2
lcd.print(sonar.ping_cm());// print distance in cm
lcd.setCursor (3,1); //character 4, line 2
lcd.print("cm");// print "cm" on the display
// print distance in inch
lcd.setCursor (7,1); //character 8, line 2
lcd.print(sonar.ping_in());// print distance in cm
lcd.setCursor (9,1); //character 4, line 2
lcd.print("inches");// print "cm" on the display
Serial.print("Ping: ");
Serial.print(sonar.ping_cm()); // Send ping, get distance in cm and print result (0 = outside set distance range)
Serial.print("cm");
Serial.print(", ");
Serial.print(sonar.ping_in());
Serial.println("in");
int distance = sonar.ping_cm();
}
Nko o na nki.
-
eBay
-
eBayPurchase LCD1602-I2C from eBayebay.us
-
AliExpressPurchase LCD1602-I2C from AliExpresss.click.aliexpress.com
-
BanggoodPurchase HC-SR04 Ultrasonic Sensor from Banggoodbanggood.com
Mokili na bisika
Pas encore de ressources.
Fichiers📁
Aucun fichier disponible.