Question

In: Electrical Engineering

Using an arduino, breadboard,  ultrasonic sensor, buzzer, lcd and red led display distance in centimeters, If needed,...

Using an arduino, breadboard,  ultrasonic sensor, buzzer, lcd and red led display distance in centimeters,

If needed, use a rotary potentiometer, male to male cable (m-m) female to male cable (f-m) or any resistor provided in the kit.

display distance in centimeters to lcd. If the object is in distance, turn on Active buzzer(play sound)

and turn on red led. If the object is not in range, display out of range or "Object now close'.  on the lcd, make sure the buzzer is off and red led is off.

Provide code and schematic

Provide code and schematic

Solutions

Expert Solution

So first i will like to discuss that how does ultrasonic sensor works and then i will try to answer the above question.

Ultrasonic Sensor : Ultrasonic sensor emits short and high frequency pulses at regular interval which travel with the speed of sound.When they strike an object they reflected back as the echo signals and the sensor himself compute the distance of object from the sensor.The range of distance upto which ultrasonic sensor can work is 20 mm to 8 m.

Formula

Velocity = (Speed)/(2*Time) where take velocity =343 m/sec(speed of sound).

CONNECTION

The circuit:

LCD RS pin to digital pin 12
LCD Enable pin to digital pin 11
LCD D4 pin to digital pin 5
LCD D5 pin to digital pin 4
LCD D6 pin to digital pin 3
LCD D7 pin to digital pin 2
LCD R/W pin to ground
220 ῼ resistor: lcd pin 15 and ground
Potentiometer wiper to LCD VO pin (pin 3) and ends to +5v and ground of arduino kit
LCD pin 16 to ground
Trig pin of the sensor to 9
Echo pin of the sensor to 10
Gnd of the sensor to ground pin of arduino.
VCC of the sensor to 5V pin

Code


#include <LiquidCrystal.h>

#define trigPin 9

#define echoPin 8

float duration;

float Inches;

float Cm;

LiquidCrystal lcd(12, 11, 5, 4, 3, 2);

void setup() {

pinMode(trigPin,OUTPUT); //sets trigpin as output to send ultrasound

pinMode(echoPin,INPUT); //sets echopin as input to receive ultrasound

Serial.begin(9600); //sets 9600 as baud rate

lcd.begin(16, 2); //enable 16 columns and 2 rows in the lcd

}

void loop()

{

lcd.setCursor(0,1); //sets cursor at 1st row and 2nd coulumn

digitalWrite(trigPin, LOW); //sets trigpin to LOW so that it do not emits ultrasound

// initially

delayMicroseconds(2);

digitalWrite(trigPin, HIGH); //sets trigpin to HIGH state to emit ultrasound

delayMicroseconds(10);

digitalWrite(trigPin, LOW);

duration = pulseIn(echoPin, HIGH); //reads the travel time of the pulse

Inches = microsecondsToInches(duration); //function

Cm = microsecondsToCentimeters(duration); //function

lcd.setCursor(0,0); //sets cursor to initial position

lcd.print("INCHES");

lcd.setCursor(7,0);

lcd.print(Inches);

lcd.setCursor(0,1);

lcd.print("CM");

lcd.setCursor(7,1);

lcd.print(Cm);

delay(100);

}

long microsecondsToInches(long microseconds)

{

return microseconds / 74 / 2; /* sounds travels at the speed of 1130 feet per second. There are 74.16 microseconds per inch. The time that will be received is of full journey of ultrasound i.e. forward and backward. So to calculate the distance we have to divide total time by number of microseconds per inch i.e. 74. We have to further divide it by 2 in order to calculate the distance of only forward path and not the total distance*/

}

long microsecondsToCentimeters(long microseconds)

{

return microseconds / 29/ 2; /*Speed of sound is 340m/s. So it takes 29 microseconds to travel 1 centimeter length of the path.All the working is same as explained in calculation of inches*/

}

Check the image for Schematic Diagram


Related Solutions

We need to code an LCD with a temperature and humidity sensor for the arduino UNO...
We need to code an LCD with a temperature and humidity sensor for the arduino UNO board. The LCD should simply display the temperature and humidity reading from the DHT11 sensor. We must do this without the use of arduino or lcd libraries, and only use raw c code. For example we need to use PORTD |= (1<<5); to set the pin to 5. The LCD is connected to pins A0 and A1, and it is using I2C. The temperature...
CODE WITH ARDUINO: With an RGB Led, Use the iterative loop (for loop) to make red,...
CODE WITH ARDUINO: With an RGB Led, Use the iterative loop (for loop) to make red, blue, and green. Use ‘analogWrite’ command inside the 'for loop.' Use the value ranges from 0-255 for this command. So, to activate any of the pins, the value should be 255. To turn off 0. pattern: First for loop Red light – delay – Second for loop for blue light – delay - Third for loop for green light - delay. (The resulting lights...
A PIC C code for Interfacing Ultrasonic sensor using PIC C 18F8722 microcontroller  
A PIC C code for Interfacing Ultrasonic sensor using PIC C 18F8722 microcontroller  
I am trying to work on LCD display using VHDL. I want to display the word...
I am trying to work on LCD display using VHDL. I want to display the word “TECH” and make it blink on LCD. I need the complete source code (If anyone helps me and the code works I will offer bonus cash for it )
What would be the wiring setup and coding using an Arduino for a display of the...
What would be the wiring setup and coding using an Arduino for a display of the temperature of the room it is in?
Draw the schematic and code for an Arduino controlled system using a temperature sensor and fan.
Draw the schematic and code for an Arduino controlled system using a temperature sensor and fan.
Write an Arduino Program that detects a reflective surface using the line sensor array of a...
Write an Arduino Program that detects a reflective surface using the line sensor array of a QTR-3RC (*Must be specific to this sensor! please this is important*) Must include a function that when called returns.. 0 (line to the left of the robot) 1 (line under the robot on the left side) 2 (line under the robot on the right side) 3 (line to the right of the robot) Output the results to the serial port in 0.5 second intervals...
Write an Arduino Program that detects a reflective surface using the line sensor array of a...
Write an Arduino Program that detects a reflective surface using the line sensor array of a QTR-3RC (*Must be specific to this sensor! please this is important*) Must include a function that when called returns.. 0 (line to the left of the robot) 1 (line under the robot on the left side) 2 (line under the robot on the right side) 3 (line to the right of the robot) Output the results to the serial port in 0.5 second intervals...
Using Arduino to blink an LED in morse code. Morse code is used as one of...
Using Arduino to blink an LED in morse code. Morse code is used as one of the methods for communications. It consists of a series of “dit” and “dah” symbols. (i) Develop an Arduino program to produce a Morse code to express the phrase “We are students” using Pin #13 (connect an LED that is in series with a 220-Ω resistor to Pins #13 to view the information sent via the Morse code). Express one “dit” with LED on for...
Design a security system using red, green, and yellow LEDS, along with MUX chip, buzzer and...
Design a security system using red, green, and yellow LEDS, along with MUX chip, buzzer and ultrasonic sensor.
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT