Light Sensor

Function introduction

The sensor integrates two photoresistors (depending on the light intensity adjustment resistance) to detect the light intensity. The photoresistor is a particular resistance that uses the photoconductive effect, and its resistance is directly related to the intensity of the incident light. When the light intensity increases, the resistance decreases; when the light intensity decreases, the resistance increases. The output signal is an analog value. The brighter the brightness, the larger the value. You can realize the function you want by judging the value of the detected light intensity, such as the function of a robot tracing light.

NyBoard

Hardware setup

Connecting to the NyBoard with a wire as shown in the following picture:

Software setup

There are two methods to upload the light mode firmware :

  • Using the Petoi Desktop App

  • Using the Arduino IDE

Petoi Desktop App

  • You can use the Firmware Uploader within the Petoi Desktop App. Please select the correct Product type, Board version, and Serial port according to your actual use. The mode should be Light, so press the Upgrade the Firmware button. For example, Nybble, NyBoard_V1_2, COM5 as follows:

Arduino IDE

  • You can use Arduino IDE to upload and modify the source code.

The code using this sensor has been integrated into the OpenCat project. Uncomment the line #define DOUBLE_LIGHT In the OpenCat.ino, as shown in the figure below, use the Arduino IDE to upload the sketch to the robot main board, which can reproduce the example function of integrating the robot action.

Prepare the Arduino UNO development environment.

With NyBoard V1_*, you can choose Arduino Uno.

For example, to modify the code for Bittle as shown below:

Arduino module test code

Suppose you want to test a light sensor's function alone or learn more about its principles. You can use the Arduino IDE to upload the test code(testDoubleLight.ino):

The test code is in the OpenCat project source code (ModuleTests/testDoubleLight)

This test code implements real-time printing of the analog values 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.

BiBoard

Hardware setup

BiBoard V0

BiBoard V1

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.

Software setup

There are two methods to upload the firmware :

  • Using the Petoi Desktop App

  • Using the Arduino IDE

Petoi Desktop App

  • You can use the Firmware Uploader within the Petoi Desktop App. Please select the correct Product type, Board version, and Serial port according to your actual use. The mode should be Standard, so press the Upgrade the Firmware button. For example, Bittle, BiBoard_V0_2, COM5 as follows:

Arduino IDE

  • You can use Arduino IDE to upload the sketch(OpenCatEsp32.ino). Use the latest OpenCatESP32 source code to finish the setup. For example, to modify the code for Bittle as shown below:

After uploading, there are two methods to activate/deactivate the light mode:

  • Serial Monitor

    • Open the serial monitor and use the serial command "XL" to activate the light mode.

    • Open the serial monitor and use the serial command "Xl" to deactivate the light mode.

  • Mobile App

    • Create a mobile app command called "Activate light" and use the code: X76

    • Create a mobile app command called "Deactivate light" and use the code: X108

Last updated

Was this helpful?