0% found this document useful (0 votes)
13 views8 pages

Lab Report

The lab report details an experiment using an ultrasonic sensor with an Arduino UNO to measure distances and control LED indicators based on those measurements. The experiment involved setting up the circuit, writing code to process distance data, and displaying results on an oscilloscope. The findings demonstrated the sensor's reliability and potential applications in automation and safety systems, while also highlighting areas for future improvement.

Uploaded by

Ahmed Omer
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
13 views8 pages

Lab Report

The lab report details an experiment using an ultrasonic sensor with an Arduino UNO to measure distances and control LED indicators based on those measurements. The experiment involved setting up the circuit, writing code to process distance data, and displaying results on an oscilloscope. The findings demonstrated the sensor's reliability and potential applications in automation and safety systems, while also highlighting areas for future improvement.

Uploaded by

Ahmed Omer
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 8

Lab Report - Round 1 (LSS-040)

Introduction:

In this round, we experimented with the multi-faceted applications of the ultrasonic


sensor; a versatile digital component that allows the completion of a plethora of tasks,
specifically according to conditions relating to distance. The circuit includes an
ultrasonic sensor and Arduino UNO as a whole. Our primary task was to investigate
distance values, and display this information in multiple ways. The investigation involved
multiple additions to our fundamental circuit. Furthermore, the overall experiment was
organized in such a way that exposure to laboratory work remained a core component
of the round.

Materials:

The experiment centered around materials related to the Arduino UNO microcontroller.
Materials Quantity Use

Ultrasonic Sensor 1 To measure the distance of


an obstacle or object,
according to a defined range.

LEDs 3 Turning on/off according to


whether certain conditions
relating to distance were met.

Jumper Wires 7 Make up the circuit - allowing


for current to pass through.

Breadboard 1 Columns/Rows - Used to


extend the circuit.

Oscilloscope 1 To display the distance


values in a two-channel
waveform format.
Procedure:

The experiment was conducted in three steps.

The first step was to set up the Arduino UNO board. All the components had to be
connected to it, as it was the main power source. Jumper wires and a breadboard were
utilized in order to extend the grid, and to ensure the provision of positive (VCC) and
negative (GND) power to the respective parts.
Firstly, we set up the connections for the ultrasonic sensor. We connected the ‘trig’ pin
to digital pin 7, and the ‘echo’ pin to digital pin 8. By way of the breadboard, we also
made sure the sensor was provided with ample amounts of both VCC and GND power.
The use of the breadboard was essential in securing availability of these two critical
power sources for the LEDs.

Next, we wired the LED connections. The shorter pins were plugged into the negative
part of
the breadboard (power supplied by the GND pin on the Arduino), while the longer pins
were plugged into the breadboard and attached to digital pins via jumper wires.

The second step we took was to write and implement the code. A copy of the code used
in the program is attached below. The comments are also attached, so that proper use
of the code is identified.

The third step was planned with reference to the oscilloscope. The assignment was to
showcase distance values on the oscilloscope. Two channels of waveforms were used
for this step.

We attached the original setup of the ultrasonic sensor and LEDs with the oscilloscope.
Moving on, we tweaked the waveforms accordingly - and depending on the distance,
waves formed further apart or closer to the origin point.

CODE:

We began by declaring the pinouts of the components, the trigger and echo pins and
the LEDs are connected to the digital pins:

const int trigpin = 7;


const int echopin = 8;
int green = 9;
int yellow = 10;
int red = 11;

In the setup part, we declared the input/output states of the components, and initialize
the serial monitor:

void setup() {
pinMode(trigpin, OUTPUT);
pinMode(echopin, INPUT);
pinMode(green, OUTPUT);
pinMode(yellow, OUTPUT);
pinMode(red, OUTPUT);
Serial.begin(9600);
}

In the void loop, the Trigger pin is initially set to off/ low, then with a little
delay, it is toggled between the HIGH and LOW states:

