There are three IR proximity sensors on the Zumo. All of them are on the lower sensor board that contains the downward facing light sensors. In addition to the sensors, there are four IR emitters. There are two front IR emitters that are in standard thru-hole LED packages on the front of the robot at the top of the metal blade. There are also two side facing surface mount emitters that are on the sides where the circuit board extends through the tracks. The left front and the left side emitters operate in parallel, and the right front and right side operating in parallel.
When you issue the command to read the sensors with the command:
proxSensors.read();
The robot sends our 6 IR pulses on the left side, and 6 pulses on the right side. The pulses are at 38 kHz, which is also a standard frequency for digital pulses for IR remote control applications like TV remote controls and IR headphones. So, there is always a potential for interference. Each of the six pulses that are transmitted are at a different amplitude level. After the IR pulses are emitted, then may find an object to reflect off of and get received by the IR receivers of the robot. As the pulses travel, their amplitude drops off rather quickly (1/r^2 for each way). The further away an object is, the lower the amplitude of the received pulse. The IR receiver simply counts the number of pulses that it can measure. Let’s say an object is a medium distance away. The very low amplitude pulses can not be received with sufficient amplitude. However, medium and high power pulses would be detected, so the number of pulses would be somewhere from 3-4. If the object is very far away, maybe only the highest power pulse would be received, and the number of pulses would be 1 (or 0 if no pulses were received).
The proximity sensor read command takes care of sending the 6 pulses on both the left and the right, as well as measuring the 3 IR sensors for both the left and right sides. However, we aren’t terribly interested in the left sensor receiving from the right side or the right sensor receiving from the left side. The following functions return integers ranging from 0 to 6 depending on the amount of IR light that is reflected back.
proxSensors.countsLeftWithLeftLeds()
proxSensors.countsLeftWithRightLeds()
proxSensors.countsFrontWithLeftLeds()
proxSensors.countsFrontWithRightLeds()
proxSensors.countsRightWithLeftLeds()
proxSensors.countsRightWithRightLeds()
As previously discussed, reading one side with the opposite side LED doesn’t really provide us with a lot of information. However, the front sensor with the left LED vs the right LED does give us some useful information regarding the direction an object may be.
Our goal of this post is simply to read the proximity sensors and display the values on the LCD. As usual, we need to include the Zumo32U4 library, rename the LCD and Proximity Sensor classes to something more usable, initialize the proximity sensors, read the values, and write the values to the display. The only item that is really new is how to read the sensors, and how to get the values. It should be fairly straight forward from the example program below.
#include <Zumo32U4.h>
Zumo32U4LCD lcd;
Zumo32U4ProximitySensors proxSensors;
void setup() {
proxSensors.initThreeSensors();
}
void loop() {
proxSensors.read();
lcd.clear();
lcd.gotoXY(0,1);
lcd.print(proxSensors.countsLeftWithLeftLeds() );
lcd.gotoXY(2,0);
lcd.print(proxSensors.countsFrontWithLeftLeds() );
lcd.gotoXY(5,0);
lcd.print(proxSensors.countsFrontWithRightLeds() );
lcd.gotoXY(7,1);
lcd.print(proxSensors.countsRightWithRightLeds() );
delay(100);
}