Department of Electrical Engineering
DEC50122 – EMBEDDED ROBOTIC
PRACTICAL WORK NO : 2
TITLE : SENSOR
LECTURER’S NAME : 1) PUAN LATENAZURAINI BINTI SAARI
PRACTICAL SKILL ATTAINMENT LAB REPORT ATTAINMENT
ASSESSMENT ASSESSMENT
(PLO5,CLO 3,P4)
S1
S2 Result
1. Equipment preparation (CLO3)
S3
S4
S1
Discussion
S2
2. Part A : LDR Sensor (CLO3)
S3
S4
S1
Conclusion
3. Part B : Ultrasonic Sensor S2
(CLO3) S3
S4
S1
Score (30)
4. Attitude towards practical S2
activity (CLO3) S3 Percentage
(30%)
S4
S1
S1
S2
Score (16)
S3
S4
S2
Total CA
S1 Marks (100%)
S2
S3
Percentage (70%)
S3
S4
S4
BIL. GROUP MEMBERS REGISTRATION NO.
1 KUHAAN GANESH 06DET20F1055
2 NASIRUDDIN B. MOHD YUSOF 06DET20F1004
3 MUHAMMAD HAMIZAN NAIM B. 06DET20F1082
SALLAHUDDIN
PORT DICKSON POLYTECHNIC DEC 50122- EMBEDDED
PRACTICAL ELECTRICAL ENGINEERING DEPARTMENT ROBOTIC
2 TITLE: SENSORS
Learning Outcome: 1. To identify the function of sensors.
2. To identify the required components in a sensor circuit.
3. To construct and test the sensor circuits.
4. To identify the theory behind sensor circuits
Tools :
Arduino board Light Dependent Resistor (LDR) Module
Ultrasonic Sensor Jumper cables
Torchlight
Theory Part A: LDR Sensor Module Interface with Arduino
Figure 1
Step 1: Introduction
LDR sensor module is used to detect the intensity of light. It is associated with both analog output
pin and digital output pin labelled as AO and DO respectively on the board. When there is light, the
resistance of LDR will become low according to the intensity of light. The greater the intensity of
light, the lower the resistance of LDR. The sensor has a potentiometer knob that can be adjusted to
change the sensitivity of LDR towards light.
Specification:
• Input Voltage: DC 3.3V to 5V
• Output: Analog and Digital
• Sensitivity adjustable
Step 2: Pin Definition
Step 3: Sample Hardware Installation (Analog Output)
Figure 2
Step 4 : Procedures
1. Connect the light sensor circuit as shown in Figure 2. Use LDR (Light Dependent Resistor)
as the light sensor.
2. Write the code and copy the sketch codes in Appendix A into the IDE.
3. Upload the sketch into the Arduino board.
4. Open Serial Monitor window.
5. Switch on torchlight and face it towards the LDR at 0 cm distance.
6. Record the reading at both Serial Monitor window.
7. Increase the distance of the torchlight from the LDR to 0cm, 5cm, 10cm, 15cm, 20cm,
25cm and 30cm. For each of the distance.
8. Record your results in Table 1 and record your summary.
Results : Part A
Distance (cm) ADC value
0 11
5 24 MARKS (4m):
10 53
15 81
20 114
25 145
30 178
Table 1
Based on the Table 1 above, plot a graph of the following using Microsoft Excel program:
a. ADC value versus distance (cm) Marks (2m)
Summary Part A Marks (2m)
LDR sensor module is used to detect the intensity of light. Where In part A,
the greater the intensity of light, the lower the resistance of LDR which mean
the resistance of LDR will become low according to the intensity of light. The
graph between distance and ADC value shows that it’s increase directly.
Lecturer signature Date
Theory Part B: Interfacing Ultrasonic Sensor with Arduino
Step 1: Components Required
Figure 3
Step 2: A Little about Ultrasonic Sensor
Figure 4
The HC-SR04 is an ultrasonic ranging module. This economical sensor provides 2cm to 400cm of non-
contact measurement functionality with a ranging accuracy that can reach up to 3mm. Each HC-SR04
module includes an ultrasonic transmitter, a receiver and a control circuit.
There are Four Pins on the HC-SR04. They are :
• Vcc (5V supply)
• Gnd (Ground) Trig (Trigger)
• Echo (Receive)
The key features to be noted are:
• Operating Voltage: 5V DC
• Operating Current: 15mA
• Measure Angle: 15°
• Ranging Distance: 2cm - 4m
Step 4: The Circuit
Figure 5
The connections are as follows:
• Vcc to 5V Pin of the Arduino.
• Gnd to Gnd Pin of the Arduino.
• Trig to Digital Pin 9 .
• Echo to Digital Pin 10.
Refer the schematics for more clarity on the connections. Few things to remember while building the
circuit
• Avoid placing the sensor on metal surfaces to avoid short circuits which might burn the sensor.
• It is recommended to put electrical tape on the back side of the sensor.
• You can also directly connect the Ultrasonic sensor to the Arduino with jumper wires directly.
Step 5 : Procedures
1. Connect the ultrasonic sensor circuit as shown in Figure 5. Use ultrasonic as the
distance sensor.
2. Write the code and copy the sketch codes in Appendix B into the IDE.
3. Upload the sketch into the Arduino board.
4. Open Serial Monitor window.
5. Use a long ruler, place it on a table surface, then mark the location of 0 cm, 10 cm, 20
cm and so on until 50 cm on the table using pencil.
6. Place the ultrasonic sensor at 0 cm pencil mark.
7. Using white plain A4 paper, get the detection by moving the paper first at 0 cm, then
10cm and so on until reaching 50 cm mark. For every mark point watch the result in
the Serial Monitor window.
8. Record your results in Table 2.
Results : Part B
Distance (cm) ADC value
0 4
10 11 MARKS (3m):
20 20
30 33
40 41
50 48
Table 2
Based on the Table 2 above, plot a graph of the following using Microsoft Excel program:
b. ADC value versus distance (cm) Marks (2m)
Summary Part B Marks (2m)
For part B, the practical used the Ultrasonic sensor to construct the
circuit and test the sensor whenever it’s work or not. The result in table 2
shows that the sensor is detect the object in front it correctly. The graph
between ADC versus distance is rise directly.
Lecturer signature Date
Discussion (10marks)
Do a discussion based on the questions below.
1. From experiment in Part A, what the function of LDR?
In Part A, the function of LDR is to detect the intensity of light. It is associated with both analog
output pin and digital output pin labeled as AO and DO respectively on the board. When there
is light, the resistance of LDR will become low according to the intensity of light.
(3 marks)
2. From experiment in Part B, what the function of Ultrasonic?
In Part B, the function of Ultrasonic is to measure the distance of a target object by emitting
ultrasonic sound waves and converts the reflected sound into an electrical signal.
(3 marks)
3. List the others input sensor in the robot world.
Sound sensor
Temperature sensor
Proximity sensor
Acceleration sensor
(4marks)
Conclusion (5marks)
After completing this practical work, we able to identify the function of sensors. In this
practical work, we have used LDR sensor and ultrasonic sensor. In Part A, we used LDR
sensor that used to detect the intensity of light. Based on the results obtained, if the distance
of the light with the sensor increases, then the value of the ADC will also increase. Next, in
Part B, we have used ultrasonic sensor that used to measure the distance of a target object.
If the distance of the object with the ultrasonic sensor increases, the value of the ADC will
also increase in Part B.
APPENDIX A:
#define LED 13
void setup()
{
Serial.begin(9600);
int i;
for(i=3;i<=5;i++)
pinMode(i, INPUT);
pinMode(LED,OUTPUT);
}
void loop()
{
int val;
while(1)
{
val=analogRead(0);
Serial.print("Value: ");
Serial.println(val);
if(val>100)
{
digitalWrite(LED, HIGH);
//Serial.println("Value is high!");
}
else
{
digitalWrite(LED,LOW);
//Serial.println("Value is low!");
}
}
}
APPENDIX B:
/*
* Ultrasonic Sensor HC-SR04 and Arduino Tutorial
*
* by Dejan Nedelkovski,
* www.HowToMechatronics.com
*
*/
// defines pins numbers const
int trigPin = 9;
const int echoPin = 10;
// defines variables
long duration; int
distance;
void setup()
{
pinMode(trigPin, OUTPUT); // Sets the trigPin as an Output
pinMode(echoPin, INPUT); // Sets the echoPin as an Input Serial.begin(9600);
// Starts the serial communication
}
void loop()
{
// Clears the trigPin digitalWrite(trigPin,
LOW);
delayMicroseconds(2);
// Sets the trigPin on HIGH state for 10 micro seconds
digitalWrite(trigPin, HIGH); delayMicroseconds(10);
digitalWrite(trigPin, LOW);
// Reads the echoPin, returns the sound wave travel time in microseconds duration
= pulseIn(echoPin, HIGH);
// Calculating the distance
distance= duration*0.034/2;
// Prints the distance on the Serial Monitor
Serial.print("Distance: "); Serial.println(distance);
}