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.
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.
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.
Sound meter
Senses the intensity of nearby sound in dB. The module will ask you to provide audio record permission.
GPS
Shows the Longitude and Latitude of your current location. The module will ask you to provide location access permission.
Temperature sensor
Senses the temperature.
Barometer
Senses the pressure.
Arduino IDE Functions
Header
To include the Sensor module in the Arduino program, you have to include the following header:
#define CUSTOM_SETTINGS
#define INCLUDE_SENSOR_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
- evive, Uno, Mega, and Nano – Dabble-Arduino
- ESP32 – Dabble-ESP32
Enabling Bluetooth Communication
To enable Bluetooth communication, you have to initialize serial communication using the following code:
- 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.
- For ESP32
Dabble.begin("Bluetooth_Name");
In place of Bluetooth_Name enter name that you want to keep for Bluetooth of ESP32. 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
Function | Return Type | Brief Description |
---|---|---|
Sensor.getAccelerometerXaxis() | Float | Returns Accelerometer X value in m/s^2 |
Sensor.getAccelerometerYaxis() | Float | Returns Accelerometer Y value in m/s^2 |
Sensor.getAccelerometerZaxis() | Float | Returns Accelerometer Z value in m/s^2 |
Sensor.getGyroscopeXaxis() | Float | Returns Gyroscope X value in rad/s |
Sensor.getGyroscopeYaxis() | Float | Returns Gyroscope Y value in rad/s |
Sensor.getGyroscopeZaxis() | Float | Returns Gyroscope Z value in rad/s |
Sensor.getMagnetometerXaxis() | Float | Returns Magnetometer X value in uT |
Sensor.getMagnetometerYaxis() | Float | Returns Magnetometer Y value in uT |
Sensor.getMagnetometerZaxis() | Float | Returns Magnetometer Z value in uT |
Sensor.getProximityDistance() | Float | Returns proximity sensor data. Returns 0 if the obstacle is ahead. |
Sensor.getLightIntensity() | Float | Returns the light sensor data in Lux |
Sensor.getSoundDecibels() | Float | Returns the sound sensor data in dB. |
Sensor.getTemperature() | Float | Returns the temperature in degree celcius |
Sensor.getBarometerPressure() | Float | Returns the barometer data in Pascals. |
Sensor.getGPSlongitude() | Float | Returns the Longitude data. |
Sensor.getGPSlatitude() | Float | Returns the Latitude data. |
PictoBlox (Scratch) Blocks
You can get the phone sensors using a reporter block “get () reading”.
In its drop-down, you will find various parameter related to phone sensors.
Examples
Example – Accelerometer
This program displays the accelerometer reading on the TFT display:
Example – Gyroscope
This program displays the gyroscope data on the TFT display of evive.
Example – Magnetometer
This program displays the magnetometer value on the TFT display.
Example – Proximity Sensor
The program turns ON the buzzer when there is an obstacle in front of the mobile.
Example – Sound Meter
This program displays the sound sensor reading on TFT display.
Example – Light Sensor
This example displays light sensor data on the TFT display of evive.
Example – GPS Location
This program displays the Latitude and Longitude of the GPS reading on the TFT display of evive.
Example – Temperature
This program displays the temperature sensor data on the TFT display.
Example – Barometer
This program displays the barometer reading (pressure) on the TFT display.
Example – Accelerometer
Displaying the values of Accelerometer parameters on TFT display.
Example – Gyroscope
Displaying the values of Gyroscope parameters on TFT display.
Example – Magnetometer
Displaying the values of Magnetometer parameters on TFT display.
Example – Light Meter
Displaying the Light parameter on TFT display.
Example – Proximity Meter
Sensing proximity and playing a tone on Buzzer accordingly.
Example – GPS Location
Displaying the values of GPS parameters on TFT display.
Example – Sound Meter
Displaying the value of the sound parameter on the TFT display.
Example – Temperature
Displaying the value of the Temperature parameter on the TFT display.
Example – Barometer
Displaying the value of the Barometer parameter on the TFT display.
Projects
This project will show you how to make an interactive humanoid robot.
- May 10, 2019 7:13 PM·
This project will show you how to control a robot using a Smartphone with the help of hand gestures.
- March 22, 2019 6:53 PM·
This project will show you how to make a DIY Dabble controlled baby mobile that will put a smile on any baby’s face!
- January 4, 2019 5:07 PM·
This Post Has 3 Comments
I tried to upload the code given to my Arduino Uno with all the necessary libraries included. However, an error message pops up, stating that an error occurred while compiling for the Uno board. It also states that it needs the 9th Analog pin (A9), which is not on the Uno. It also uses all 3 serial monitor available on a Mega, while the Uno only has one serial monitor. So I would like to ask, is this app is REALLY compatible with the Uno?
It seems that the code you are trying to run is made for evive , hence you are getting this error with UNO. You can navigate to “Files>>Examples>>Dabble>>02.Uno Nano Mega>>08.Phone Sensor” in Arduino IDE to find examples appropriate for your UNO board.
Pingback: DIY Robot điều khiển hình người – ISTEM