Petoi Doc Center
Ask or search…

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

Hardware setup

  • NyBoard
Connecting to the NyBoard with wire as shown in the following picture:
  • BiBoard
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

The code using this sensor has been integrated into the OpenCat (NyBoard)/ OpenCatEsp32 (BiBoard) project. Uncomment the line #define DOUBLE_LIGHT in the OpenCat.ino / OpenCatEsp32.ino, as shown in the figure below, and then 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 simply choose Arduino Uno.


If 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 demo sketch(doubleLight.ino), as shown below:
This demo sketch 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.

The demo code