There is nothing like seeing a program you wrote interact with the physical world. For this lab experiment you can make and program your own robot.
I began with instructions for the micro robot from Greece but realized my soldering skills are lacking.
But it did give me an idea for the parts I would need to get a small form factor robot up and running. This led to a search of Amazon for applicable parts. I needed at least two motors, some model of Arduino, a L293D H-Bridge Motor Driver chip, some servos for additional capabilities and a platform for all the parts to attach to.
Here is what I ended up with.
Total cost was around $40.00.
I picked the nearly compatible generic Arduino Nano because of its built in USB support and small form factor and its price. I say nearly compatible because its USB driver chip is a cheaper version than what comes on an official Arduino. It requires special drivers that have to be installed on the computer you are using to program the Arduino. I used the article, How to Use Cheap Chinese Arduinos with the CH340G USB Chip On Yosemite and Windows. It will show how to install the driver and enable it so it works with the Arduino IDE where you can write your code.
To find the computer chip you would like to use consult this chart at the Arduino website.
To make sure things were working I connected the Nano to my computer, started up the Arduino IDE and loaded the blink example code or what they call a sketch. Then I uploaded it to the Arduino and watched the onboard LED blink on and off.
The next step, the exciting part, was to wire up the L293D chip to the Arduino.
RobotPlatform.com had a great explanation and pin diagrams of the L293D. But I used a video to really nail down how to attach the two parts together using two breadboards and jumper wires between the two.
In the video he maps out what pins to attach to on the Arduino. The pin numbers are written on the Arduino board.
But here is a diagram that I made that will help you line up the wiring pin by pin. First use the mini bread boards.
I used one for the L293D motor driver chip and another for the Nano. You can use the jumper wires to push into the holes on the breadboard that line up with the pin you want to connect. You will need to attach more than one wire to some of the pins. This configuration will allow the battery pack to power the motors and the chip. Make sure you are supplying at least 5 volts. The VIN pin is for unregulated power so if your motors need more power just supply more voltage. The Nano has a built in voltage regulator.
- Pin 8 -> VIN on Nano
- Pin 1 -> Pin 16
- Pin 9 -> Pin 16
- Pin 16 -> 5v on Nano for power
- Pin 4 -> Pin 5 for Grounding
- Pin 12 -> Pin 13 for Grounding
- Pin 4 -> Pin 13 for Grounding
- Pin 12 -> Gnd on Nano
- Pin 10 -> D5 on Nano controls right motor
- Pin 15 -> D4 on Nano controls right motor
- Pin 7 -> D7 on Nano controls left motor
- Pin 2 -> D6 on Nano controls left motor
- Pin 3 -> - on left motor
- Pin 6 -> + on left motor
- Pin 14 -> - on right motor
- Pin 11 -> + on right motor
- on battery pack -> VIN on Nano VIN is for raw power.
- on battery pack -> GND on Nano
At some point after I had it all working I crossed the V5 wire with the ground and shorted out the Arduino. So be careful with that. I ended up finding a lower cost option and purchased three new Nanos. This way of wiring it up allows the Arduino and the motors to be powered from the same battery pack. I used the battery container that came with the chassis kit which supplies 6v.
Now it’s time to program the Nano and see what it can do. I used the code samples from the Arduino forum and modified it to work with the pins I selected for controlling the motors.
To program the Arduino get the IDE from Arduino.cc and install it. Follow the directions at How to use cheap Arduinos. In the IDE select the Tools menu and select the Board you have (in my case Nano), the processor (I have the ATamega328) and the port (mine shows as dev/cu.wchusbserial1420).
Upload this to your Arduino and see what happens. It should drive forward or backward for 3 seconds depending on which direction you attached the wires then it should stop turn quickly to the left and then go forward again. It will loop forever until you press the reset button or kill the power.
Let me know here how it works for you and follow the blog and twitter volumeint for future lab projects. Upcoming posts include IoT, Internet of Things and adding sensors to the Arduino robot.