Experiment 7 - Optical Sensor I
- 1 1. Context of the Experiment
- 2 2. Learning Goals of this Experiment
- 3 3. Literature
- 4 4. Basics/Fundamentals
- 5 5. Technical Basics & Preparations
- 6 6. Experiment Procedure
- 6.1 6.1. Setting up of the IR sensor
- 6.2 6.2. Find the distance threshold of the sensor
- 6.3 6.3. Influencing parameters on the sensor
- 6.3.1 6.3.1. Smoothness of the surface
- 6.3.2 6.3.2. Angle
- 6.3.3 6.3.3. Speed
- 6.3.4 6.3.4. Color
- 6.3.5 6.3.5. Artificial light
- 6.3.6 6.3.6. Heat
- 6.4 6.4. Distance measurement
- 6.5 6.5. Applications
- 7 7. Evaluation of Experiment Results
1. Context of the Experiment
So far, you have learned about different types of sensors that work in contact with the object you are measuring. But sometimes you can't have a connection and you need a type of sensor that can measure the parameters without contact. In this situation, optical sensors can help. Optical sensors are electronic components that detect the rays of light that hit them (incident light rays) and convert them into electrical signals. Optical sensors are components widely used in electronic devices and equipment in a variety of fields, including industrial, consumer, healthcare, and automotive.
We advise you to read once the complete description of the experiment before going to the lab.
This experiment requires you to bring a laptop to upload a program to Arduino.
2. Learning Goals of this Experiment
Knowing: Light detection, Optical concept, Distance measurement without contact
Abilities: Measuring distance, movement direction and detecting an object
Understand: Impact of light and reflection on optical sensors, Optical circuit
3. Literature
[1]. Rai, Vineet Kumar. "Temperature sensors and optical sensors." Applied Physics B 88.2 (2007): 297-303.
[2]. Santos, José Luís, and Faramarz Farahi, eds. Handbook of optical sensors. Crc Press, 2014.
[3]. Thorsten A. Kern, Hatzfeld, Christian, and Alireza Abbasimoshaei. Engineering haptic devices. Springer London Limited, 2022.
[4]. Measurement Technology lecture slides
[5]. Datasheet of the TCRT5000 reflective sensor:
4. Basics/Fundamentals
What Is an IR sensor? An infrared (IR) sensor measures and detects infrared radiation in its environment. It has different usages in daily life and in industry, like for automatic doors or TVs. This ray is not noticeable by the human eye, its wavelength ranges from 0.7 µm to 1000 µm and is divided into three regions: Near-infrared, Mid-infrared, and Far-infrared.
Usually IR sensors have two IR components: an IR transmitter and an IR receiver. The transmitter sends the IR signal and the receiver receives it and detects the desired parameter, such as the distance or presence of an object. The distance is determined by the time of light.
It is based on geometrical optics, assuming that most of the ray of light emitted by the transmitter will be reflected on the surface of the object to reach the receiver. According to the law of reflection, the direction of the reflected ray is determined by the angle the incident ray makes with the surface normal (a line perpendicular to the surface at the point where the ray hits). The incident angle and the reflected angle are in the same plane and have the same angle. The IR transmitter doesn’t emit one single ray aligned to its axis, but emits in a range of angles. This is what allows the transmitter to receive the reflected light, even though the axis of the receiver and transmitter are not coaxial.
There are many different models of optical sensors. In this experiment, you will use 2 different sensors from MH-Sensor-Series. The “flying fish” only detects the presence or not of an object on a digital output, while the other one, the TCRT5000, also outputs a value of the distance to this object. They both have a LED which shows when the sensor is powered and another LED which shows when an object is detected. The “flying fish” has 3 pins while the TCRT5000 has 4 pins. Both sensors also have a sensitivity regulator.
The different pins of the two sensors are labeled as followed:
Role | Name on “flying fish” | Name on TCRT5000 |
---|---|---|
Power supply | Vcc | Vcc |
Ground | GND | GND |
Digital output (for the detection) | OUT | D0 |
Analog output (for the distance) |
| A0 |
5. Technical Basics & Preparations
Before measuring, these aspects of measuring should be considered and thought trough:
What is supposed to be measured? What values?
What measuring device can be used for this?
What are the possible (systemic) errors and external limitations that exist in the setup?
Please download and install the program “CoolTerm” (https://freeware.the-meiers.org/) to save the data from the arduino terminal.
Also download the different codes:
6. Experiment Procedure
Take your box and check its content. It should contain the following parts:
4x IR sensors:
2x MH-Sensor-Series TCRT5000
2x MH-Sensor-Series “flying fish”, one with a bended LED and the other one with the LED straight.
1 black sheet of paper
You will also need these components from a general box:
Breadboard
Jumper wires
Arduino
6.1. Setting up of the IR sensor
The first step is to do some tests with the “flying fish” sensor (the one with only 3 pins and the straight LED). Attach the sensor to the 3D-printed attachment piece and use the power supply to provide it with 5V (with a limit of 200 mA).
The LED on the right should be green (power) while the LED on the left should be off (if there is nothing in front of the receiver).
6.2. Find the distance threshold of the sensor
Bring your hand (or a piece of paper) slowly to the sensor and detect the point when the LED turns green. You can tune this distance by turning the sensitivity regulator. Be careful, at the maximum sensitivity, the LED will constantly stay ON, while at the minimum sensitivity, the LED will constantly stay OFF.
Turn the sensitivity regulator to its minimum (to the limit in the counter-clockwise direction).
Place the experiment box at 3 cm from the sensor’s receiver.
Turn the regulator until the detection light starts flickering (this is a very delicate process).
Q-E7.6.2.1. How much did you turn the regulator to get a distance threshold of the box at 3 cm? (Check the number of marks from the minimum limit) ( save in app in the lab)
Place the experiment box at 7 cm from the sensor’s receiver.
Turn the regulator until you detect the box.
Q-E7.6.2.2. How much did you turn the regulator to get a distance threshold of the box at 7 cm? (Check the number of marks from the minimum limit) ( save in app in the lab)
Q-E7.6.2.3. Set the sensitivity the way you want, somewhere in between the min and max. Measure the distance threshold. ( save in app in the lab)
6.3. Influencing parameters on the sensor
In this part, we will try to find out about the different parameters that influence or not the detection of the sensor.
6.3.1. Smoothness of the surface
As the sensor is based on the light reflecting on the object, it is sensitive to the state of the surface of the object. Let’s find out how much it is influenced by it.
Take a really smooth object, like the screen of your phone or a mirror.
Bring it closer to the sensor until it is detected.
Q-E7.6.3.1. Measure the distance threshold of the sensor with a smooth object. ( save in app in the lab)
6.3.2. Angle
In a first step, we will try to figure out what happens if the emitter and receiver are not aligned.
Take the flying fish sensor with the bent emitter and attach it to the 3D-printed piece like you did previously.
Make sure that it is not set to the minimum or maximum threshold but somewhere in between.
Take a sheet of paper and approach the sensor from the top or the side. Do you detect anything?
Try to fold the piece of paper in a way to detect the object.
Q-E7.6.3.2.1. What is the approximate angle in which you start to detect the object? ( save in app in the lab)
Now, we will try to figure out if the orientation of the surface of the object regarding to the sensor matters or not.
Use again the flying fish sensor which is not bent.
To make it easier, you can flip the breadboard on its side in a way that the sensor is horizontal.
Place a rigid and flat object (like the side of your experiment box) right next to the receiver, aligned with its axis.
Slowly turn the object until you detect it.
Continue until the object is perpendicular to the axis of the receiver.
Repeat with a smooth object (like the screen of your phone or a mirror).
Q-E7.6.3.2.2. What is the approximate angle of the smooth object when it starts to be detected? ( save in app in the lab)
Q-E7.6.3.2.3. Does the orientation of the surface of the object impacts the ability of the sensor to detect it? ( save in app in the lab)
6.3.3. Speed
Now, we will try to figure out if the sensor can detect an object in movement and if the speed of the object influences its detection.
Move the hand slowly to the sensor until it is detected.
Do some movements, back and forth, between the threshold distance and a bigger distance. Start slowly and regularly increase the speed of your hand as fast as you can.
Q-E7.6.3.3. Does the speed of the hand seem to impact the distance threshold? ( save in app in the lab)
6.3.4. Color
The black color absorbs more light than any other color and therefore reflects it less to the sensor. We will now observe how it impacts the sensor.
Put your hand in front of the sensor at the threshold distance.
Slide the black sheet of paper below your hand and observe what happens.
Move the black sheet of paper in a way to detect it.
Q-E7.6.3.4. Measure the distance threshold of the black sheet of paper. ( save in app in the lab)
6.3.5. Artificial light
We will now try to figure out if the sensor is sensitive to artificial light.
Take a flashlight (for example from your phone) and move it closer to the sensor until you detect it.
Switch off the flashlight without moving it. What do you observe?
Q-E7.6.3.5. Does the flashlight impact the distance threshold? ( save in app in the lab)
6.3.6. Heat
Finally, we will try to figure out if the heat affects the detection of the system.
Take a warm object (like your finger) and bring it in contact to the side of the receiver, taking care of not being in front of the emitter. Observe if the sensor detects anything.
Move your hand in front of the sensor and measure the distance threshold.
Q-E7.6.3.6. Does the heat seem to impact the sensor? ( save in app in the lab)
6.4. Distance measurement
6.4.1. Reading of the analog value
Until now, we used the flying fish sensor, which is only able to detect the presence or not of an object, regarding a defined distance threshold. We will now use the TCRT5000 sensor, which is also able to output a value of the distance between the object and the sensor. This value is available on the analog output of the sensor. To read it, we will use an Arduino. As the Arduino is able to provide 5V, we will use it to power the sensor instead of the power supply on the desk.
Connect the TCRT5000 sensor as shown below.
Sensor Pin | Arduino Pin |
---|---|
GND | GND |
Vcc | 5V |
A0 | A0 |
D0 | 3 |
Connect the Arduino to the computer. You should observe the power LED of the sensor turning ON and the detection LED turning ON and OFF depending on the presence of an object in front of the sensor or not.
Flash the code Exp7_distance.ino to the Arduino.
Open the serial plotter (Tools/Serial Plotter) of the Arduino and observe the 2 variables while you move your hand in front of the sensor.
Use the sensitivity regulator to set the distance threshold of the sensor how you like. Observe if this affects the reading of the analog output of the sensor?
Q-E7.6.4.1. Measure the distance threshold of the TCRT5000 sensor. ( save in app in the lab)
6.4.2. Calibration of the sensor
The value you see for now is not a distance. The analog output of the sensor is a voltage which is proportional to the supplied voltage and to the distance. The Arduino reads this analog value and converts it with a 10-bit analog to digital converter. This means that it will map input voltages between 0 and the operating voltage (5V) into integer values between 0 and 1023. To use the sensor for distance measurement, you need to calibrate it. For this, you need to collect some datapoints, containing the analog value read by the Arduino and the real distance measured manually, in cm. Then you can find the characteristic of the sensor.
Close the Serial Plotter and open the Serial Monitor to see the values instead of the curves.
Q-E7.6.4.2. Make a table of 10 datapoints following the example below. Start from the minimum distance (about 3 cm) and finish with the maximum distance (about 10 cm). ( save in app in the lab)
Point | Analog value | Distance [cm] |
---|---|---|
1 |
| 3 |
2 |
| 3,5 |
… |
|
|
10 |
| 10 |
6.4.3. Performances of the sensor
The next step is meant to do some analysis on the sensor data.
Open the Serial Plotter of the Arduino (you have to close the Serial Monitor for that)
Move your hand back and forth, really slowly, in front of the sensor, going from the detected area to the non detected area. You should obtain a curve like that:
Regularly increase the speed of your hand until you reach your maximum speed. You should obtain a curve like that:
Now, we want to save these data in order to work on it later.
Uncomment the line Serial.print(millis()); and flash the code again to the Arduino
Close the Serial Plotter and open the program CoolTerm.
Check that the port automatically detected is the same as the one the Arduino is connected to (Options/Serial Port/Port).
Connect to the Arduino
Start a measurement (Connection/Capture to Text/Binary File/Start or Ctrl+R). Name the file “Slow_back_forth”
Do again the same movement going back and forth very slowly at least 10 times.
Stop the measurement (Connection/Capture to Text/Binary File/Stop or Ctrl+Shift+R)
Save the file to work on it later. The objective will be to find out about the precision of the sensor. ( Vips)
Start another measurement and reproduce the back and forth movement by increasing the speed until you reach your maximum speed. Name the file “Fast_back_forth”
Save the file to work on it later. The objective will be to calculate the frequency of your movement. ( Vips)
The file looks like that:
6.5. Applications
6.5.1. Counting a number of detections
This type of sensor can be used for example to count the number of persons entering a shop. For this, we will focus again on the digital output of the sensor, which detects the presence or not of an object.
Flash the code Exp7_count1.ino to the Arduino.
Move your hand back and forth in front of the sensor and observe the counter increasing in the Serial Monitor.
6.5.2. Counting a number of persons
Now, imagine that you want to count the number of persons that are actually inside the shop. You have to detect when someone enters, and when someone leaves. Therefore, we will use 2 sensors and detect the direction of movement.
Place the 2nd TCRT5000 sensor on the Breadboard next to the 1st one.
Connect it to the Arduino, in a similar way you did for the first one. The analog pin is not necessary anymore. Use these ports:
Sensor Pin | Arduino Pin |
---|---|
Sensor 1 - GND | GND |
Sensor 1 - Vcc | 5V |
Sensor 1 - A0 |
|
Sensor 1 - D0 | 3 |
Sensor 2 - GND | GND |
Sensor 2 - Vcc | 5V |
Sensor 2 - A0 |
|
Sensor 2 - D0 | 2 |
Set the sensitivity of the 2 sensors in a way that they both have the same threshold distance.
Upload the code Exp7_count2.ino to the Arduino.
Open the Serial Plotter
Move your finger in front of the sensors (going from one sensor to the other), try to move in both directions. You should observe a signal similar to this one:
The signals should partially overlap. If they don’t, place the sensor close to each other.
In the code, replace the value of “print_signal” by 0 instead of 1. Upload the code to the Arduino again.
Open the Serial Monitor (you have to close the Serial Plotter before).
Move your finger in front of the sensors, start from sensor 1 to sensor 2, do it several times and then go in the other direction. Observe the counter increasing and decreasing (you have to do it rather fast in order to make it work).
6.5.3. Odometry
Now that we have a sensor able to detect a direction of movement, we can also use it to calculate a speed of movement, from the knowledge of the distance between the 2 sensors.
Q-E7.6.5.3. Measure the distance between the 2 sensors. ( save in app in the lab)
In the code, replace the value of “print_signal” by 1 instead of 0.
Uncomment the line Serial.print(millis());
Upload the code to the Arduino again.
Check that you see the 2 signals and the timestamp value in the Serial Monitor.
Close the Serial Monitor and connect CoolTerm again. Start a measurement with CoolTerm (Ctrl+R). Name the file “Odometry”.
Move your finger in front of the sensors, from sensor 1 to sensor 2.
Stop the measurement (Ctrl+Shift+R).
Save the file to work on it later. The objective will be to calculate the speed of your finger. ( Vips)
This is the principle of the encoder sensors used for odometry to measure the speed or distance traveled by mobile robots.
7. Evaluation of Experiment Results
7.1 App in the lab
Question number | Value | Unit |
---|---|---|
Q-E7.6.2.1. | Number of marks for a distance threshold of 3 cm |
|
Q-E7.6.2.2. | Number of marks for a distance threshold of 17 cm |
|
Q-E7.6.2.3. | Threshold distance chosen for the flying fish sensor | cm |
Q-E7.6.3.1. | Threshold distance on a smooth object | cm |
Q-E7.6.3.2.1. | Angle of the folded paper | ° (degree) |
Q-E7.6.3.2.2. | Angle of the surface of the smooth object | ° (degree) |
Q-E7.6.3.2.3. | Influence of the angle of the object for detection | Boolean (1: yes, 0: no) |
Q-E7.6.3.3. | Influence of the speed of the object for detection | Boolean (1: yes, 0: no) |
Q-E7.6.3.4. | Distance threshold of the black sheet of paper | cm |
Q-E7.6.3.5. | Influence of the flashlight on the distance threshold | Boolean (1: yes, 0: no) |
Q-E7.6.3.6. | Influence of the heat on the sensor | Boolean (1: yes, 0: no) |
Q-E7.6.4.1. | Distance threshold of the TCRT5000 sensor | cm |
Q-E7.6.4.2. | Datapoint table for sensor calibration |
|
Q-E7.6.5.3. | Distance between the 2 sensors | mm |
Just as an information, you can see here an overview of the app where you will have to enter your results:
7.2. Data processing
7.2.1. Sensor characteristic
Take the datapoints from the table collected in Q-E7.6.4.2.
Plot the curve of the distance (in cm) over the analog value of the sensor.
Find a good fit for it.
Which type of fit is it (linear, polynomial, …)? ( Vips)
Find the coefficients of the following equation. ( Vips)
7.2.2. Precision of the sensor
In the file Slow_back_forth.txt that you saved before, you have the datapoints from the analog value of the sensor and the digital value of the detection.
The file looks like that:
The first column contains the timestamp, in ms.
If the first line is incomplete, like in this example, just delete it. Then import the data in your favorite software (excel, matlab,…).
Convert the analog value to a distance in cm from the characteristic function you determined before.
The object detection switches from 0 to 1 and from 1 to 0 several times. Collect the distance values for each change of state. Take the average between the 2 values (when the detection is 0 and when it is 1). This correspond to the threshold distances. ( Vips)
What is the average of the threshold distance? ( Vips)
What is the standard deviation of the threshold distance? ( Vips)
7.2.3. Frequency of the hand
Find the maximum frequency from Fast_back_forth ( Vips)
7.2.4. Speed of the finger
From the file "Odometry.txt" that you saved before and the distance between the 2 sensors measured in Q-E7.6.5.3., find the speed of your finger. ( Vips)
7.3. Vips
Value | Unit | Format |
---|---|---|
Type of fit |
| single choice |
List of coefficients |
| structure as array: [a;b;c;d] |
List of threshold distances | cm | [value_1;value_2;value_3;...;value_n] |
Average threshold distance | cm | numerical value with decimal point |
Standard deviation of the distance | cm | numerical value with decimal point |
Maximum frequency | Hz | numerical value with decimal point |
Speed | mm/s | numerical value with decimal point |
Related pages
Institut für Mechatronik im Maschinenbau (iMEK), Eißendorfer Straße 38, 21073 Hamburg