Measure the Output of the Sharp IR Distance Sensor Exercise
GTA Marking
This is an assessed Exercise. When you have completed the
Note
Before starting these exercises, you should ensure that you have completed the circuit on the robot chassis, as suggested on
The following video is a quick demonstration of the final outcome from this exercise:
Introduction and Background
The aim of this exercise is to generate a graph of sensor measurement from the Sharp IR distance sensor against measurement distance. During this exercise, you will interface the Sharp IR distance sensor with the Arduino, record the measured voltage as a function of the distance to a target, and observe any constraints for the operation of this sensor.
Before you start this exercise, you will need to construct the circuit according to
Noise on the IR sensor
The IR sensor is not an ideal sensor and induces noise onto the output of the sensor, as shown in
A
//Read the IR sensor
irVal = analogRead(irPin);
// accumulate a further 7 readings
irVal = irVal + analogRead(irPin);
irVal = irVal + analogRead(irPin);
irVal = irVal + analogRead(irPin);
irVal = irVal + analogRead(irPin);
irVal = irVal + analogRead(irPin);
irVal = irVal + analogRead(irPin);
irVal = irVal + analogRead(irPin);
// right shift 3 places to divide by 8
irVal = irVal >> 3;
Camparing the magnitude of the noise on the IR sensor measurement, between
Experimental Setup with Lolly Stick up
The IR sensor is sensitive to picking up reflections from any surface that it is operating. It has been found from experimentation, that raising the sensor above the surface that it is operating produces improved and more consistant results.
As a result, when using the IR sensor, you should ensure that the lolly stick assembly is in the upright position, as shown in the righthand figure in the
For more details on concerning the pin connections for the Sharp GP2Y0A21YK0F distance measurement sensor, see the data sheet for the sensor on the Blackboard site:
ACS231 Blackboards Site>>Mechatronics Kit Information>> Component Data Sheets and Technical Documentation.
Expected Results
The IR sensor has a non-linear distance to output voltage characteristic, as illustrated in
Assessed Exercise
For this exercise you will write an Arduino sketch to measure the output of the IR sensor and display its value of on the serial monitor. The distance measurements should be taken at static positions, using a series of measurement points similar to:
1cm, 2cm, 3cm, 4cm, 5cm, 6cm, 7cm, 8cm, 9cm, 10cm, 15cm, 20cm, 25cm, 30cm, 35cm, 40cm, 45cm, 50cm, 55cm, 60cm, 65cm, 70cm, 75cm, and 80cm
You should plot your results in a computer package, such as Excel or MATLAB, with the x-axis as the distance measured, and the y-axis as the ADC measurement value.
Procedure:
- The starting point for this exercise is the
circuit layout for the IR sensor and the potentiometer code,POT.ini located at the end of theLED pattern exercise . - Write an Arduino sketch to read the analogue measurement value from the IR distance sensor and display the reading on the serial monitor. (It is acceptable to use a fresh copy of the
POT.ini as a template for this exercise.)
Once you have the measured value of the distance sensor being streamed to the serial monitor, you will be required to plot the distance sensor measurement value against distance measured, (with a ruler/scale).
- Perform an experiment to characterise the Sharp IR sensor between 1cm and 80cm distance. The results from this experiment should be a graph of the ADC measurement value from the Sharp IR distance sensor, against the distance from the target. Note: Your graph should have a similar characteristic to that shown in
Fig 3 .
What we expect to see from your demonstration?
When completed, your code should allow you to run an experiment to draw the following graph:
- A graph of ADC measurement value against distance.
- The trace should be correctly framed within the axes.
- Appropriate axes labels, with units and a descriptive graph title.
You should plot your results in a computer package, such as Excel or MATLAB, with the x-axis as the distance measured, and the y-axis as the ADC measurement value, as illustrated in
Fig 3
We expect you to also demonstrate the operation of your code and the output on the Serial Monitor, as describes in the procedure.
Now Get Your Work Marked by a GTA
Once you have completed your code and are satisfied with its operation, you should show your work to a GTA for marking.