Gesture & Touch Sensor for Arduino Wiki - DFRobot

SEN0285 Gravity: Gesture & Touch Sensor

Introduction

This sensor module integrates gesture recognition and touch detecting functions in one piece, and provides an adjustable detection range within 0~30cm. When connected to your microcontroller, it can detect 5-way touch signal and 7 kinds of gestures: move left, move right, move forward, move backward, pull up, pull down, pull and remove. Besides, the sensor is also equipped with the function of auto-sleep and wake up. The module comes with the gesture recognition algorithm and provides simple and reliable data output. Use the sensor to directly communicate with upper computer or micro-controllers like Arduino and Raspberry Pi via serial port.

The onboard 5-way touch pad on the sensor can be directly used to detect touch, or you can extend the touch pad with wires to make it perfectly fit in your application. The outer shield for the sensor retains the advantages of Gravity series as well as makes the sensor more durable. This sensor can be used to make smart lamp, DIY intelligent car, or used in interactive projects requiring gesture recognition.

warning_yellow.png NOTE

Specification

Pinout

SEN0285 Gravity: Gesture & Touch Sensor Pinout
Num Label Description Color
1 TXD Receive Data Greem
2 RXD Transmit Data Blue
3 GND Ground Black
4 VCC Power Supply Red
5 Touch Port 5-way Touch signal

Function Description

Example: DFGT.setGestureDistance(20)---Unit(cm); Max height: 30cm

Example: DFGT.setSleep(4);---unit(s)

Example(1) DFGT.enableFunction(DFGT_FUN_ALL);---enable all gestures sensing fuction

Example(2) DFGT.disableFunction(DFGT_FUN_RIGHT | DFGT_FUN_LEFT);---disable sensing function of part gestures

Example(3) DFGT.enableFunction(DFGT_FUN_RIGHT | DFGT_FUN_LEFT);---enable sensing function of part gestures

Tutorial

In this tutorial, we will show you the basic usages of the sensor. First of all, connect all parts together and download the codes to Arduino UNO. Open the serial monitor, when we do any one of the seven gestures or touch any touch pad on the sensor, there should be a corresponding reaction appearing on the serial monitor.

Note:

Requirements

Arduino Debug

Since the gesture & touch sensor is a serial device and there is only 1 hardware serial port on Arduino, we recommend using the sensor with software serial or you can use device with multiple serial ports such as Arduino Leonardo, Arduino Mega2560 and so on. Here we choose Arduino UNO as the controller and define D10 and D11 as software serial port.

Connection Diagram

SEN0285 Gravity: Gesture & Touch Sensor Connection Diagram

How to use gestures recognization (The maxmium height the sensor can detect is 30cm)

SEN0285 Gravity: Gesture & Touch Sensor How to use gestures recognization SEN0285 Gravity: Gesture & Touch Sensor How to use gestures recognization

Arduino Debugging Codes

PC serial tool will be needed here, and the read data will be displayed on the Arduino serial interface.

/*!
 * @file simpleGesture.ino
 * @brief Sensor event will print on your serial monitor
 * @n     for esp32, rx_pin = D5, tx_pin = D6
 * @copyright   Copyright (c) 2010 DFRobot Co.Ltd (http://www.dfrobot.com)
 * @license     The MIT License (MIT)
 * @author      PengKaixing(kaixing.peng@dfrobot.com)
 * @version  V1.0.0
 * @date  2022-03-25
 * @url https://github.com/DFRobot/DFRobot_Gesture_Touch
 */

#include "DFRobot_Gesture_Touch.h"

#ifdef __AVR__
  SoftwareSerial    mySerial(/*RX*/10, /*TX*/11); 
#elif defined ESP_PLATFORM
// ESP32:IO16 <--> TX:sensor
// ESP32:IO17 <--> RX:sensor
HardwareSerial mySerial(1);
#endif

// init sensor object, request write and read function
DFRobot_Gesture_Touch   DFGT(&mySerial);    

void setup()
{
  Serial.begin(115200);

  // suggest default value
  DFGT.setGestureDistance(20);

  // enable all functions
  DFGT.enableFunction(DFGT_FUN_ALL);

  // disable function test
  DFGT.disableFunction(DFGT_FUN_RIGHT | DFGT_FUN_LEFT);

  // enable function test
  // DFGT.enableFunction(DFGT_FUN_RIGHT | DFGT_FUN_LEFT);

  // set auto sleep time out, in sleep mode, something approach will wake it up
  // DFGT.setSleep(4);

  Serial.println("simple Gesture!");
}

void loop()
{
  // get an event that data saved in serial buffer
  int8_t rslt = DFGT.getAnEvent();  

  if(rslt != DF_ERR) 
  {
    // disable auto sleep
    // DFGT.setSleep(DFGT_SLEEP_DISABLE);
    switch(rslt) 
    {
      case DFGT_EVT_BACK: 
        Serial.println("get event back");
        break;
      case DFGT_EVT_FORWARD: 
        Serial.println("get event forward");
        break;
      case DFGT_EVT_RIGHT: 
        Serial.println("get event right");
        break;
      case DFGT_EVT_LEFT: 
        Serial.println("get event left");
        break;
      case DFGT_EVT_PULLUP: 
        Serial.println("get event pull up");
        break;
      case DFGT_EVT_PULLDOWN: 
        Serial.println("get event pull down");
        break;
      case DFGT_EVT_PULLREMOVE: 
        Serial.println("get event pull and remove");
        break;
      case DFGT_EVT_TOUCH1: 
        Serial.println("get event touch1");
        break;
      case DFGT_EVT_TOUCH2: 
        Serial.println("get event touch2");
        break;
      case DFGT_EVT_TOUCH3:  
        Serial.println("get event touch3");
        break;
      case DFGT_EVT_TOUCH4: 
        Serial.println("get event touch4");
        break;
      case DFGT_EVT_TOUCH5: 
        Serial.println("get event touch5");
        break;
    }
  }
}

