IR Distance Sensor
Last updated
Last updated
This module integrates two IR distance sensors; it measures distance through reflected light waves and is used to detect the presence of an object within a specific range. The sensor comprises an IR LED and a photosensor (phototransistor) pair. The light emitted by the IR LED is 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 for measuring complex objects, such as tracing an object.
You can use the Firmware Uploader within the Petoi Desktop App.
You can use Arduino IDE to upload and modify the source code.
Install the latest version of the Adafruit NeoPixel library using the Arduino IDE.
The code using this sensor has been integrated into the OpenCat project. Uncomment the line #define DOUBLE_INFRARED_DISTANCE
in the OpenCat.ino, as shown in the figure below, and 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.
With NyBoard V1_*, you can choose Arduino Uno.
Connecting to the NyBoard with wire as shown in the following picture:
You can use the Firmware Uploader within the Petoi Desktop App. Please select the correct Product type, Borard version, and Serial port. The mode should be Standard, so press the Upgrade the Firmware button. for example, Bittle, BiBoard_V0_2, COM5 as follows:
After uploading, open the serial monitor and use the serial command "XD" to switch to using the IR distance sensor mode.
You can use Arduino IDE to upload the sketch(OpenCatEsp32.ino). Use the latest OpenCatESP32 code to finish the setup. For example, to modify the code for Bittle as shown below:
After uploading, open the serial monitor and use the serial command "XD" to switch to using the IR distance sensor mode.
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.
If you want to test this sensor's function alone or learn more about its principles. You can use the Arduino IDE to upload the demo sketch(testDoubleInfraredDistance.ino) :
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 for NyBoard / 34 and 35 for BiBoard) in the serial monitor. You can also use the serial plotter to view the two analog pins (A2 and A3 for NyBoard / 34 and 35 for BiBoard) more intuitively. The waveform graph is generated by the analog value of the pin output along the time axis.