Tuesday, March 1, 2016

Arduino to Android Part II

Arduino to Android using an Attiny85

So in a previous story I showed you how to send data from an Arduino Nano to the display of your Android device. I also told you there were many practical projects for this. Well I have made a practical project I want to share with you.

My girlfriends daughter and her husband bought a camper. And it is a very old and large camper. Well large isn't exactly the problem. The width is. 
As it is very wide it is almost impossible to see what is behind it. And therefore I decided to build a parking aid.

The idea is very simple. I'll take a HC-SR04 ultrasonic distance meter. Attach it to an Attiny85 and then send the measured distances over bluetooth to a mobile phone. Easy ?? Piece of cake !!!

First let me give you the schematics. In this you can see that the HC-SR04 ultrasonic distance sensor and the HC06 bluetooth module are attached to an Attiny85.

 I'll give the pin attachments for your convenience here.

Pin 5 of the Attiny85 is attached to the RX line of the Bluetooth module
Pin 6 of the Attiny85 is attached to the TX line of the Bluetooth module
Pin 7 of the Attiny85 is attached to the TRIG pin of the Ultrasonic Module and
Pin 2 of the Attiny85 is attached to the ECHO pin of the ultrasonic module.

On a breadboard it wil look as follows:

And that looks in real life like this:

As you can see the project can be powered by 3AAA batteries. The case for the batteries is designed by me and 3D printed. You can find the design for this case in an upcoming story.

Now lets's have a look at the arduino code:

Nor very complicated. First we define the TX and RX pins on the Arduino. Remember that we put the TX of the Attiny to the RX of the Bluetooth module and the other way round.  As the Attiny85 has no USB port or serial communication we use the Softwareserial library for this. Next we define the Trigger and Echo pins for communication with the Ultrasonic Sensor.
In the Setup() part we define the pins as INPUT or OUTPUT.

Next step is to put the Triggerpin for 10 microseconds HIGH and then measure how long it takes to get feedback on the ECHOPIN. The duration of the bouce has to be divided by 29.1 to get the sistance in Centimeters. And that's all.

Oh just one last thing. We print over the Bluetooth connection the words: The Distance is, followed by the measured distance.

So the nice part is that the Android screen will display what we print to it over bluetooth just like this shows:

Neat huh ????

Ok. On the Android side nothing has changed from the previous story. The Android program has been made with APP-Inventor and is therefore easy to edit for your own purposes. So get the source code here or the readymade APK which can directly be installed.

Rests me only to give you the Arduino code:

Arduino to Android distance measurer

So till next time.
Have fun.

Luc Volders