0% found this document useful (0 votes)
27 views

Project3 Ultrasonicwith LCD

The document describes a project to create an obstacle avoidance system using an ultrasonic sensor. The system measures distance and displays information on an LCD based on distance thresholds, setting different colored LEDs. It lists materials needed, provides the Arduino code, and notes the wiring.

Uploaded by

christiantc0000
Copyright
© © All Rights Reserved
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
27 views

Project3 Ultrasonicwith LCD

The document describes a project to create an obstacle avoidance system using an ultrasonic sensor. The system measures distance and displays information on an LCD based on distance thresholds, setting different colored LEDs. It lists materials needed, provides the Arduino code, and notes the wiring.

Uploaded by

christiantc0000
Copyright
© © All Rights Reserved
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 2

1.

Description: Obstacle avoidance using Ultrasonic sensor

In this project you are going to create a system which is supposed to measure the distance and also
display some information on the LCD and set on led light whever necessary. If the distance is in the
range of 10 to 50 cm then you will display “the risk is high” and set the red LED on, if the distance is
greater than 50cm and less or equal to 100cm then the risk is medium and set the yellow LED on, if the
distance is greater than 100cm then display no risk and set the green light on

2. Materials

1. Arduino.
2. ultrasonic sensor ( Hc-sr04 ).
3. LCD display with I2C
4. Resistor 220ohm.
5. LED.
6. Breadboard.
7. Jumper wire.

3. Program
/*
* Created by ArduinoGetStarted.com
*
* This example code is in the public domain
*
* Tutorial page: https://arduinogetstarted.com/tutorials/arduino-ultrasonic-sensor-lcd
*/

#include <LiquidCrystal_I2C.h>

LiquidCrystal_I2C lcd(0x27, 16, 2); // I2C address 0x3F, 16 column and 2 rows

int trigPin = 9; // TRIG pin


int echoPin = 8; // ECHO pin

float duration_us, distance_cm;

void setup() {
lcd.init(); // initialize the lcd
lcd.backlight(); // open the backlight
pinMode(trigPin, OUTPUT); // config trigger pin to output mode
pinMode(echoPin, INPUT); // config echo pin to input mode
}
void loop() {
// generate 10-microsecond pulse to TRIG pin
digitalWrite(trigPin, HIGH);
delayMicroseconds(10);
digitalWrite(trigPin, LOW);

// measure duration of pulse from ECHO pin


duration_us = pulseIn(echoPin, HIGH);

// calculate the distance


distance_cm = 0.017 * duration_us;

lcd.clear();
lcd.setCursor(0, 0); // start to print at the first row
lcd.print("Distance: ");
lcd.print(distance_cm);

delay(500);
}

4. Wiring

You might also like