Aurduino + Android + Bluetooth = Naughty / Nice Meter - Part 1 of 2
by cdsgraphic in Circuits > Arduino
4893 Views, 52 Favorites, 0 Comments
Aurduino + Android + Bluetooth = Naughty / Nice Meter - Part 1 of 2
This is Part 1 of a 2 part Instructable.
Part 1 is about getting the electronics to work.
Part 2 will be about putting it all together into what we'll call the "Naughty / Nice Meter" -or- "The best damn way to get my daughter to behave I've found in years, Meter ! ! !"
Jump to part 2 here.
This project is/was inspired by a similar project that Ben Heck published on his YouTube channel.
What I have done here is try to simplify his idea to a point that anyone with some basic electronics/Arduino and crafting skills can build this. I have also made it a point to do this as inexpensively as possible. This whole build could easily be done for less than $20 even if you have to buy most of the parts outright. We'll assume you already have some of the tools needed, especially for Part 2.
Why two parts?... I just thought it would be easier to reference if getting the electronics to work was separate from the actual build. As well as just controlling something via Bluetooth is, in itself, very useful.
This entire project can be easily done in less than a day, and maybe a few hours if your experienced!
So let's get started...
The Stuff...
1 Arduino UNO or similar (clones can be found on that popular auction site for less than $5)
...and the Arduino coding software for your computer
1 SG-90 mini servo motor (again... can be found on that popular auction site for less than $5)
...be sure the one you get has several 'servo horns' with it, we'll need at least one.
1 Bluetooth serial module (and again... can be found on that popular auction site for less than $5)
...I use the HC-06 module for this project
1 Android Smart Phone - that has Bluetooth capability
Some jumper wires to hook everything up (no soldering if you use jumper wires)
...you will need an assortment of 'male-male', 'female-female' or 'male-female' jumpers
1 9 volt alkaline battery
1 9 volt battery clip with plug
Getting in Touch With Arduino
Connecting the Arduino to the Computer...
I'm not going to go into detail about this because it's covered in lot's of other Instructables, the Arduino website, and all over the net.
--------------------------------------------
But basically (if you haven't done it before)...
Connect Arduino to computer via a USB cable.
Install USB drivers for Arduino if they aren't installed automatically.
Start Arduino sketch interface.
Set the type of Arduino you are using and the COM (USB) port it is connected to.
Open or copy the copy code into the sketch window.
Upload the code to the Arduino.
Done.
Arduino Needs to Learn Some Moves
First, I prefer to have the Arduino powered down while I'm connecting or disconnecting things to it... so maybe it would be a good idea to unplug the USB cable for now.
Following the diagram connect your SG-90 servo to the Arduino.
Most SG-90 servos that I have seen have Brown, Red and Orange wires.
Brown - negative or ground (GND)
Red - positive or hot (VCC / 5V)
Orange - control or trigger
-------------------------------------------
Using jumper wires...
Connect the brown lead to a ground pin on the Arduino.
Connect the red lead to 5V pin on the Arduino
Connect the orange lead to digital pin 9 on the Arduino
-------------------------------------------
Connect the Arduino to the computer once again via the USB cable.
The servo should 'twitch' just a little as it gets power.
-------------------------------------------
Download the "serial_servo_control.ino" code from this step.
Open the Arduino application and load (open) the code you just downloaded.
Upload it to the Arduino.
Some lights should flash on the Arduino for a second and then settle back to 'normal'.
-------------------------------------------
Now open the serial monitor interface from within the Arduino application.
A couple of lines of text should appear telling you the the servo is attached and to enter a number.
Enter any number from 1 to 179 and press enter (the range of a servo is generally 0 to 180 degrees).
The servo should have moved to the number (degree) you entered. (it is easier to see it move if one of the servo horns are installed)
And the serial monitor should be ready to accept a new input.
-------------------------------------------
Congratulations, let's move on to the next step.
Downloads
Android Wants Control...
First, disconnect your Arduino from the computer and the USB cable from the Arduino. But leave the servo attached. Set the Arduino and servo aside for now. And you can also exit the Arduino application on the computer.
--------------------------------------------
Download the Android app ("bluetooth_servo_control.apk") from within this step, either with your Android phone or transfer it to you phone from your computer. Install the app.
NOTE: You must have "Unknown Sources" enabled within the security settings of your phone in order to install the app.
NOTE: The only thing I have written into this app for it to use is stuff related to Bluetooth. So if your worried about any weird permissions that may show up during the install... well, that's all that's in there.
--------------------------------------------
I have also included the original "source code" (bluetooth_servo_control.aia) if you would like to look at or modify it at the MIT App Inventor website.
--------------------------------------------
Once the app is installed, run it, to make sure that it will start on your device. It really should run on just about any Android phone.
Quit the app for now... we'll come back to it in a moment.
--------------------------------------------
Moving on...
Arduino Needs Some Attention Now...
Up to this point we have attached the servo to the Arduino and loaded the control program to it, installed the Bluetooth control app to the Android phone.
Now we will connect the Bluetooth module to the Arduino.
--------------------------------------------
PLEASE NOTE: In the diagram provided, the Bluetooth controller itself is a different model than the HC-06 we are using, but the connections are the same.
--------------------------------------------
Using 4 jumper wires, make the connections as follows... (these colors are arbitrary and can be replaced with whatever is available).
Red - Arduino 3.3V --> Bluetooth VCC (my be labeled differently on other boards)
Black - Adruino GND --> Bluetooth GND
Green - Arduino TXD --> Bluetooth RXD
Blue - Arduino RXD --> Bluetooth TXD
NOTE: Be sure to have the TXD and RXD wires 'cross-over' or it won't work.
--------------------------------------------
We do not need to plug the Arduino into the computer anymore, so using the 9V battery and connector, supply power to the Arduino board.
The Arduino lights should flash for a second, the servo should 'twitch' and the light on the Bluetooth module should be blinking rapidly.
--------------------------------------------
All good?... Let's move on...
Android... Meet Arduino...
Now that we have the Arduino running on battery power with the servo and Bluetooth connected... It's time to connect our Android phone to the Bluetooth module.
--------------------------------------------
First things first, if it's not already, turn on the Bluetooth radio in your phone... ok, good.
Now, open the Bluetooth control panel in the phone and search for devices (we need to pair our phone with the Bluetooth module before we can connect to it via the app).
The module should show up in the the list of devices (it will probably be a string of letters and numbers followed by "HC-06" or "HC06" or something similar.
Click on it and you should be prompted for the password. By default it is normally... 1... 2... 3... 4...
--------------------------------------------
"So the combination is... one, two, three, four? That's the stupidest combination I've ever heard in my life! That's the kind of thing an idiot would have on his luggage!"
hehe... sorry, I couldn't resist it!
--------------------------------------------
If everything went well, your phone and blutooth module should now be paired.
NEXT!
Gentlemen... Start Your Apps!
You should have the Bluetooth module and your phone paired from the previous step.
As well the Bluetooth radio should be on.
------------------------------------
Start the app we installed earlier... It's nothing special, but it gets the job done.
Touch the "Connect Bluetooth" button.
A list of all your paired Bluetooth devices should now be shown.
Select the "HC-06" Bluetooth module.
If the connection is successful, the "Connect Bluetooth" button will turn green and the text will change to "CONNECTED".
And the flashing light on the HC-06 Bluetooth module will now be on steady.
If not, an error message will probably pop up on your screen saying something to the effect of "...couldn't connect...".
------------------------------------
Assuming that all went well, and the app is now connected to the Bluetooth module...
Move the slider to a position and the servo should move!
Did it move... huh... well did it?... Awesome!
------------------------------------
If things aren't working out the way they should...
Go back through and double check all connections.
Is the phone and Bluetooth module paired?
If all else fails, post a question in the comments and I or someone in the community might be able to help.