Functions: recognize the 5-way touch signal and the seven gestures including move right, move left, forward, backward, pull up, pull down, and pull and leave.

Dispaly the results on LCD

In actual application, we may use the sensor outdoor, so here we specially provide an case for you. Li-ion batteries will be the power supply and an LCD will be used to display the measured distance information.

Arduino LCD Connection

SEN0285 Gravity: Gesture & Touch Sensor Arduino LCD Connection

Arduino LCD Debugging Code

/*!
 * @file simpleGesture.ino
 * @brief Sensor event will print on your serial monitor
 * @n     for esp32, rx_pin = D5, tx_pin = D6
 * @copyright   Copyright (c) 2010 DFRobot Co.Ltd (http://www.dfrobot.com)
 * @license     The MIT License (MIT)
 * @author      PengKaixing(kaixing.peng@dfrobot.com)
 * @version  V1.0.0
 * @date  2022-03-25
 * @url https://github.com/DFRobot/DFRobot_Gesture_Touch
 */

#include "DFRobot_Gesture_Touch.h"
#include <Wire.h>
#include "DFRobot_RGBLCD1602.h"

/*
Change the RGBaddr value based on the hardware version
-----------------------------------------
       Moudule        | Version| RGBAddr|
-----------------------------------------
  LCD1602 Module      |  V1.0  | 0x60   |
-----------------------------------------
  LCD1602 Module      |  V1.1  | 0x6B   |
-----------------------------------------
  LCD1602 RGB Module  |  V1.0  | 0x60   |
-----------------------------------------
  LCD1602 RGB Module  |  V1.1  | 0x2D   |
-----------------------------------------
*/
DFRobot_RGBLCD1602 lcd(/*RGBAddr*/0x60 ,/*lcdCols*/16,/*lcdRows*/2);  //16 characters and 2 lines of show

#ifdef __AVR__
  SoftwareSerial    mySerial(/*RX*/10, /*TX*/11); 
#elif defined ESP_PLATFORM
// ESP32:IO16 <--> TX:sensor
// ESP32:IO17 <--> RX:sensor
HardwareSerial mySerial(1);
#endif

// init sensor object, request write and read function
DFRobot_Gesture_Touch   DFGT(&mySerial);

void setup()
{
  Serial.begin(115200);

  // initialize the LCD and master IIC
  lcd.init();
  delay(20);

  // suggest default value
  DFGT.setGestureDistance(20);

  // enable all functions
  DFGT.enableFunction(DFGT_FUN_ALL);

  // disable function test
  DFGT.disableFunction(DFGT_FUN_RIGHT | DFGT_FUN_LEFT);

  // enable function test
  // DFGT.enableFunction(DFGT_FUN_RIGHT | DFGT_FUN_LEFT);

  // set auto sleep time out, in sleep mode, something approach will wake it up
  // DFGT.setSleep(4);

  Serial.println("simple Gesture!");

  /**
   *  @brief set cursor position
   *  @param col columns optional range 0-15
   *  @param row rows optional range 0-1,0 is the first row, 1 is the second row
   */
  lcd.setCursor(0, 0);
  lcd.print("State:");
}

void loop()
{
  lcd.setCursor(0, 1);
  int8_t rslt = DFGT.getAnEvent();  // get an event that data saved in serial buffer
  if(rslt != DF_ERR) {
    switch(rslt) {
      case DFGT_EVT_BACK: {
        lcd.print("Back            ");
      } break;
      case DFGT_EVT_FORWARD: {
        lcd.print("Forward            ");
      } break;
      case DFGT_EVT_RIGHT: {
        lcd.print("Right            ");
      } break;
      case DFGT_EVT_LEFT: {
        lcd.print("Left            ");
      } break;
      case DFGT_EVT_PULLUP: {
        lcd.print("Pull up          ");
      } break;
      case DFGT_EVT_PULLDOWN: {
        lcd.print("Pull Down          ");
      } break;
      case DFGT_EVT_PULLREMOVE: {
        lcd.print("Pull and Remove          ");
      } break;
      case DFGT_EVT_TOUCH1: {
        lcd.print("Touch1          ");
      } break;
      case DFGT_EVT_TOUCH2: {
        lcd.print("Touch2          ");
      } break;
      case DFGT_EVT_TOUCH3: {
        lcd.print("Touch3          ");
      } break;
      case DFGT_EVT_TOUCH4: {
        lcd.print("Touch4          ");
      } break;
      case DFGT_EVT_TOUCH5: {
        lcd.print("Touch5          ");
      } break;
      default: break;
    }
  }
}

Result displayed on LCD:

State: 

Pull Down

FAQ

For any questions, advice or cool ideas to share, please visit the DFRobot Forum

More Documents