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

C Experiment 3

Uploaded by

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

C Experiment 3

Uploaded by

Rahul Rajagopal
Copyright
© © All Rights Reserved
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
You are on page 1/ 4

Experiment - 3

Aim - Distance measurement using Ultrasonic sensors with LCD Display.

Objectives –

1. To measure the distance using Ultrasonic sensor.


2. To display the measured distance in LCD Display.

Components Required –

1. Arduino Board
2. USB Cable
3. Ultrasonic Sensor
4. Jumper Wires
5. LCD Display

Circuit Diagram and Theory –

Circuit Diagram:

Figure. 1: Circuit diagram of distance measurement using Ultrasonic sensor and display
measured value in LCD.
Figure .2: An Ultrasonic sensor

Steps:

The distance measurement system using ultrasonic sensors with LED indication can be
implemented using the following steps:
 Use Ultrasonic sensor with Arduino board.
 Connect the VCC pin of the ultrasonic sensor to the 5V pin of the Arduino board.
 The GND pin to the GND pin of the Arduino board.
 The TRIG pin to pin 11 of the Arduino board, and the ECHO pin to pin 12.
 Connect the LEDs to the Arduino board. Connect the anode (positive) pin of the red LED
to pin 4 of the Arduino board through a 220-ohm resistor.
 Connect the anode (positive) pin of the green LEDs to pins 5, 6, and 7 of the Arduino
board, each through a 220-ohm resistor.
 Upload the code and use the Arduino IDE to write and upload the code to the board.
 System Test - Place an object in front of the sensors and observe the LED indication.
 The red LED should light up if the object is within 10cm of the IR sensor, and the green
LEDs should light up to indicate the distance measured by the ultrasonic sensor.

Code:

1. // I2C address scanner program


2. #include <Wire.h>
3. void setup()
4. {
5. Wire.begin();
6. Serial.begin(9600);
7. Serial.println("I2C Scanner");
8. }
9. void loop()
10. {
11. byte error, address;
12. int nDevices;
13. Serial.println("Scanning...");

14. nDevices = 0;
15. for (address = 1; address < 127; address++) {
16. Wire.beginTransmission(address);
17. error = Wire.endTransmission();
18. if (error == 0)
19. {
20. Serial.print("I2C device found at address 0x");
21. if (address < 16)
22. Serial.print("0");
23. Serial.print(address, HEX);
24. Serial.println(" !");
25. nDevices++;
26. }
27. else if (error == 4) {
28. Serial.print("Unknown error at address 0x");
29. if (address < 16)
30. Serial.print("0");
31. Serial.println(address, HEX);
32. }
33. }
34. if (nDevices == 0)
35. Serial.println("No I2C devices found");
36. else
37. Serial.println("done");
38. delay(5000); // wait 5 seconds for next scan
39. }

Additional Tasks –

1. Distance measurement using IR sensors with led indication.


2. Distance measurement using Ultrasonic sensors and display distance value.

Conclusions -

You might also like