Using Arduino with Parts and Sensors – Photoreflector

Arduino Setup

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.

Today’s Electronics Recipe

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

What Is a Photoreflector?

Photo Reflector
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.

Use a Simple Circuit to Display an Input Value

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.

Photoreflector Test Circuit
Figure 1 Diagram of the photoreflector test circuit diagram

Arduino photoreflector test circuit
Picture 2 Test circuit for the photoreflector

Arduino Display Monitor Input
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.

Photoreflector ultraviolet LED
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.

Use the Photoreflector Properties

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.

Arduino Setup
Picture 4 Depending on whether the box is open or closed, the LED lights up

Photoreflector
Picture 5 The photoreflector is positioned at the box edge

Arduino circuit LED light up based on the photoreflector values
Figure 3 Circuit in which the LED lights up depending on the photoreflector value


The photoreflector measures a value of 2~5 when the box is closed, but immediately goes over 200 when it is slightly opened; hence, the LED is set to light up when the value exceeds 200. The “if” statement condition needs to be changed for different environments. So, first examine the environment you’re in and change the value accordingly.

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!

You Can Measure Your Pulse? Why?

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.

Measuring Pulse

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).

Photoreflector Test Circuit
Figure 4 Photoreflector test circuit diagram

Checking pulse with photoreflector
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.

d01b770855ca66407b00e809ea91cde6

Figure 5 Data graphed in Excel (delay set to 50)

5390746d797de4e4f86751ed5a58b06b

Figure 6 Data graphed in Excel (delay set to 100)

8ff322e7eb9735d6937b6f04d2bb500f
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.

Using a Function to Make It Easier to See the Pulse

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.

91b0b6f5144c6cdea073e606970f917a
Figure 8 A graph with added innovation in the function

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.

Summary

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.