Comment on page
IR Distance Sensor
This module integrates two IR distance sensors, it measures distance through reflected light waves, It is used to detect the presence of an object within a specific range. The sensor consists of an IR LED and a photosensor (phototransistor) pair. The light emitted by the IR LED gets reflected by any object placed in front of the sensor and this reflection is detected by the photosensor(phototransistor). Any white (or lighter) colored surface reflects more than a black (or darker) colored surface. It is suitable to be used to measure complex objects, such as tracing an object.
Connecting to the NyBoard with wire as shown in the following picture:
For specific use, the end connected to the sensor can be fixed on the robot's head (included in Bittle's mouth, or attached to the top of Nybble's head), of course, you can also use your creativity according to your needs.
The code using this sensor has been integrated into the OpenCat project. Uncomment the line
#define DOUBLE_INFRARED_DISTANCEin the OpenCat.ino, as shown in the figure below, and then use the Arduino IDE to upload the sketch to the robot main board. The sketch can reproduce the example function of integrating the robot action.
If you want to test the function of this sensor alone or want to learn more about its principle. You can use the Arduino IDE to upload the demo sketch(testDoubleInfraredDistance.ino), as shown below:
This demo sketch implements real-time printing of the analog values (rL, rR) and data that have been processed (dL,dR) of the two analog pins (A2 and A3) in the serial monitor. You can also use the serial plotter to view the two analog pins (A2 and A3) more intuitively. The waveform graph is generated by the analog value of the pin output along the time axis.
The demo code is in the OpenCat code repository on GitHub (specific path: OpenCat/ModuleTests/testDoubleInfraredDistance). You can visit our GitHub code repository https://github.com/PetoiCamp/OpenCat to download the complete code, as shown in the following picture: