We’ve been making a RC car until now. But from this section onwards, we’re going to use Arduino with various parts and sensors. Many parts are sold as Shields, but for other parts, we’ll have to build the circuit ourselves. To grasp the general flow of the process, let’s try using a wide range of sensors.
Time to complete – 90 minutes
Required parts
Arduino (Arduino Uno R3) https://www.adafruit.com/products/50
Breadboard https://www.adafruit.com/products/64
Photoreflector (RPR220 http://www.digikey.com/product-detail/en/RPR-220/511-1366-ND/638554)
Resistors 220Ω×2 / 512Ω×1
LED
Picture 1 Photo Reflector (ROHM RPR-220)
A photoreflector is a sensor with parts for both sending and receiving. Usually, the transmitter of the device is an infrared, blue or ultraviolet LED. The construction is such that light emitted from the transmitter is reflected off an object and received by a phototransistor on the receiver.
A photoreflector is also known as a “photo-sensor” or “photo interrupter”. It is often used by measurement machines to detect whether an object is “present” or “not-present”. In electronic kits, it’s also commonly used for robots when running on top of black lines to trace the path of the line.
Here, we’ll use a photoreflector with an infrared LED.
Let’s try to measure an input value using the photoreflector.
The transmitter is basically an infrared LED. So, we will construct the circuit in the same way we would do to make an LED light up. The photo-transistor on the receiver changes its resistance depending on the light it receives. So, we will enter this through the analog-in pin. The circuit is shown below in Figure 1.
Figure 1 Diagram of the photoreflector test circuit diagram
Picture 2 Test circuit for the photoreflector
1 2 3 4 5 6 7 8 9 10 11 12 13 |
//******************************************************************** //*Program to display the photoreflector input values //******************************************************************** int pin = 0; // void setup() { Serial.begin(9600) ; } void loop() { int val; val = analogRead(pin) ; //Read sensor value from Analog pin 1 Serial.println(val) ; //Display to serial monitor delay(100) ; // Wait 100ms } |
Figure 2 Confirmation of the input values on the serial monitor
Once the program is entered into the Arduino, we can have a look at the serial monitor (Figure 2). By placing a finger closer or further away from the photo-reflector, we can confirm changes in the value shown on the monitor.
Picture 3 Infrared LED in the photoreflector
Since it’s infrared LED, you cannot confirm whether the LED is on or not by the naked eye. If you take a photo using your smartphone camera for example, you will be able to confirm that the infrared LED is emitting a purple color, as seen in Picture 3.
The photoreflector used here has a standard detection range of 1~10mm. What can we actually do using this property? An example that comes in mind would be using it to check whether drawers, boxes or doors are opened or closed.
By adding a few corrections to the circuit in Figure 1, we arrive at this design, where by putting the photoreflector inside a box, the LED lights up depending on whether the lid is opened or closed.
Picture 4 Depending on whether the box is open or closed, the LED lights up
Picture 5 The photoreflector is positioned at the box edge
Figure 3 Circuit in which the LED lights up depending on the photoreflector value
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 |
//******************************************************************** //* Program to make LED light up on input from photo-reflector //******************************************************************** int pin = 0; // int pinLED = 13; void setup() { Serial.begin(9600) ; pinMode(pinLED,OUTPUT); } void loop() { int val; val = analogRead(pin) ; //Read sensor value from Analog pin 1 Serial.println(val) ; //Display to serial monitor //Box is open = photo-reflector value val is large if(val > 200){ digitalWrite(pinLED,HIGH); //Make LED light up } else{ digitalWrite(pinLED,LOW); //Turn off LED } delay(100) ; //Wait 100ms } |
By replacing the LED with a motor, or sending the result online through an Ethernet Shield, you can even make a jack-in-the-box that moves when opened, or place it on a door and remotely detect whether it has opened or not; there are all kinds of possible applications!
Now, I’d like to try and use the photoreflector in another interesting way.
When tracing a line, the photoreflector detects changes in color by detecting changes in the absorption of the emitted LED light by black and white materials. Why not apply this further?
By using the infrared absorption of hemoglobin in blood, we are able to measure our pulse. When our pulse gets faster, there is more blood flow. There is a greater amount of hemoglobin in our blood, and thus, by measuring the change in the value, we can apply it as a pulse sensor.
So, let’s give this a go using our current circuit. Using the same circuit as in Figure 1, place a finger on top of the photoreflector (Figure 4).
Figure 4 Photoreflector test circuit diagram
Picture 6 Put a finger on the top of the photoreflector to check your pulse
We can copy the values displayed on the serial monitor, and produce graphs using programs like Excel.
The resulting graphs are showed in Figures 5, 6 and 7. A normal pulse rate is said to be around 60~100 beats per minute. In order to obtain values in this range, we will see what happens to the graphs when we change the delay on the program side.
Figure 5 Data graphed in Excel (delay set to 50)
Figure 6 Data graphed in Excel (delay set to 100)
Figure 7 Data graphed in Excel (delay set to 500)
As seen from these graphs, the shorter the delay is, like in Figure 5, the more clearly changes in pulse (blood flow) are captured.
By trying other things, say moving your finger, or straining it more, the value quickly changes. As in Figure 7, with a delay of 500, it’s hard to tell from the graph whether it’s a pulse or simply noise from a finger movement.
Our objective this time was simply to “see” our pulse. But, there’s clearly a need to adjust your program thinking about the intervals at which data should be collected, with a view to how it is going to be used. To extract a pulse value as accurately as possible and apply it for something else, it is necessary to add changes to the circuit and the program.
It is possible to realize post-processing e.g. by adding op-amps to the circuit to amplify the photoreflector output and cut certain values. For more details, searching for “Arduino pulse” will give you lots of circuit diagrams; if you’re interested, you should give it a try.
Even without using an op-amp, it’s possible to emphasize the pulse using our current program. By adding a little innovation to the function, one can make the parts that swell upward rise even more, resulting in graphs like the one below.
Figure 8 A graph with added innovation in the function
1 2 3 4 5 6 7 8 9 10 11 12 13 14 |
//******************************************************************** //* Program to display photoreflector input //******************************************************************** int pin = 0; // void setup() { Serial.begin(9600) ; } void loop() { int val; val = analogRead(pin) ; //Read in sensor value from analog pin 1 val = (val*val)/100; //Extra innovation in the function Serial.println(val) ; //Display to serial monitor delay(100) ; //Wait 100ms } |
Here, by simply squaring the input value, parts of the function that rise upwards are made to swell even more.
At the beginning and at the end of the graph, you can see a change in the blood flow because the finger position was adjusted. We could develop this simple innovation farther and only extract the parts that are required; for those of you who learned “differential equations” in high school maths, it’s possible for you to apply them to extract only the data that is required from the graph.
In this article, we learned various ways to use one particular type of sensor, called the photoreflector. This is just the beginning. Through trial and error, it’s possible to discover new ways to use them. There are all kinds of discoveries out there, interesting ones, even ones that might shock the world (!), so you should keep on trying new things.