Phone Sensors Module

Phone Sensor Accelerometer&Gyroscope
Description
Access sensors of smartphones like accelerometer, gyroscope, sound, and others.

Introduction

This phone sensor module allows you to access the following inbuilt sensors of your smartphone: Accelerometer, Gyroscope, Proximity sensor, Magnetometer, Light meter, Sound meter, GPS, Temperature sensor and Barometer.

Accelerometer

Senses the acceleration acting on your Smartphone in all three directions (X-axis, Y-axis, and Z-axis) in m/s2.

Dabble Phone Sensor Accelerometer & Gyroscope

Gyroscope

Senses the angular velocity in all three directions (X-axis, Y-axis, and Z-axis) in rad/s.

Magnetometer

Senses the magnetic field acting in all three directions (X-axis, Y-axis, and Z-axis) in µT. It can be used to move robots in a specific direction.

Dabble Phone Sensor Magnetometer Proximity Meter

Proximity sensor

Senses if there is an object near your Smartphone. If the object is nearby, 0.0000CM is displayed. Otherwise, a different number depending on the default setting of your phone is displayed.

Light meter

Senses the light falling on your Smartphone in Lux.

Dabble Phone Sensor Light Meter Sound Meter

Sound meter

Senses the intensity of nearby sound in dB. The module will ask you to provide audio record permission.

Dabble Phone Sensor Record Audio Permission

GPS

Shows the Longitude and Latitude of your current location. The module will ask you to provide location access permission.

Dabble Phone Sensor Sound Meter Location

Temperature sensor

Senses the temperature.

Phone Sensor Temperature Barometer

Barometer

Senses the pressure.

Arduino IDE Functions

Header

To include the GamePad module in the Arduino program, you have to include the following header:

#define CUSTOM_SETTINGS
#define INCLUDE_DATALOGGER_MODULE

After defining the above mention headers, you have to include the dabble library:

#include <Dabble.h>

You can download the zip of Arduino Library for

  1. evive, Uno, Mega, and Nano – Dabble-Arduino 
  2. ESP32 – Dabble-ESP32

depending on the board you are using.

Enabling Bluetooth Communication

To enable Bluetooth communication, you have to initialize serial communication using the following code:

  1. For evive and Arduino Mega, Uno, and Nano
    Dabble.begin(Baud_Rate);Here Baud_Rate is the baud rate set for the Bluetooth module. With evive, you normally get 115200 baud rate modules.
  2. For ESP32
    Dabble.begin("Bluetooth_Name");In place of Bluetooth_Name  enter the name that you want to keep for Bluetooth of ESP32. The default name given in the library is “MyEsp32”.

Refreshing the data

To refresh the data that the device has got from the mobile app, you have to use the following line of code:

Dabble.processInput();

Functions

FunctionReturn TypeBrief Description
Sensor.getAccelerometerXaxis()FloatReturns Accelerometer X value in m/s^2
Sensor.getAccelerometerYaxis()FloatReturns Accelerometer Y value in m/s^2
Sensor.getAccelerometerZaxis()FloatReturns Accelerometer Z value in m/s^2
Sensor.getGyroscopeXaxis()FloatReturns Gyroscope X value in rad/s
Sensor.getGyroscopeYaxis()FloatReturns Gyroscope Y value in rad/s
Sensor.getGyroscopeZaxis()FloatReturns Gyroscope Z value in rad/s
Sensor.getMagnetometerXaxis()FloatReturns Magnetometer X value in uT
Sensor.getMagnetometerYaxis()FloatReturns Magnetometer Y value in uT
Sensor.getMagnetometerZaxis()FloatReturns Magnetometer Z value in uT
Sensor.getProximityDistance()FloatReturns proximity sensor data. Returns 0 if the obstacle is ahead.
Sensor.getLightIntensity()FloatReturns the light sensor data in Lux
Sensor.getSoundDecibels()FloatReturns the sound sensor data in dB.
Sensor.getTemperature()FloatReturns the temperature in degree celcius
Sensor.getBarometerPressure()FloatReturns the barometer data in Pascals.
Sensor.getGPSlongitude()FloatReturns the Longitude data.
Sensor.getGPSlatitude()FloatReturns the Latitude data.

PictoBlox Blocks

You can get the phone sensors using a reporter block “get () reading”.

get sensor reading 2

In its drop-down, you will find various parameters related to phone sensors.

get sensor reading

evive Notes Icon
Note: When you are using this module with Arduino Uno, Mega, and Nano,  you have to set the Bluetooth baud rate to the baud rate of the Bluetooth module to have proper communication between the board and the module. To set the baud rate you have to use set bluetooth baud rate to () block.

set bluetooth baud rate to

Examples

Arduino IDE

Accelerometer

This program displays the accelerometer reading on the TFT display:

/* Accelerometer block of Phone sensor module allows you to access your smartphone's accelerometer values.
   NOTE:
   1)For Arduino Mega Connect Bluetooth on Serial3 pins.
   2)For Arduino Uno/Nano library uses SoftwareSerial,hence pin 2 and pin 3 are used
   as RX and TX pins respectively on SoftwareSerial.Hence with arduino Uno
   follow below connections for bluetooth.
   UNO  - BLUETOOTH
   2    - TX
   3    - RX

   3)For Uno/Nano keep bluetooth Baudrate below 38400.
  
   You can reduce the size of library compiled by enabling only those modules that you want
   to use. For this first define CUSTOM_SETTINGS followed by defining INCLUDE_modulename.

   Explore more on: https://thestempedia.com/docs/dabble/phone-sensors-module/
*/

#define CUSTOM_SETTINGS
#define INCLUDE_SENSOR_MODULE
#include <Dabble.h>

void setup() {
  Serial.begin(9600);     // make sure your Serial Monitor is also set at this baud rate.
  Dabble.begin(9600);    //Change this baudrate as per your bluetooth baudrate. Connect bluetooth on digital pin 2(RX) and 3(TX) for Uno/Nano and on Serial3 pins for Mega.
}

void loop() {
  Dabble.processInput();             //this function is used to refresh data obtained from smartphone.Hence calling this function is mandatory in order to get data properly from your mobile.
  print_Accelerometer_data();
}

void print_Accelerometer_data()
{
  Serial.print("X_axis: ");
  Serial.print(Sensor.getAccelerometerXaxis(), 4);
  Serial.print('\t');
  Serial.print("Y_axis: ");
  Serial.print(Sensor.getAccelerometerYaxis(), 4);
  Serial.print('\t');
  Serial.print("Z_axis: ");
  Serial.println(Sensor.getAccelerometerZaxis(), 4);
  Serial.println();
}

PictoBlox

Accelerometer

Displaying the values of Accelerometer parameters on the TFT display.

accelerometer data display on screen

Gyroscope

Displaying the values of Gyroscope parameters on TFT display.

gyroscope data display on screen

Magnetometer

Displaying the values of Magnetometer parameters on TFT display.

magnetometer data display on screen

Light Meter

Displaying the Light parameter on TFT display.

light data display on screen

Proximity Meter

Sensing proximity and playing a tone on Buzzer accordingly.

proximity data display on screen

GPS Location

Displaying the values of GPS parameters on TFT display.

GPS location data display on screen

Sound Meter

Displaying the value of the sound parameter on the TFT display.

sound data display on screen

Temperature

Displaying the value of the Temperature parameter on the TFT display.

temperature data display on screen

Barometer

Displaying the value of the Barometer parameter on the TFT display.

Pressure data display on screen

Table of Contents