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

Arduino Ultrasonic Sensor Navigation System Report

Uploaded by

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

Arduino Ultrasonic Sensor Navigation System Report

Uploaded by

Muhammad Ahmad
Copyright
© © All Rights Reserved
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
You are on page 1/ 6

Arduino Ultrasonic Sensor Navigation System Report

Objective
The objective of this assignment is to design a navigation system using Arduino UNO and three
ultrasonic sensors (HC-SR04) to detect objects and navigate based on their proximity. The system uses
LEDs to indicate the proximity of objects detected by the sensors.

Components
 Arduino UNO: The microcontroller used to control the system.
 3 x HC-SR04 Ultrasonic Sensors: Sensors to measure distance from objects.
 LEDs: Three LEDs to indicate the proximity of objects.
 Resistors: Used in series with LEDs to limit current.
 Breadboard and Jumper Wires: For building the circuit and making connections.

Functionality

1. Sensor Setup
o Connect one ultrasonic sensor each to the front, left, and right of the Arduino UNO.
2. Distance Measurement
o Front Sensor:

 Measure the distance using the front sensor.


 LED indicates proximity:
 Dim LED: Object is far from the sensor.
 Brightening LED: Object is approaching the sensor.
 Threshold: Once the object is close enough, a threshold triggers
navigation to the next sensor.

o Right Sensor:
 Repeat the LED indication based on distance:
 Dim LED: Object is far.
 Brightening LED: Object is approaching.
 Threshold: Shift to the left sensor when the object reaches a certain
distance.
o Left Sensor:
 LED indication repeats:
 Dim LED: Object is far.
 Brightening LED: Object is approaching.
3. Navigation Logic
o Begin with the front sensor.
o Progress to the right sensor when an object approaches.
o Finally, switch to the left sensor for proximity indication.
4. TinkerCAD Requirement
o Platform: Utilized TinkerCAD for simulation. TinkerCAD offers an intuitive
environment for circuit design and simulation.

Implementation

The implementation of the navigation system involves setting up the sensors and LEDs, coding
the Arduino to handle sensor readings, and controlling the LEDs based on the proximity of
objects. The following steps outline the process:

1. Connecting Sensors and LEDs


o Connect each HC-SR04 sensor to the Arduino UNO. The trig and echo pins of
each sensor are connected to digital pins on the Arduino.
o Connect the anode of each LED to a PWM-capable pin on the Arduino through a
resistor, and connect the cathode to ground.

Arduino Code

 The code initializes the sensors and sets up the pins for the LEDs.
 In the loop, the distance to an object is measured using the HC-SR04 sensors.
 The LEDs are controlled based on the measured distance, with their brightness varying to
indicate proximity.

 #include <LiquidCrystal_I2C.h>
 int front_echo = 6;
 int front_trig = 7;
 int right_echo = 12;
 int right_trig = 11;
 int left_echo = 10;
 int left_trig = 9;
 int front_led = A0;
 int right_led = A1;
 int left_led = A2;

 float front_duration, right_duration, left_duration;
 int front_distance, right_distance, left_distance;
 LiquidCrystal_I2C lcd_1(32, 16, 2);
 void front() {
 digitalWrite(front_trig, LOW);
 delayMicroseconds(2);
 digitalWrite(front_trig, HIGH);
 delayMicroseconds(10);
 digitalWrite(front_trig, LOW);
 front_duration = pulseIn(front_echo, HIGH);
 front_distance = (front_duration * 0.0343) / 2;
 }
 void right() {
 digitalWrite(right_trig, LOW);
 delayMicroseconds(2);
 digitalWrite(right_trig, HIGH);
 delayMicroseconds(10);

 digitalWrite(right_trig, LOW);
 right_duration = pulseIn(right_echo, HIGH);
 right_distance = (right_duration * 0.0343) / 2;
 }
 void left() {
 digitalWrite(left_trig, LOW);
 delayMicroseconds(2);
 digitalWrite(left_trig, HIGH);
 delayMicroseconds(10);
 digitalWrite(left_trig, LOW);
 left_duration = pulseIn(left_echo, HIGH);

 left_distance = (left_duration * 0.0343) / 2;
 }
 void setup() {

 lcd_1.init();
 pinMode(front_trig, OUTPUT);
 pinMode(right_trig, OUTPUT);
 pinMode(left_trig, OUTPUT);
 pinMode(front_echo, INPUT);
 pinMode(right_echo, INPUT);
 pinMode(left_echo, INPUT);
 pinMode(front_led, OUTPUT);
 pinMode(left_led, OUTPUT);
 pinMode(right_led, OUTPUT);
 } // C++ code
 void f_away(){
 analogWrite(front_led,100);

 }
 void f_approaching(){
 for(int i=100;i<255;i++){
 i++;
 analogWrite(front_led,i);
 }
 }
 void r_approaching(){
 for(int i=100;i<255;i++){
 i++;
 analogWrite(right_led,i);
 }
 }
 void l_approaching(){
 for(int i=100;i<255;i++){
 i++;
 analogWrite(left_led,i);
 }
 }
 void r_away(){
 analogWrite(right_led,100);
 }
 void l_away(){
 analogWrite(left_led,100);

 }
 //
 void loop() {
 left();
 right();
 front();
 lcd_1.setCursor(0,0);
 lcd_1.print("Front:");
 lcd_1.print(front_distance);
 lcd_1.print("cm");
 lcd_1.setCursor(10,0);
 lcd_1.print("left:");
 lcd_1.print(left_distance);
 lcd_1.setCursor(0,1);
 lcd_1.print("cm");
 lcd_1.print("RIGHT:");
 lcd_1.print(right_distance);
 lcd_1.print("cm");
 if(front_distance<80){
 f_approaching();
 // Delay a little bit to improve simulation performance
 }else{
 f_away();
 }
 if(left_distance<80){
 l_approaching();
 // Delay a little bit to improve simulation performance
 }else{
 l_away();
 }
 if(right_distance<80){
 r_approaching();
 // Delay a little bit to improve simulation performance
 }else{
 r_away();
 }
 }

Challenges Faced

1. Sensor Interference: One of the challenges faced was interference between the ultrasonic
sensors. To mitigate this, the sensors were triggered sequentially rather than simultaneously.
2. LED Control: Another challenge was ensuring smooth control of the LED brightness. This was
addressed by mapping the distance measurements to appropriate PWM values for the LEDs.

Conclusion

The Arduino Ultrasonic Sensor Navigation System successfully detects object proximity and navigates
based on sensor readings. TinkerCAD was effectively used for simulation, allowing for easy design and
troubleshooting of the circuit. The project provided valuable experience in interfacing sensors with
Arduino and controlling output devices based on sensor input.

You might also like