This instructable shows you how to control a small battery powered DC motor via bluetooth using a few basic components.
Step 1: Materials
You will need:
- 1x Arduino (any will do but you may need to modify pins numbers in the sketch)
- 1x Transistor capable of 400MA+ current (I used a 2N4401 I got 10 for £1 on ebay)
- 1x 3v DC motor (I ripped mine from a hand held fan)
- 1x 330 Ohm resistor
- 1x diode (Not sure which one I used as I picked a random one I had but any simple one will do)
- 2x 1.5V AA battery
- 1x Some kind of holder to chain the batteries together (I used the remainder of the fan I tore apart)
- 1x Arduino Bluetooth module HC-05 (Again I got mine from ebay for less than £5)
- 1x Small breadboard and jumper wires
Step 2: The Wiring
The schematic shows what we are trying to achieve. The basic idea of the circuit is to have the batteries supply power to the transistors collector pin via the motor. Then when the Arduino outputs a logical high it will allow the current to flow from the batteries through the transistor to ground making the motor spin.
Step 3: Connect the Batteries to the Breadboard
Our batteries will act as our power source in this circuit with the Arduino just used for control. The batteries need to be chained together to give an output of 3V. Simply connected the chained batteries positive terminal to the positive power rail and the negative to the ground rail.
Step 4: Connect the Motor & Diode
This step is fairly simple but tricky to explain so I'd advise you follow the schematic.
- Connect power bar to diode terminal with the stripe on it
- Connect one of the motor terminals to the same diode terminal
- Connect the other motor terminal to the other diode terminal
The diode is used to provide a safe path for current to flow when there is a sudden change in current. For more info on this see here: http://electronics.stackexchange.com/questions/951...
Step 5: Connect the Transistor
- Connect the transistors collector pin to the diode terminal without the stripe on it
- Connect the base pin to the 330Ohm resistor then connect that resistor to pin 3 of the Arduino
- Connect the emitter pin to the ground rail
- Finally we must connect the ground pin of the Arduino to the ground rail so both batteries and the Arduino share a common ground
In this circuit our transistor acts like a switch allowing current to flow from the collector to the emitter when there is current going into the base pin. This allows us to use the pin of the Arduino to control our motor without needing to power our motor with the Arduino itself.
Step 6: The Sketch
Our sketch is fairly simple we read a number from serial then output that number to our pin. The higher the value the faster the motor will spin. Our project relies on the fact that the analog pins are actually PWM pins on the arduino.
If the pin output value for the pin is 100 then the pin will be high for about 40% each cycle (100/255*100). This is why the motor will spin faster if the value is higher.
It is a good idea to test the circuit now!
Open up the arduino ide connect your board then open the serial monitor. IMPORTANT: Choose "Both NL & CR" as the line ending otherwise the values will not be read. Enter some values in the serial monitor and hit enter you should be able to control the motor speed!
If this doesn't work it may be a good idea to check your wiring now.
Step 7: Adding Bluetooth
We are almost there! We have a circuit that we can control via serial now we need to replace the serial connection from our computer with the bluetooth module.
Doing this is fairly simple the pin connections are the following:
- Module VCC to Arduino 5V
- Module GND to Arduino GND
- Module RX to Arduino TX
- Module TX to Arduino RX
Step 8: Connecting Via Bluetooth
Power on your Arduino it does not need to be connected to a computer as data will be going via bluetooth instead of USB this time.
Download a bluetooth serial app for your phone I use https://play.google.com/store/apps/details?id=mobi... which I have found to be particularly good.
Connect to your board and send some values between 0 to 255. Congratulations you are done.
I'd really appreciate feedback on this tutorial if you have any!