Why care about MIT App Inventor?

The other day I made a post about using App Inventor to create a simple UI for the Particle Photon. I have also been working on a project that involves an internet connected Weather Cloud. To make it easy for the owner to control this cloud, I have put together and Android app.

image

This works much faster that using something like IFTTT and requires no additional libraries like Blynk.

This brings up an interesting observation when it comes to IOT. If you want to interact with your devices, there are not a lot of good ways to go about it.
You can throw some Ajax onto your web server. If you have a web server that is.
Connect your devices API to another companies API and send your data on an epic journey when you are often in the same room as the device you are sending data to.
Make your own API and take pride that you have joined a legacy of frustrated developers world wide. Then scrap it all to use IFTTT just so much easier.
You could add a few new libraries to your firmware so that it can talk to a custom UI app like Blynk. This is actually not a bad option except that I should not have to add a new library to exploit the basic HTTP interaction protocol that comes standard with the Particle API.
Going back to the web server thing, you can just use a simple HTML page and form data for interaction. This just leaves your device credentials open for the world to see.

This is the problem with IOT right now. There are lots of ways to interact with devices, but no really good way to just go from user to device for the average person. App Inventor gives us a quick fix by letting us create an app that just uses HTTP GET and POST requests while keeping the credentials private. However, we need something better. An app that uses basic the preexisting protocol with an intuitive UI.

This is what I am working on at the moment with Vince at SoDo MakerSpace. An app like Blynk with no additional libraries, IFTTT without the additional API hooks, and Ajax without all of the coding.

I feel like this will help to open the door to the dream of IOT for the masses.

ArduDroid & HC-05 Bluetooth

ArduDroid02
A Simple 2-Way Bluetooth-based Android Controller for Arduino.

REQUIREMENTS

  • Breadboard wiring and electronics skills.
  • Arduno Uno.
  • HC-05 Bluetooth serial module.

INTRODUCTION

ArduDroid (formerly Andruino) is a simple tool to help you control your Arduino (or clone) from your Android phone. It’s both an Android app and an Arduino program. ArduDroid has a simple Android user interface to 1) control Arduino’s digital and PWM pins 2) send text commands to Arduino 3) and receive data from Arduino over Bluetooth serial using the ever popular and really cheap (less than $10 from ebay) HC-05 Bluetooth over serial module. This app has been tested and designed for the HC-05 Serial Bluetooth module. Other Bluetooth modules may or may not work. Please see comments section for users who tried other Bluetooth modules with this app.

INSTALL FROM GOOGLE PLAY
https://play.google.com/store/apps/details?id=com.techbitar.android.Andruino

ArduDroid should work with other Bluetooth modules with some tweaking but I have only tested it with the HC-05. This is an alpha version that’s running fine on my Samsung Galaxy S2 Plus. Please share your experience running ArduDroid on your phone. Also, while I used Arduino Uno in this prototype, feel free to experiment with other models of Arduino. Please share your experience to help me improve this app.

I have published a guide before on building and programming a circuit with the HC-05 Bluetooth module and Arduino but I will briefly describe again in this guide how to wire the circuit using a breadboard and jumper wires.

ArduDroid is an app that evolved during one of my development projects. Special thanks to engineer Jafar Quttaineh for testing the app and for his invaluable input.

Step 1: How to use ArduDroid

ArduDroid03

You can use ArduDroid to send commands to Arduino to control a relay to turn electric gadgets on/off, control a robot servo, increase/decrease speed of a motor and reverse direction, dim a light, speed up a fan, and so on. Furthermore, you can read Arduino pins and sensors then transmit the data back to your android phone.

Step 2: ArduDroid components & downloads

ArduDroid04

1) Install ArduDroid from Google Play:
For previous version downlowded from my website, this is the certificate fingerprints:
MD5 : BA:80:C2:6A:68:31:8F:21:D6:FC:08:8E:09:D8:F5:CF
SHA1: 04:EA:2E:47:80:71:BE:D9:D2:ED:86:5F:15:1F:1E:9E:77:62:DB:85

2) Download the Arduino program: ardudroid.ino (requires Arduino IDE 1.05 or later)

