You are on page 1of 12

Food Living Outside Play Technology Workshop

SensoDuino: Turn Your Android Phone into a Wireless Sensors Hub for
Arduino
by techbitar on October 14, 2013

Table of Contents

SensoDuino: Turn Your Android Phone into a Wireless Sensors Hub for Arduino . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 1

Intro: SensoDuino: Turn Your Android Phone into a Wireless Sensors Hub for Arduino . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 2

Step 1: .................................................................................................................. 3

Step 2: How to Use SensoDuino . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 4

Step 3: Wiring the Arduino to the HC-05 Bluetooth . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 5

Step 4: Transmitting from SensoDuino to Arduino . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 6

Step 5: Pairing and Establishing a Serial Connection between Windows 7 and SensoDuino . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 6

Step 6: Capturing SensoDuino Data on Windows PC using C++ and C# over Bluetooth . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 7

Step 7: Log SensoDuino Data to File Then Import into Excel . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 8

Step 8: .................................................................................................................. 8

Step 9: Boost Your HC-05 Bluetooth Transmission Speed . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 9

Step 10: Feedback & Bug Reorts . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 10

Step 11: Android: A Capable Electronics DIY Platform . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 10

Step 12: Resources . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 11

Related Instructables . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 12

Advertisements . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 12

http://www.instructables.com/id/SensoDuino-Turn-Your-Android-Phone-into-a-Wireless/
Author:techbitar
Did I unplug the solder iron?

Intro: SensoDuino: Turn Your Android Phone into a Wireless Sensors Hub for Arduino
SensoDuino is a free Android application that captures data from sensors built into your Android mobile device then saves the captured data to a text file and/or transmits
the data as human readable ASCII via HC-05 Bluetooth module (or comparable) to Arduino, Windows PC or any device with serial Bluetooth capabilities. You can control
the frequency of sensor data reading, transmitting, and logging (subject to the specifications of the sensor vendor.)

SensoDuino eliminates the need for USB Host hardware for your phone or Arduino. For Arduino or microcontroller, you only need a $10 HC-05 Bluetooth module (or
equivalent).

You can save over $200 in sensors and parts for your Arduino or microcontroller project if you already have a mid-range Android device such as my Samsung Galaxy II
Plus. See section titled: Android: A Capable Electronics DIY Platform.

SUPPORTED SENSORS

SensoDuino recognizes the following Android sensors: GPS, Orientation, Gravity, Rotation vector, Gyroscope, Linear Acceleration, Magnetometer, Light Level, Audio
Level, Proximity, Pressure and Temperature. More sensors to be supported in later releases of SensoDuino.

SensoDuino also features an Android sensor scanner that will list hardware and software sensors supported by your Android device as well as key sensor specifications
such as max power consumption, resolution, vendor, etc. Some Android devices have duplicate sensors from different vendors. The Android SDK will return the default
sensor.

FEATURES OVERVIEW

Read Android sensors. Save sensor readings to comma-delimited text file. Transmit readings in ASCII comma-delimited format via Bluetooth. List available Android
device sensors both hardware and software (virtual sensors). Configure speed of sensor data capturing, logging, and transmission from 100 milliseconds to 10 minutes
(subject to sensor limits). Keeps track of accuracy for logged sensor readings and provide visual clues for inaccurate sensor data. Geo-tag sensor readings using your
Android device GPS.
Optimized for speed of operation and transmission. Keep device awake to prevent loss of sensor data logging. - Supports Android devices from version 2.33 onward.
Scan and list available sensors and their specifications.

WHAT CAN YOU DO WITH SENSODUINO

With the help of Arduino or other microcontrollers, SensoDuino can be used in robotics projects, UAVs, etc. It's support for 12 motion and environmental sensors covers
a wide range of sensory feedback. Also, SensoDuino can be used for logging. The ability to determine the speed of logging from 10Hz to once every 10 minute allows for
high-speed as well as time-lapse logging of sensor readings.

THANKS

Special thanks to colleagues from PIN13 Protospace who helped with testing, usability, guide review and proofreading. Mainly, I wish to thank Jafar Quttaineh for his
detailed product testing and for his invaluable insights and feature suggestions. Also thanks to Mujahed Al-Tahle for his detailed analysis and testing of the product and
guide.

