Steun onze actie WeGoSTEM

Voor onze actie WeGoSTEM zoeken we nog vrijwilligers. Doe mee via WeGoSTEM.be/meedoen

Robot control with the sensor panel

The robot sensor panel contains all sensors you need to build a variety of robots. Due to the four ground sensors, you can easily build a fast line following robot. With two light sensors your robot will detect every light source. The distance sensors (for both short and longer distance) enable your robot to navigate even the most difficult parcours. Next to this the sensor panel also contains an infra-red receiver which you can use to steer the robot with the remote control of your tv. For navigating in the dark, the sensor panel also has two headlights.


Functionality

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

  1. #include <Wire.h>
  2. #include <LiquidCrystal.h>
  3. #include <Dwenguino.h>
  4. #include <DwenguinoSensorPanel.h>

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

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

  1. void setup() {
  2. // put your setup code here, to run once:
  3. initDwenguino();
  4. sensorpanel = SensorPanel();
  5. sensorpanel.init();
  6. sensorpanel.powerLongRange(true); // if you want to use the long range distance sensor, you need to activate it
  7. }

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

  1. void loop() {
  2. // put your main code here, to run repeatedly:
  3. unsigned char sensor;
  4. sensorpanel.setHeadlights(LD2,true);
  5. delay(200);
  6. sensorpanel.setHeadlights(LD2,false);
  7. delay(200);

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.

  1.  
  2. dwenguinoLCD.setCursor(0, 0);
  3. sensor = sensorpanel.readSensor(OS1,DIFF_MODE);
  4. dwenguinoLCD.print("Sensor OS1: ");
  5. dwenguinoLCD.print((int)sensor);

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.

  1. dwenguinoLCD.setCursor(0, 1);
  2. sensor = sensorpanel.readSensor(OS8,ACTIVE_MODE);
  3. dwenguinoLCD.print("Sensor OS8: ");
  4. dwenguinoLCD.print((int)sensor);
  5. }

Schematics and design files

CC-BY-SA 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

Additional Materials