Featured Video Play Icon


  • four ground sensors (infra-red), type Vishay TCRT1000 (OS1-4)
  • three short-distance sensors (infra-red), type Vishay TCRT5000 with a range of about 3 cm (OS5-7)
  • one long-distance sensor, type Sharp GP2Y0A21 with a range of 8 to 80 cm (OS8)
  • two strong white power leds as headlights of the robot (LD1-2)
  • two light sensors, type Vishay TEPT5600 (D1-2)
  • one infra-red sensor, type TSOP2136 (IR1)
  • a MAX7320 port expander (I2C)
  • a MAX11604 A/D-conversion chip (I2C)

Please note that the sensor panel uses the I2C bus on pins 14 and 15. Consequently, you should not connect anything else on these pins when using the sensor panel.

Sensor panel

Getting started

We start by loading the required libraries.

#include <Wire.h>
#include <LiquidCrystal.h>
#include <Dwenguino.h>
#include <DwenguinoSensorPanel.h>

After this, we can declare an SensorPanel object which determines the functionality of the Dwengo Sensor Panel.

SensorPanel sensorpanel;

In the setup function we need to initialise the Dwenguino by initDwenguino() after which we can call the SensorPanel constructor which initiates the SensorPanel object. This object needs to be initialised by calling the init() function.
Additionally, by setting the powerLongRange to true we can activate the long range distance sensor. If you not need this sensor, set it to false, your robot will save energy.

void setup() {
  // put your setup code here, to run once:
  sensorpanel = SensorPanel();
  sensorpanel.powerLongRange(true); // if you want to use the long range distance sensor, you need to activate it

We can now manipulate the Sensor Panel.

Lights ON/OFF

For example, by calling the setHeadlights function we can switch on (or off) the two headlights LD1 and LD2. The function setHeadlights takes two arguments of which the first defines the LED (LD1 or LD2) and the second defines the state (true or false).

void loop() {
  // put your main code here, to run repeatedly:
  unsigned char sensor;

Reading sensors

The sensors can be read by using the readSensor function. This function also takes two arguments. The first argument defines the sensor which can one of the ground sensors (OS1, OS2, OS3 or OS4) or one of the short range distance sensors (OS5, OS6 or OS7). The second argument determines the mode which is important only for the sensors ground and distance sensors. There are three possibilities: ACTIVE_MODE, AMBIENT_MODE and DIFF_MODE.

Sensors mode

The ground sensors and the proximity sensors have different modes because they consist of an IR-LED and a photo transistor.

ACTIVE_MODE. By using the ACTIVE_MODE both the IR-LED as well as the photo transistor are activated.

AMBIENT_MODE. In AMBIENT_MODE only the photo transistor is activated, in which case the sensor only receives ambient light.

DIFF_MODE. In DIFF_MODE two measurements are done: one in ACTIVE_MODE and one in AMBIENT_MODE, next both measurements are subtracted from each other. As a result, in DIFF_MODE will both proximity and ground sensors be less sensitive to ambient light.

  dwenguinoLCD.setCursor(0, 0);
  sensor = sensorpanel.readSensor(OS1,DIFF_MODE);
  dwenguinoLCD.print("Sensor OS1: ");

The long range distance sensor OS8 can also be read with the readSensor function. However, the second argument is neglected by the function and can be any value.

  dwenguinoLCD.setCursor(0, 1);
  sensor = sensorpanel.readSensor(OS8,ACTIVE_MODE);
  dwenguinoLCD.print("Sensor OS8: ");

Schematics and design files

Dwengo Sensor Panel by Dwengo vzw is licensed under a Creative Commons Attribution-ShareAlike 4.0 International License.
Please read the license before using this material

Click to download the schematics and design files

Related Post