http://www.instructables.com/id/SensoDuino-Turn-Your-Android-Phone-into-a-Wireless/
Step 1:
UPDATE: AS OF OCT-14- 13 | 12:30PM (UTC+02:00) SENSODUINO IS IN PRODUCTION. IT WILL SHOW UP IN GOOGLE PLAY SEARCH ENGINE IN A WHILE.

SensoDuino is very stable but I prefer to do more testing using different Android devices before I move it from Beta to production which may take a few more days. So
even though SensoDuino is on Google Play, it's not visible to searches until it goes into production.

During the testing period you can still install SensoDuino from Google Play Testing Service. To install it, you need to join the SensoDuino Google Group:
https://groups.google.com/d/forum/sensoduino

Once you receive confirmation of SensoDuino group membership, you can install SensoDuino from Google Play via this link:
https://play.google.com/apps/testing/com.techbitar.android.sensoduino

I will okay SensoDuino group membership requests within minutes of receiving them, during work hours. On weekends and after work hours, I will do my best to okay
membership requests as quickly as possible. My time zone is UTC+02:00

http://www.instructables.com/id/SensoDuino-Turn-Your-Android-Phone-into-a-Wireless/
Step 2: How to Use SensoDuino
SensoDuino is very simple to use. Basically you have rows of sensor names (number of sensors may change in the future). Each sensor has three checkboxes next to it
labeled On, Tx, and Log.

ON: The first checkbox turns the sensor On or Off which means SensoDuino is either reading this sensor or not.
TX: The second checkbox when enabled, SensoDuino will transmit the associated sensor readings via Bluetooth to any paired and connected Bluetooth serial
device.
LOG: When the third checkbox is checked, the associated sensor readings are logged to a comma-delimited text file named "sensoduino.txt" in the root of your
Android's SD card.

You can control the speed of sensor reading from the Preferences menu. You have a choice between 100 millisecond (10 Hz) to 10 minutes. The speed of the sensor is
subject to the limits of the vendor specifications. Most GPS sensors today generate location data once per second (1 Hz). Some GPS modules generate location data 10
times per second (10 Hz). On the other side of the speed spectrum, some sensors generate readings over microseconds.

SENSOR SENSITIVITY

Motion sensors (gyro, accelerometer, magnetometer) are sensitive to environmental conditions such as presence of magnetic field or slight physical vibrations. So even
when your phone is placed on a flat stationary surface, you will still see changes in sensor reading affecting mostly the least significant digits. The least significant digits
of motion sensor readings may produce more data than you need for your application. Your application requirements should determine how many digits will be truncated
or kept.

POWER DRAIN

SensoDuino is a power-hungry app. Between active sensors, Bluetooth transmission, logging to device storage, and keeping your device awake so as not to interrupt
sensor readings, you are bound to drain your battery. For prolonged use of SensoDuino, an additional power source should be considered either in the form of power
brick, solar/wind energy, or power outlet if one is available.

http://www.instructables.com/id/SensoDuino-Turn-Your-Android-Phone-into-a-Wireless/
Step 3: Wiring the Arduino to the HC-05 Bluetooth
To take advantage of SensoDuino out of the box, you don't need anything. You can start logging sensor readings to a text file then process the logged data with myriad
graphing and data analysis tools. But if you see the added value in wirelessly transmitting sensor readings over Bluetooth to a microcontroller or PC, you should get the
HC-05 Bluetooth serial module.

The HC-05 package comes in two flavors, SMD and breakout board versions. Both can be purchased for less than $10 from ebay. I strongly recommend buying the HC-
05 with the breakout board to avoid unnecessary soldering and debugging headaches and to take advantage of useful features included with the breakout board such a
status LED that blinks in patterns to show if the HC-05 is paired, connected, in command mode, or not even powered.

The breakout board has a 3.3V regulator which can convert Arduino's incoming 5V power but you still have to drop the Arduino's 5V pins down to 3.3V. The simplest way
is a voltage divider from two resistors but you can use a level shifter such as the CD4050 level shifter IC.

I use 2K & 1K resistors as voltage divider to drop the Arduino's 5V TX pin to 3.3V, which is the operating voltage of the HC-05 pins. You have to do this to protect the HC-
05 3.3V RX pin. On the other hand, the Arduino 5V RX pin can handle the 3.3V sent from the HC-05 TX pin. Even if the HC-05 worked without the voltage divider, there's
no telling for how long.

TO UPLOAD A SKETCH TO ARDUINO YOU MAY HAVE TO REMOVE THE POWER FROM THE HC-05 MODULE TO AVOID ANY CONFLICT OVER SERIAL.
Alternatively, you can wire the HC-05's TX/RX to different Arduino pins supported by Arduino's SoftwareSerial library.

http://www.instructables.com/id/SensoDuino-Turn-Your-Android-Phone-into-a-Wireless/
Step 4: Transmitting from SensoDuino to Arduino
SensoDuino can transmit sensor readings to an Arduino via the HC-05 Bluetooth module. Other comparable Bluetooth modules may work as-is or require changes to
their default settings.

The attached Arduino sketch "sensoduino.ino " reads data transmitted by SensoDuino over Bluetooth then parses and converts this data from strings to numeric values
ready for utilization in your Arduino application be it robotics control or UAV navigation or sensor logging.

The process of connecting SensoDuino to Arduino is simple.As with all Bluetooth communication you must pair your Android device with the HC-05 Bluetooth module
attached to your Arduino. You only need to do the pairing once.

Step 5: Pairing and Establishing a Serial Connection between Windows 7 and SensoDuino
Pairing Bluetooth devices is a very basic task. On Windows 7 (or similar OS) opening serial over Bluetooth involves one additional step and that is assigning a virtual
COM port to the Bluetooth connection between Windows and SensoDuino. More often than not, this is done behind the scenes and the user does not have to worry about
it. But if you like to debug your Bluetooth connection to SensoDuino, you may need some basic details of what takes place when connecting serial over Bluetooth.

NOTE: To debug the Bluetooth connection, make sure SensoDuino is running with one sensor enabled and transmitting (check Tx checkbox for that sensor) at slow
speed.

For testing the Bluetooth connection between SensoDuino and Windows PC, I use Tera Term. You don't have to but it's a robust terminal emulation software that helps
me test serial connections either Bluetooth or wired. You can download the latest Tera Term from here: http://ttssh2.sourceforge.jp/index.html.en If you see garbage on
the screen after you established a connection, match the baud rate for both Bluetooth devices.

The data you will see on the terminal emulator console may not be neat looking but it's properly formatted for the C++ and C# utilities as well as for the Arduino sketch to
consume.

Let's start by establish a pairing between the Bluetooth on your Android device and your computer's Bluetooth. Once you do this step successfully, we can move
to the next stage.
Check to make sure Bluetooth is set to Discoverable on your Android device.
Check to make sure Bluetooth is enabled on your Android device.
Run SensoDuino.
To test the setup, enable the Orientation sensor and enable its Tx (transmit) checkbox and bring down the transmission rate to 1 per second, from the preferences
menu.

http://www.instructables.com/id/SensoDuino-Turn-Your-Android-Phone-into-a-Wireless/
Step 6: Capturing SensoDuino Data on Windows PC using C++ and C# over Bluetooth
I am attaching two skeletal programs in C++ "main.cpp " and C# "Program.cs " that will serially send and receive data to and from Arduino and SensoDuino either over
wired serial or Bluetooth serial.

These two programs were extracted and modified from sample code published by the Microsoft Developer Network. The programs are simple, robust, and can handle
reasonably high data transmission speeds.

For one test, I enabled all SensoDuino sensors at the highest speed and could not detect significant loss in data transmission. I used a Samsung Galaxy S2 Plus and re-
configured my HC-05 Bluetooth baud rate to 115200. Results may vary depending on your Android phone and Bluetooth module.

To modify your HC-05's default baud rate and other settings, refer to the section titled Boost Your Bluetooth Transmission Speed.

