Introduction: Ultrasonic Sensor With LCD
This is my first instructables, so sorry if I mess out with something. For quite a long time I have been thinking of using ultrasonic range finder sensor and to display it's readings on the LCD screen. I came across many different instructables on this and read many forums, but some didn't work out well. There are thousands of forums and codes out there on this, but they are too much complex. In this I have tried to keep it as simple as possible.
Step 1: Start Up
Arduino has been a sensation ever since it's creation. Beginners or Pro, everyone loves playing with Arduino and its sensors.
I got ultrasonic sensor few weeks back and two days back I started building this thing. It's not very tough.
Step 2: Things Required
All the stuff you need for this is real basic.
1. An Arduino
2. LCD Screen or A shield will be better.
3. An Ultrasonic Sensor
4. A Breadboard
5. 30 minutes of your time.
I used an Arduino Mega but any Arduino would work well. Mega is better because I had LCD shield and it covered UNO's all pins. Mega has more digital pins so it becomes easy to interface. If you have LCD, then you have to interface the pins yourself. Shield is better as it saves time.
Step 3: Initializing LCD
First connect your LCD shield on to your Arduino and test the basic HELLO WORLD program. If it works then BINGO and it doesn't you might wanna look into your interface pins.
LiquidCrystal lcd(12, 11, 5, 4, 3, 2). These are the interface pins used in example code. But if you have robot shield which you bought from ebay then this won't work for you. I had the robot shield so this interface didn't work for me. I used different pin interface. My LCD is 16x2.
LiquidCrystal lcd(8,13,9,4,5,6,7) this pin interface and this worked fine for me. If the problem still prevails try removing that 13 and then try. If still it doesn't work then you have to surf the web or contact your seller to figure out.
However, if the lcd works fine then most of the part is done.
Step 4: Testing Ultrasonic Sensor
Now it's ultrasonic sensor's turn to be tested. There are four pins in your Ultrasonic Sensor (HC-SR04).
The pin interface is as follows :
VCC pin : 5V on your Arduino
Trig pin : D12 on your Arduino.
Echo pin : D11 on your Arduino.
GND pin : Ground on your Arduino.
You might wanna need Jumper wires to easily connect the ultrasonic sensor to Arduino.
Download the zip file and unzip it. Then copy paste it in your Library folder in your Arduino folder. Then restart the Arduino IDE and you should be able to see it. Then run the New Ping example sketch. I found the library here :
Run the following program to test if your ultrasonic sensor works fine.
If it does you should be able to see some reading on your serial monitor.
Step 5: Finalizing
Now if everything works fine you might wanna add the lcd and finish the project.
For this I used my own code so the pin configuration is bit changed.
Now connect as follows :
Trig Pin : D31
Echo Pin : D22
Rest all is same.
Now upload this final code and your project should fine.
This is a good startup project. You can further play with the ultrasonic sensor by connecting a Servo or LED and using if else conditional statement to mess with the distance detection.
If it work for you, do comment and do Thumbs Up.