Introduction: Robot Car With Bluetooth, Camera and MIT App Inventor2
Did you ever wanted to build your own robot car? Well...this is your chance!!
In this Instructable I will walk you in how to make a Robot Car controlled via Bluetooth and MIT App Inventor2. Be aware that I’m a newbie and that this is my first instuctable so please be gentle in your comments.
There are many instructables out there but in this one I’ve tried to combine many features such as: camera streaming, obstacle avoidance, ultrasonic range sensor, Larson scanner (with charlieplexing) and battery monitoring to an Android App!!
So let’s get started and meet Frankie (it uses ideas from many places....hence Robo Frankenstein)
Step 1: Parts and Software
Here, in my home town, it is difficult to get all the parts, therefore I was able to get most of them from www.aliexpress.com
I estimate that the project can be built for USD 25 - 30 without considering the old cellphone.
- Car chassis: 3 wheels, 2 motors 6V (USD 9)
- Arduino Nano (USD 2)
- Bluetooth HC-05 (USD 3 to 4)
- L293D motor driver to drive wheel motors (USD 1.50 for a 5 pieces lot)
- Old cellular with camera and Wi-Fi
- Ultrasonic sensor HC-SR04 for measurement to a nearby object (USD 1)
- 6 LEDs for Larson scanner
- ATtiny85 for Larson scanner (USD 1)
- Breadboard (USD 1)
- 100K Ohm resistor (4)
- 1K Ohm resistor (2)
- 2K Ohm resistor (1)
- 270 Ohm resistor (3)
- Arduino IDE
- IP Webcam (for old cellular Android)
- MIT App Inventor2: This App is great but only works for Android operating system (no Iphones…sorry!)
Step 2: Construction Process
Car chassis is very easy to assemble; it has 2 motors 6V that powers rear wheels and a 4 battery pack.
The Robot car is controlled via Bluetooth and Wi-Fi. Bluetooth controls the serial communications between the Car and MIT App inventor2 and Wi-Fi is used to communicate with the camera (old cellphone) installed in front of the car.
For this project, I have used two set of batteries: the arduino is powered by a 9V battery and the car motors by 6V (four 1.5V AA batteries).
Arduino Nano is the brain of this project that controls the car, buzzer, ultrasonic range sensor HC-SR04, Bluetooth HC-05, Larson scanner (ATtiny85) and monitors the batteries. 9V battery goes to Vin (pin 30) and Arduino's pin 27 gives 5V regulated power to breadboard. Need to tie all grounds from all the ICs and batteries together.
Attached, the circuit diagram made it in Excel (Sorry.... next time I’ll try Fritzing). I've connected everything using breadboard and male to male wire connectors, mine looks like a rats nest.
Step 3: L293D Motor Driver
L293D is a quadruple high current half-H driver designed to provide bidirectional drive currents of up to 600 mA at voltages 4.5V to 36V. It is used to drive the car wheels.
It is powered by a 6V battery pack (four 1.5V AA) for the motors and uses 5V for the logic that comes from regulated 5V (pin 27) in Arduino Nano. Connections are shown in the attached schematic.
There was no need to install it in a heat sink.
Step 4: HC-05 Bluetooth
HC-05 Bluetooth is powered by 5V (arduino pin 27), but it is important to understand that the logic level is 3.3V, i.e. communications (Tx and Rx) with 3.3V. That is why Rx has to be configured with maximum 3.3V which can be achieved with a level shifter converter or, as in this case, with a voltage divider by using a 1K and 2K resistors as seen in the circuit.
Step 5: Battery Monitor
In order to monitor the battery levels I have set voltage dividers in order to bring voltage levels below 5V (Arduino’s max range). The voltage divider decreases the voltage being measured to within the range of the Arduino analog inputs.
The analog inputs A4 and A6 are used and high resistors (100K ohms) are used in order not to drain the batteries too much in the measurement process. We need to compromise, if resistors are too low (10K ohms), less loading effect, voltage reading is more accurate, but more current drawing; if they are too high (1M ohms), more loading effect, voltage reading is less accurate, but less current drawing.
Battery monitoring is made every 10 sec and displayed directly in your controller cellphone.
I’m sure there is lots of room for improvement in this part since I’m reading from two analog pins and the internal MUX is swapping between them. I am not averaging multiple measurements and maybe that is what I should be doing.
Let me explain the following formula:
//Read voltage from analog pin A4 and make calibration for Arduino: voltage1 = (analogRead(A4)*5.0/1024.0)*2.0; //8.0V
The Arduino nano board contains 8 channel, 10-bit analog to digital converter. Function analogRead() returns a number between 0 and 1023 that is proportional to the amount of voltage being applied to the pin. This yields a resolution between readings of: 5 volts / 1024 units or, .0049 volts (4.9 mV) per unit.
Voltage divider halves voltage and, in order to get true voltage, need to multiply by 2!!
IMPORTANT: I doubt there is a more inefficient way to power an arduino than the way I'm doing it!! As a newbie I've learned the hard way. Arduino Vin pin uses a linear voltage regulator which means that, with a 9V battery, you will be burning a big chunk of the power in the linear regulator itself! Not good. I did it this way because it was fast and just because I didn't know better ...but be sure that in Robo Frankie version 2.0 I will certainly do it differently.
I'm thinking (out loud) that a DC DC Step up Switching Power Supply and a Li-ion rechargeable battery might be a better way. Your kind suggestion will be more than welcome...
Step 6: HC-SR04 Ultrasonic Range Sensor
HC-SR04 is an ultrasonic range sensor. This sensor provides measurement from 2cm to 400cm with a ranging accuracy of up to 3mm. In this project, it is used to avoid obstacle when it reaches 20cm or less and also to measure the distance to any object, which is sent back to your cell phone.
There is a button in your cellphone screen that needs to be clicked in order to request distance to a nearby object.
Step 7: Larson Scanner
I wanted to include something fun, so I included Larson scanner which resembles K.I.T.T. from Knight Rider.
For the Larson scanner I’ve used ATtiny85 with charlieplexing. Charlieplexing is a technique for driving a multiplexed display in which relatively few I/O pins on a microcontroller are used to drive an array of LEDs. The method uses the tri-state logic capabilities of microcontrollers in order to gain efficiency over traditional multiplexing.
In this case I’m using 3 pins from ATtiny85 to light 6 LEDs!!
You could light up "X" LED’s with N pins. Use the following formula to derive how many LEDs you can drive:
X= N(N-1) LEDs with N pins:
3 pins: 6 LEDs;
4 pins: 12 LEDs;
5 pins: 20 LEDs…you get the idea ;-)
Current flows from positive (anode) to negative (cathode). Tip of the arrow is cathode.
It is important to note that pin 1 (in Arduino IDE code) refers to physical pin 6 in ATtiny85 (please refer to attached pinout).
Attached please find the code that needs to be uploaded to ATtiny85 that controls Larson scanner. I'm not describing how to upload a code into ATtiny85 since there are plenty of instructables that do that like this one.
Step 8: Code
I'm attaching the code that needs to be uploaded to ATtiny85 that controls Larson scanner and the code for Arduino nano's.
As for the Arduino nano, I have used part of codes from other instructables (here) and made changes to fit my needs. I have included a flowchart (also in word for a clearer image) of the code to better understand how the Switch - Case works.
Important: In order to upload CarBluetooth code into Arduino nano, you need to disconnect Rx and Tx from HC-05 Bluetooth module!
Step 9: Camera
IP Webcam app needs to be downloaded from play store and installed in your old cellphone. Check for video preferences, adjust resolution accordingly and finally go down to the last command “Start server” in order to start transmission. Don't forget to turn Wi-Fi in cellphone!!
Step 10: MIT App Inventor2
MIT App inventor2 is cloud based tool that helps build apps in your web browser. This app (only for android based cellular) can then be uploaded to your cell and control your robot car.
I am attaching .apk and .aia code so you can see what I’ve done and can modify it as you wish. I have used a code from the internet (MIT App) and made my own modifications. This code controls movement of the robot car, receives signal from ultrasonic sensor, turns on lights and beeps the buzzer. It also receives signal from the batteries letting us know the voltage level.
With this code we will be able to receive two different signals from the car: 1) distance to a nearby object and 2) voltage from motor and arduino's batteries.
In order to identify the serial string received, I have included a flag in Arduino's code that specifies the type of string been sent. If Arduino sends the distance measured from ultrasonic sensor, then it sends an “A” char in front of the string. Whenever Arduino sends Battery levels, it sends a flag with a “B” char. In MIT App inventors2 code I have parsed the serial string coming from Arduino and checked for these flags. As I said, I’m a newbie and I’m sure there are more efficient ways to do this and I hope someone can enlighten me in a better way.
Send Arduino_Bluetooth_Car.apk to your cellphone (via email or Google Drive) and install it.
Step 11: Connect Your Cellphone to Your RC Car
First of all, turn on wi-fi in old cellphone (the one in RC robot).
In your controller cellphone turn on your wi-fi, Bluetooth and open Arduino_Bluetooth_Car.apk that you just installed. At the end of the screen (scroll down if you cannot see it) you will see two buttons: Devices and CONNECT. Click Devices and select the Bluetooth from your RC Car (should be something HC 05), then click CONNECT and you should see the CONNECTED message at the left bottom of your screen. The first time, you will be asked for a password (enter 0000 or 1234).
There is a box where you need to type the IP address of your old cell (cellphone that is in your RC Car), in my case it is http://10.97.148.132
This IP number can be detected in your Wi-fi Router. You need to get into your Router configuration, select Devices List (or something like that depending on your Router brand) and you should be able to see your old cell device, click on it and enter this IP number into this box.
Then select CAMERA and you should start viewing the camera streaming from your RC Car.
Step 12: You Are Done!
You are done! Start playing with it!
Future changes: I will change the 9V battery with Li-ion batteries in order to recharge them and use a DC-DC step up voltage regulator, also I want to enhance the battery monitor by including smoothing (averaging) of the analog readings. Not planning to include A.I. yet ...;-)
I've entered my first instructable contest...so please vote ;-)
We have a be nice policy.
Please be positive and constructive.