void loop() {
long duration, distance;
digitalWrite(trigpin, LOW);
delayMicroseconds(2);
digitalWrite(trigpin, HIGH);
delayMicroseconds(10);
digitalWrite(trigpin, LOW);

Furthermore, the echopin is signaled to calibrate the duration:

duration=pulseIn(echopin, HIGH);
Distance formula is applied to the result of echopin, and the results are displayed on
the serial monitor:

distance=(duration*0.0343)/2;
Serial.print("distance: ");
Serial.println(distance);
delay(100);

The if and else block is used to turn the leds on when distance is calculated, red for
less than 20, yellow for 20 to 50, and green for values exceeding 50:
if (distance>=50) {
digitalWrite(green, HIGH);
digitalWrite(yellow, LOW);
digitalWrite(red, LOW);
} else if (distance>=20) {
digitalWrite(green, LOW);
digitalWrite(yellow, HIGH);
digitalWrite(red, LOW);
} else if (distance<20) {
digitalWrite(green, LOW);
digitalWrite(yellow, LOW);
digitalWrite(red, HIGH);
} else {
digitalWrite(green, LOW);
digitalWrite(yellow, LOW);
digitalWrite(red, LOW);
Results:

Task 1:
The first task was to measure the distance using the Ultrasonic sensor. After
writing the code, connecting the ultrasonic sensor to the Arduino UNO
microcontroller, the distance was shown on Arduino's serial monitor in
centimeters. Moreover, it regularly updated itself - consistently responding
to any changes in distance.

Task 2:
The next step was to use the ultrasonic sensor's ability to measure distance
to turn on LED lights. We wrote the code in such a way that the three LED
lights; green, yellow and red, automatically activated/deactivated
depending on the distance of the object from the sensor. The red LED
turned on smoothly with negligible delay when the distance was less than
20 centimeters. The yellow LED was lit when the distance was between 20
and 50 centimeters. The green LED turned on when the distance increased
beyond 50 centimeters. This was visual proof that the sensor was accurately
measuring the distances.
Task 3:
Lastly, the most difficult task was to represent the distance values produced
by the ultrasonic sensor on the oscilloscope. Sticking with the same code,
we initialized the oscilloscope by setting up Channel 1 and Channel 2 pins,
and assigning the maximum and minimum values. The circuit was attached
to the probes of the oscilloscope. We then fiddled with the potentiometers
of the oscilloscope to ensure there was adequate distance between the
representations of both channels, in order to prevent them from becoming
illegible and impaired. In this way, we ensured accurate and clear
representation of the values read by the sensor.

Discussion:

The experiment precisely demonstrated the use of an ultrasonic sensor for distance
measurement and control of LED indicators from those measures. Every task provided
valuable insight and highlighted different issues regarding the functionality of sensors
and representation of data.

Task 1: Measuring Distance with the Ultrasonic Sensor:


The first exercise was to measure distances using an ultrasonic sensor. It was
successfully displayed within the serial monitor in the Arduino, therefore proving that
this sensor would be capable of measuring distances in real-time. The results were not
varied and showed reliability in reading distances within the expected range.

Task 2: Control of LEDs Depending on the Distance:

In the second exercise, we used the distance measurements obtained from the
ultrasonic sensor to drive three LEDs: green, yellow, and red. The LEDs turned on and
off well with respect to the threshold values chosen for distances in the code, and with
negligible delay. This exercise clearly demonstrated a practical use of the sensor in a
real-life application e.g. detecting obstacles or proximity warnings. The smooth
transition of the LEDs when the distance changed further underpinned the preciseness
and responsiveness of the sensor.

Task 3: Distance Display on Oscilloscope:

The last exercise was the most challenging, and it involved distance values being
represented on an oscilloscope. For this exercise, it was necessary to set up the
channels properly on the oscilloscope and perform calibration using potentiometers. We
eventually did manage to get the readings from the ultrasonic sensor onto the
oscilloscope, showing a graph of the distance data. In this exercise, we have learned
that calibration has to be correct, and ultrasonic distance sensors can be connected
with other measuring devices for further in-depth analysis.

Significance:

The experiment clearly demonstrated the flexibility and accuracy of the ultrasonic
sensor for application in many such fields. The successful completion of all tasks proved
the reliability of the sensor in the area of distance measurement and control
applications. The seamless functioning of the LEDs on distance thresholds shows
potential for practical implementations in safety and automation systems.

Probable further improvements:

Although the experiment was a success, there were a few more considerations. The
accuracy of these distance measurements themselves might be altered by temperature
or humidity, which is not taken into account in this experiment. Future iterations would
include calibrating the sensor at various environmental conditions to check the
robustness and regularity of its performance. In addition, code optimization for speed
and different ways of data visualization can be implemented to provide a better user
experience for the whole experiment.

According to our judgment, the experiment verified the functionality and accuracy of the
ultrasonic sensor in distance measurement and output control as a function of distance
readings. The tasks have given us an all-rounded understanding of the capabilities this
sensor can deliver and its potential applications, which now opens ways for further
exploration and optimization.

Conclusion:

Conclusively, we learned about the use of ultrasonic sensors and integrated it with the
Arduino UNO, whilst also writing code for communication between these components in
the Arduino IDE software. Then we visually displayed the readings with red, yellow and
green LEDs. Lastly, we connected our setup with an oscilloscope and observed the
fluctuations in both channels, bringing our experience to an end. It was a great
experience that has helped us refine our programming skills and develop a greater
in-depth understanding of the coordination between the different components used in
the experiment.

You might also like