HARDWARE

  • Android device running version 2.3.3 or higher with Bluetooth.
  • Arduino Uno or clone.
  • CD4050 level shifter IC or 2K Ohms & 1K Ohms resistors as voltage dividers.
  • HC-05 Bluetooth module. Other Bluetooth over serial modules should work with some modifications.
  • Breadboard & jumper wires.
  • Power source.

Step 3: Wiring the Circuit

ArduDroid05
Please note that while my actual prototype as shown in the video and photo uses the CD4050 IC to level shift from 5V to 3.3V, in the wiring diagram I am using a voltage divider because I believe it will be simpler for most people to acquire the resistors than the IC. You only need to drop the Arduino’s TX voltage to 3.3V to match the RX of the HC-05. The Arduino’s RX pin can handle the HC-05 incoming TX signal which is 3.3V.

I used 2K and 1K ohms resistors in my circuit diagram to drop 5V to 3.3V but you can use different resistor values. Google “voltage divider calculator” and use the myriad calculators to determine what other resistor values work best for you.

Step 4: How to modify the ArduDroid companion program

ArduDroid06
On the Arduino side I have included a skeletal program (ardudroid.ino) that intercepts and processes the ArduDroid commands issued from your Android device. You can update the Arduino code according to your project needs.

ArduDroid is an Android app that sends/receives data from Arduino with the help of an Arduino sketch named ardudroid.ino In this sketch, there are four code blocks supporting the four key functions of ArduDroid. You can modify these code blocks to suit your requirements.

The blocks are labeled according to their functions in a comment line at the start of each code block. I inserted a comment “// add your code here” to help you find and place your code, but you can decide how you wish to modify the functional code blocks.

Step 5: Control analogWrite pins

ArduDroid07 This is the code block that receives the PWM value from 0 to 255 that you send from Android to control the PWM designated Arduino Uno pins 11,9,10,5,4,3. You can add code to control a motor for a robot or fan, for example, to speed it up or slow it down. Or you can send a command to dim a light.

Step 6: Control digitalWrite pins

ArduDroid08 This is the code block that receives from Android the pin number and the ON/OFF (HIGH/LOW) value to toggle the corresponding pin. You can turn a relay on /off to switch an electrical device. Please note that this code block calls a function set_digitalwrite() which has a Switch/Case structure to give you room to write code to act on each pin separately.

I have excluded pin 0 and pin 1 because they are used for Arduino Uno serial communication by default. I might enable those two pins in future releases of the app and leave it up to the user to determine which pins will be used for the Arduino serial communications.

Step 7: Send text/command from Android to Arduino

ArduDroid09 This is the code block that handles the text you type in the field next to Send Data button. For example, you can send a password to activate/login into a system. Or you can send text to an LCD connected to Arduino to display something.

Step 8: Get text/command from Arduino

ArduDroid10This code block sends anything you want from Arduino to your Android. In my sample code below, I send the value of analog pin 0 whenever I press the Get Data button. Since analog pin is not connected to anything in the demo video, I was getting ambient noise values. Please note that there is no error detection/correction in my code block. If accuracy is critical to your app, make sure you add error detection such as visual markers to enclose the data being sent or a checksum.

 

Step 9: Things to consider

ArduDroid11 Alternatives to ArduDroid

There are a quite a few solutions to enable Android-Arduino integration. The more expensive and complex ones involve specialized and costly hardware such as Google’s ADK, but by far the cheapest and in my opinion the simplest is the Bluetooth integration using the HC-05 transceiver. I expect WiFi to eventually replace Bluetooth with the help of WiFi Direct (point to point WiFi communications without a router) but his is a couple of years down the road.

As for Bluetooth-based solution for Android to Arduino communication, you can find a few approaches to pick from depending on your project needs and the degree of abstraction you are looking for. Some approaches use a terminal app on the Android such as Blueterm to send and receive raw text data from Arduino over Bluetooth SPP. Others solutions employ a comprehensive library such as Amarino. My ArduDroid sits in the middle.

Notes on support and updates

I will do my best to support ArduDroid and I am hoping that those of you who find this tool useful to share your expertise with other users. Please let me know if you run into any bugs or problems running ArduDroid on your device. Kindly note the device model and OS version as well as other useful info.

Please feel free to leave a comment if you have any technical questions.