لومړی ۷۱: واټن اندازه کول او د LCD سکرین پر ښودل | د آردوینو ګام په ګام کورس
دا پروژه ښیي چې څنګه د HC-SR04 الټراسونیک سینسر د LCD1602 ښودنې سره یوځای کړو ترڅو په Arduino کې واټنونه اندازه او ښکاره کړو. دا ترتیب د مختلفو غوښتنلیکونو لپاره ګټور دی چې د نږدېوالي کشف او بصري فیډبیک ته اړتیا لري.
عملي غوښتنلیکونه:
- روبوټیک: د خنډونو مخنیوي یا نیویګیشن لپاره د واټن اندازه کول.
- د پارکینګ مرسته: د پارکینګ ساده واټن سینسر جوړول.
- کور اتوماتیک: د نږدېوالي پر بنسټ د رڼا سیسټم جوړول.
- صنعتي اتوماتیک: د تولید پروسو کې د واټنونو څارنه.
هارډویر/اجزاوې
د دې پروژې د جوړولو لپاره، تاسو به لاندې اجزاوو ته اړتیا ولرئ:
- Arduino Uno (یا مطابقت لرونکی بورډ)
- HC-SR04 الټراسونیک سینسر
- LCD 1602 ښودنه (د I2C نسخه وړاندیز کیږي)
- جمپر تارونه
د تارونو لارښود
تارونه په ویډیو کې تشریح شوي (په ویډیو کې په 00:31). کلیدي اړیکې دا دي:
- الټراسونیک سینسر: VCC ته 5V، GND ته GND، TRIG ته پن 12، ECHO ته پن 11.
- LCD 1602: VCC ته 5V، GND ته GND، SDA ته پن A4، SCL ته پن A5.
%%WIRING%%
د کوډ تشریح
کوډ د الټراسونیک واټن اندازه کولو لپاره د NewPing کتابتون او د LCD کنټرول لپاره د LiquidCrystal_I2C کتابتون کاروي (په ویډیو کې په 02:15). کلیدي د تنظیم وړ پیرامیټرې دا دي:
#define TRIGGER_PIN 12 // د Arduino پن د الټراسونیک سینسر د ټریګر پن سره تړلی.
#define ECHO_PIN 11 // د Arduino پن د الټراسونیک سینسر د ایکو پن سره تړلی.
#define MAX_DISTANCE 200 // اعظمي واټن چې موږ یې اندازه کول غواړو (په سانتي مترو کې).
// د LCD پته 0x3F وټاکئ د 16 حروفو او 2 کرښو ښودنې لپاره
LiquidCrystal_I2C lcd(0x3F, 16, 2);
int VCC2 = 2; // د LCD لپاره اضافي VCC
TRIGGER_PIN او ECHO_PIN د Arduino هغه پنونه تعریفوي چې د الټراسونیک سینسر سره وصل دي. MAX_DISTANCE اعظمي د اندازه کولو وړ واټن ټاکي. د LCD پته (0x3F) ممکن ستاسو د ځانګړي LCD ماډل پورې اړه ولري تنظیم ته اړتیا ولري. د VCC2 پن د LCD لپاره اضافي 5V بریښنا چمتو کوي.
د sonar.ping_cm() او sonar.ping_in() فنکشنونه د واټن اندازه کولو لپاره په ترتیب سره په سانتي مترو او انچو کې کارول کیږي (په ویډیو کې په 05:27 او 06:01).
ژوندۍ پروژه/مظاهره
د پروژې یوه مظاهره په ویډیو کې ښودل شوې (په ویډیو کې په 06:42). ویډیو ښیي چې سینسر مختلفو شیانو ته واټنونه اندازه کوي او پایلې په LCD سکرین کې په سانتي مترو او انچو ښیي. سریال مانیټر ورته اندازه ګیرۍ ښیي، چې د لوستلو د تایید وسیله چمتو کوي.
فصلونه
- [00:04] پیژندنه او د پروژې کتنه
- [00:31] د تارونو ډیاګرام او اړیکې
- [02:15] د کوډ تشریح: د الټراسونیک سینسر تنظیم
- [03:19] د کوډ تشریح: LCD1602 تنظیم
- [04:21] د کوډ تشریح: Arduino تنظیم
- [04:46] د کوډ تشریح: اصلي لوپ او ښودنه
- [06:42] ژوندۍ مظاهره
- [07:26] پایله
/*
* 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();
}
Things you might need
-
eBay
-
eBayPurchase LCD1602-I2C from eBayebay.us
-
AliExpressPurchase LCD1602-I2C from AliExpresss.click.aliexpress.com
-
BanggoodPurchase HC-SR04 Ultrasonic Sensor from Banggoodbanggood.com
Resources & references
No resources yet.
Files📁
No files available.