I have tested both utilities on my Windows 7 workstation using the free Microsoft Developer Express 2012 which you can download for fee from Microsoft. You can easily
modify this code to add functionality such as graphing, logging to hard disk, and sharing sensor data with other applications and users.

ESTABLISH THE CONNECTION

I have included an instructional video to explain the steps below. Make sure you have paired your Windows PC Bluetooth with your Android Bluetooth first. Let's install
and run the C++ sample program:

1. Download the attached "main.cpp" and save it to your computer.


2. Download and run Visual Studio Express 2012.
3. Select New Project.
4. From Templates, Select Visual C++ CLR Empty Project (call it SensoDuino).
5. From Solution Explorer, right-click on project name, not solution name.
6. Select Add Existing Item then pick the file main.cpp from Step 1.
7. Run SensoDuino and make sure you select only one sensor to transmit at 1 reading second. You can increase speed and add sensors later.
8. Run the C++ program.
9. A console for the C++ program will open up and it will prompt you to enter the COM port you wish to communicate with.
10. Enter the COM port assigned to your Bluetooth SensoDuino.
11. You should see a stream of numeric data showing up on your C++ application console each made up of comma-delimited numbers representing sensor
information such as type, count, and raw sensor readings, reading accuracy.

If the connection does not work the first time, stop the C++ application. Exit SensoDuino. Launch SensoDuino again then run the C++ program. Sometimes when
SensoDuino sends too much serial data to the serial buffer, the C++ program chokes on it. So make sure you sync running SensoDuino and the C++ program. If you see
garbage on the C++ console, adjust the baud rate.

Additional programming will be needed for the C++ and C# programs to parse the incoming SensoDuino strings into floats and integers per your requirements.

http://www.instructables.com/id/SensoDuino-Turn-Your-Android-Phone-into-a-Wireless/
Step 7: Log SensoDuino Data to File Then Import into Excel
SensoDuino logs data to a comma-delimited text file with a format that's consistent across all sensor data which means ease of importation into application such as Excel
or other analytical and charting tools.

The logged sensor readings follows this format:


SENSOR TYPE (string)
SERIAL COUNT (integer)
FIRST VALUE OR X (float)
SECOND VALUE OR Y (float)
THIRD VALUE OR Z (float)
ACCURACY (Integer)

Step 8:
In the list of official Android sensors below I have retained the sensor name and number as listed by the Android SDK SensorManager. For Audio (mic) and GPS, which
are not part of the Android SDK SensorManager family, I have assigned my own numbering and naming scheme starting from 99 downwards.

OFFICIAL ANDROID SENSORS

1- ACCELEROMETER (m/s^2 - X,Y,Z)


2- MAGNETIC_FIELD (uT - X,Y,Z)
3- ORIENTATION (Yaw, Pitch, Roll)
4- GYROSCOPE (Rad/sec - X,Y,Z)
5- LIGHT (SI lux)
6- PRESSURE (hPa millibar)
7- DEVICE TEMPERATURE (C)
8- PROXIMITY (Centimeters or 1,0)
9- GRAVITY (m/s^2 - X,Y,Z)
10- LINEAR_ACCELERATION (m/s^2 - X,Y,Z)
11- ROTATION_VECTOR (Degrees - X,Y,Z)
12- RELATIVE_HUMIDITY (%)
13- AMBIENT_TEMPERATURE (C)
14- MAGNETIC_FIELD_UNCALIBRATED (uT - X,Y,Z)
15- GAME_ROTATION_VECTOR (Degrees - X,Y,Z)
16- GYROSCOPE_UNCALIBRATED (rad/sec - X,Y,Z)
17- SIGNIFICANT_MOTION (1,0)

UNOFFICIAL ANDROID SENSORS

97- AUDIO (Volume in generic units)


98- GPS1 (Lat., Long., Alt.)
99- GPS2 (Bearing, Speed, Date/Time)

http://www.instructables.com/id/SensoDuino-Turn-Your-Android-Phone-into-a-Wireless/
Step 9: Boost Your HC-05 Bluetooth Transmission Speed
SensoDuino reads and transmits data for 12 sensors at speeds ranging from 1 Hz to 10Hz (sensor reading speed will increase in future releases.) Most of the supported
sensors send X,Y,Z data in floats converted to characters for serial communications. That's lots of data being processed, saved, and transmitted.

