0

members

Easy Basics: Project 009c Ultrasonic Sensor HC-SR04, LCD 1602 I2C module and LEDs

of Acoptex.com in UNO

Basics: Project 009c

Project name: Ultrasonic Sensor HC-SR04, LCD 1602 I2C module and LEDs

Attachments: libraries1 and sketch1 or libraries2 and sketch2

In this project, you needed these parts :

1.Aruduino Uno R3 (you can also use the other version of Arduino)

2.Ultrasonic Sensor HC-SR04 module

3.Arduino IDE ( you can download it from here  )

4.Jumper cables

5. LCD 1602 I2C Module

6. LEDs 2 pcs (green and red color LEDs)

7. Resistor 2 pcs (220 Om each)

8. Half breadboard 1 pc

Understanding LCD 1602 I2C module

More information you can find here.

Understanding the HC-SR04 Ultrasonic Module

The HC-SR04 Ultrasonic Sensor is a very affordable proximity/distance sensor that has been used mainly for object avoidance in various robotics projects. It essentially gives your Arduino eyes / spacial awareness and can prevent your robot from crashing or falling off a table. 

The HC-SR04 ultrasonic sensor uses sonar to determine distance to an object like bats do. It offers excellent non-contact range detection with high accuracy and stable readings in an easy-to-use package. From 2cm to 400 cm or 1” to 13 feet. It operation is not affected by sunlight or black material like Sharp rangefinders are (although acoustically soft materials like cloth can be difficult to detect). It comes complete with ultrasonic transmitter and receiver module.

The HC-SR04 ultrasonic sensor uses sonar to determine distance to an object like bats do. It offers excellent non-contact range detection with high accuracy and stable readings in an easy-to-use package. From 2 cm to 400 cm or 1” to 13 feet. It operation is not affected by sunlight or black material like Sharp rangefinders are (although acoustically soft materials like cloth can be difficult to detect). It comes complete with ultrasonic transmitter and receiver module.

Features

  • Power Supply :+5V
  • DCQuiescent Current : <2mA
  • Working Current: 15mA
  • Effectual Angle: <15°
  • Ranging Distance : 2cm – 400 cm/1″ – 13ft
  • Resolution : 0.3 cm
  • Measuring Angle: 30 degrees
  • Trigger Input Pulse width: 10uS
  • Dimension: 45mm x 20mm x 15mm

Ultrasonic Sensor emits an ultrasound at 40 000 Hz which travels through the air and if there is an object or obstacle on its path It will bounce back to the module. Considering the travel time and the speed of the sound you can calculate the distance.The HC-SR04 Ultrasonic Module has 4 pins, Ground, VCC, Trig and Echo. The Ground and the VCC pins of the module needs to be connected to the Ground and the 5 volts pins on the Arduino Board respectively and the trig and echo pins to any Digital I/O pin on the Arduino Board.In order to generate the ultrasound you need to set the Trig on a High State for 10 µs. That will send out an 8 cycle sonic burst which will travel at the speed sound and it will be received in the Echo pin. The Echo pin will output the time in microseconds the sound wave traveled.For example, if the object is 10 cm away from the sensor, and the speed of the sound is 340 m/s or 0.034 cm/µs the sound wave will need to travel about 294 u seconds. But what you will get from the Echo pin will be double that number because the sound wave needs to travel forward and bounce backward.  So in order to get the distance in cm we need to multiply the received travel time value from the echo pin by 0.034 and divide it by 2.

 

You can see datasheet here.

Signals and connections of HC-SR04 Ultrasonic Module

"Trig" stands for Trigger Pulse Input

"Echo" stands for Echo Pulse Output

"VCC" stands for power supply (+5V)

"GND" stands for GND (0V)

Duration for the sound to reach echo is twice the duration required to reach the object that will create echo. That is if you shout in front of a wall the voice to reaches the wall and returns back to your ear. The moment you hear the sound, the voice has traveled twice the distance between you and the wall. Thus the time taken will be twice as the speed of sound is constant. Hence the following formula:

d = v/t;

therefore d = 29 / (time in miliseconds / 2).

or d = 340 / (time in seconds / 2).

Signals and contacts of LCD 1602 I2C module

As you can see on the back of LCD 1602 module there 4 connections: GND (-), VCC (+5V), Serial Data Line (SDA) and Serial Clock Line (SCL)

Connect the long leg of the LED (the positive leg, called the anode) to the other end of the resistor. Connect the short leg of the LED (the negative leg, called the cathode) to the GND. Resistor connected for long leg.

Wiring

The following picture shows the needed connections with the Arduino Uno 

Step by Step instruction

  1. Plug your Adruino Uno board into your PC and select the correct board and com port
  2. Open up serial monitor and set your baud to 9600 baud
  3. Find your I2C address. Each device has an I2C address that it uses to  accept commands or send messages. Load the sketch over at http://playground.arduino.cc/Main/I2cScanner and follow the instructions to use it.  By opening up the Serial monitor window after you upload the sketch, Arduino will scan the address range looking for a reply.  Even though the documentation said it was 0x27, this scanner can detect different (in my case 0x3F)
  4. Modify the sketch in attachments above (you can use the sketch below too): the line LiquidCrystal_I2C lcd(0x3F, 2, 1, 0, 4, 5, 6,7, 3, POSITIVE) (See part marked bold)
  5. Verify and upload the the sketch to your Adruino Uno.
  6. If you move the sensor the distance will change in serial monitor window and on LCD screen

Libraries:

  • See attachments on the begining of this project description - all libraries included.
  • I have used the library - NewliquidCrystal_1.3.4.zip which I downloaded, unzipped, changed the name of folder to LiquidCristal and added to libraries in my PC, for example C:\Users\toshiba\Documents\Arduino\libraries. This link you can find in Preferences of Adruino IDE program which installed in your PC. If you have LiquidCristal folder in this location already - delete this folder and copy folder, which was made by you, to this location. 
  • Ultrasonic library included in zip file.

Program/Sketch

  • See attachments on the begining of this project description. 2 different programmes included, program2 does not use any specific library for ultrasonic sensor


Other projects of Acoptex.com

« Go back to category
Is this project fake? Report it!   
Recommend to a friend
Published at 04-07-2017
Viewed: 525 times