I doubt many application will require all SensoDuino sensors transmitting full throttle concurrently but it may be advantageous to configure the HC-05 Bluetooth module
(or your Bluetooth module) for the highest practical baud rate.

You have to experiment until you decide which speed is acceptable to you. I have published a guide on how to change the settings of the HC-05 in preparation for
SensoDuino increased bandwidth requirements. Follow any of the two links below for detailed how-to instructions to change the HC-05 configuration.

Modify The HC-05 Bluetooth Module Defaults Using AT Commands:

http://www.instructables.com/id/Modify-The-HC-05-Bluetooth-Module-Defaults-Using-A
http://www.techbitar.com/modify-the-hc-05-bluetooth-module-defaults-using-at-commands.html

http://www.instructables.com/id/SensoDuino-Turn-Your-Android-Phone-into-a-Wireless/
Step 10: Feedback & Bug Reorts
There are two ways to contact me regarding bugs and feature requests via SensoDuino.

CRASH REPORT

SensoDuino is equipped with a Crash Reporter from ACRA. When the app crashes it will open up a dialog box and prompt you for permission to send me the crash
report, next time you connect to the internet and run SensoDuino.

The ACRA crash reporter will send me technical info about your device such as Android version, app version, phone model, technical specs, stack info, etc to help me
identify the source of the crash so I can fix the bug. You can also enter a comment to send to me from the crash report dialog box.

FEEDBACK FORM

From the action menu of SensoDuino, select Preferences. At the bottom of the list of sensors, there's a Feedback form that you can use to send me your comments and
suggestions. You need to be connected to the internet.

For general inquiries, please use my contact form on this website.

Step 11: Android: A Capable Electronics DIY Platform


If you buy all the sensors supported by SensoDuino separately to go with your Arduino project from some of the well-known stores, you could pay over $200. If you have
an Android phone why not use its built-in sensors. And since Android is the most popular phone in the world today, it's a ready and capable DIY platform.

Even the newer SoC ARM boards being introduced today by top DIY vendors can't match the overall price, performance, and built-in features and integration of a mid-
range Android phone.

Here's a breakdown of the costs when you buy sensors and parts supported by SensoDuino and included in most Android phones:

ITEM / COST
-----------------------
Gyro $30
Accelerometer $15
GPS $45
Magnetometer $20
Bluetooth $20
Barometer $20
Temperature $5
Light Sensor $5
Audio Sensor $5
Display & Input $20
Battery/charger $20
SD card $10
Open Source Dev Tools $0
-----------------------
TOTAL: $215
TAX: Varies
SHIPPING: Varies.
CUSTOMS TARRIF: Varies

http://www.instructables.com/id/SensoDuino-Turn-Your-Android-Phone-into-a-Wireless/
Step 12: Resources
Android SDK | Sensors Overview
http://developer.android.com/guide/topics/sensors/sensors_overview.html

Android SDK | Position Sensors


http://developer.android.com/guide/topics/sensors/sensors_position.html

Android SDK | Motion Sensors


http://developer.android.com/guide/topics/sensors/sensors_motion.html

Android SDK | Environment Sensors


http://developer.android.com/guide/topics/sensors/sensors_environment.html

Android SDK | Location Sensor


http://developer.android.com/guide/topics/sensors/index.html

Sensor Fusion on Android Devices


http://www.youtube.com/watch?v=C7JQ7Rpwn2k

http://www.instructables.com/id/SensoDuino-Turn-Your-Android-Phone-into-a-Wireless/
Related Instructables

Quadcop Green/
Black Shield ---
QUADROTOR Laser Cut
Arduino
temperature (video) by Arduino AND MultiWii based
web monitor preddy12 Bluetooth HC-05 quadcopter by
Use your
(video) by kerimil Connecting dylanfm ArduRoller
android phone
sensors on the easily by balance bot by
arduino ! by a1r Mohannad fasaxc
Rawashdeh

Advertisements

http://www.instructables.com/id/SensoDuino-Turn-Your-Android-Phone-into-a-Wireless/

You might also like