This Instructable deals with the construction of a RC 2WD robot under Arduino, and the construction of the prototyping PCB on the vehicle.
There are many pages dealing with similar subjects, f.eg. for the vehicle: http://billwaa.wordpress.com/2012/06/06/arduino-l... , and for prototyping boards: https://www.instructables.com/id/How-to-Prototype-... or https://www.instructables.com/id/How-to-Prototype-...
This webpage is different not only because it is mine, which it is indeed (and in fact my first Instructable!), but because it describes both the steps to the goal as well as the mistakes I made, which were too many and, some of them, funny enough.
This record of the mistakes is what I think makes this Instructable worth reading and what has convinced me of writing it . . .
So ... I hope you can enjoy & learn going through them.
Step 1: THE GRAND SCHEME
I started with Aruino few months ago. Once I decided to build my pet-robot, I ordered the parts which I thought would be needed. And while waiting for the pieces to arrive I started grandiose planning. Even being just barely familiar with the motor control in Arduino, or with soldering, I decided that my robot would follow some sensors (my claps, for instance, or that it would be shy and hide from light). In addition to that, it would have a distance sensor mounted on servos which would create an image of the surroundings, acting as a sonar. This image would then be wirelessly forwarded to my mobile so that I could see what was happening around my cute pet. Needless to say, the robot would also have a bit of intelligence with a Bayesian inference procedure which would help it to follow the best path to its final destination. My youngest daughter started to think in names for the new family member, and I considered leaving my job and move into DIY electronics. My wife nodded.
So, the kit for the vehicle arrived. . .
Step 2: THE 2WD VEHICLE
I bought the kit for the 2WD vehicle from China and here is the source: http://www.dhgate.com/product/new-arrival-motor-s...
It came with no instructions, but Internet assisted with pictures of the assembly, so I quickly had it ready: http://www.ebay.com/itm/2WD-Smart-Robot-Car-Chass...
This easy conquer gave me even more confidence. . .
Step 3: BATTERIES HOLDERS
Two set of batteries are required (Arduino logic controller separated from motor power), so I decided to place them where they didn’t bother me: under the chassis.
6 V for the motors equals 4 AA batteries; 9 V for the Arduino Mega equals 6 of the same batteries: so two holders for 4 and 6 batteries.
It was a good movement – but the head of the screws supporting the holders protruded from the plastic body, so some batteries were not totally enclosed and had a nasty tendency to fall . . . which was compounded by gravity, that easily forgettable force of Nature.
Later I changed to Arduino mini Pro, at 6 V, so my 6 AA battery holder was also in need of additional retrofitting . . .
Step 4: THE MOTORS
I had read of IC motor controllers, L293D, but I didn’t have one so I started with transistors and diodes. And it worked! But it used a lot of space in my bread board, and I didn’t see an easy way to move back and forth the vehicle, so I decided to jump into the L293 world.
Unfortunately my city dealers either didn’t have L293 ICs, or only L293B. I thought “B, D? It cannot be that big a problem”. The alternative was ordering through Internet and waiting for the shipment, so . . . I bought few L293Bs. They are good, but . . . they do not have diodes to protect the controller from the reverse EMF, so I had to prepare a bunch of 4 diodes per L293B, which was even messier on the breadboard. . .
By that time, with already enough problems, I started crying about the motor connections. My motors have a small, thin, perforated connector for each of its two feeding lines. I started using my male-male pinned cables, so I could directly feed them from the board. The contact was not good, of course, so I . . . glued the pin to the connector! And I worked like that until I decided that enough was enough and I . . . soldered them, yes!
Step 5: THE SECOND DECK
With my grandiose plans I noticed with horror that the chassis did not provide enough room for all my needs, real or potential. Hence I prepared for a second deck on the vehicle, so that the Arduino board would be on the lower floor, like in a boat’s engine room, and all the higher and cleverer sensors on the upper one, like in a gent’s (and lady’s) head.
For the upper deck I used some MD panels that I recovered from some box and prepared everything with 3 cm spacer bolts. . . Just to see that there was not enough clear room for the Arduino board and all the attached pin cables.
Well . . . this made me bring everybody up to the nobler second deck. Now, with everybody packed on the top it was clear that there was too much movement so I had to fix the items. The Arduino boards have nicely laid holes for that purpose; unfortunately the back of the board is not flat so I was scared of damaging it with too much of bolt tightening. . . until I found an old socket (yes, one of those cloth pieces that people use in pairs for their feet) and used it as a cushion. For the breadboards . . . I just reused some aluminum strips cleverly bent and covered. Sure, I still had to add some plastid strips.
Step 6: THE SHIFT TO THE PROTOTYPING BOARD
By thins time I had discovered the Arduino mini-Pro, and I also decided to shift from Mega to mini.
I have read of problems in the communication of the mini Pro, but I have not had any difficulty, not even requiring resetting for downloading the sketches: they move down my USB cable straightforwardly.
Unfortunately, the change from the Mega to the mini-Pro didn’t clear enough the array of floating cables from the chassis to the second deck . . .
I took my inability to make things look nice (too many cables around, too little space for my large fingers) as a fault in the hardware, so I decided that instead of using a breadboard where all the cables were messing around I would use a prototyping board where things would be nicely set. The machine would also look like much less amateurish. Then, though I had soldered less than 2 dozens points in all my life, I looked at a video on how to do prototyping and . . . I ordered, again from China, a set of prototyping boards (thanks God that I didn’t decide to go etching . . .). I had also read that planning is worthy, so I downloaded a format for prototyping, filled it with colored lines and started working: hands on!
In my first prototype I placed the L293D under the mini-Pro, just to see that I wasn’t able to weld anything because the space was too tight. I half burnt one of the header supporting the mini while trying to solder one leg of the capacitor to the L293 – and, of course, I decided that my soldering iron was not good enough, and that I required a thinner one, better suited for my precision works. I came back from the shop with a new soldering pencil, branded, same size, same thickness . . . but four times the price.
Step 7: THE DISCOVERY OF PLASTINSHIT
Soldering brought me into discovering a new material which I call plastinshit. Plastinshit is the melted blend of soldering tin and plastic (either from the cables isolation or from the PCB). Besides its venomous fumes, it shares properties with semiconductors (you can never be sure whether it will conduct electricity or not) and magnetic poles (you can also never be sure whether the balls of this material will join or will repel).
Plastinshit also has one amazing property: terrestrial gravity affects it, so when it is molten it tends to fall through the openings of the PCB, creating large balls of plastingshit on the other face of the PCB. This is how I decided that I needed to go to the International Space Station to continue my work – Earth was too small for me . . .
Plastinshit and my poor cable planning made my first prototype PCB quickly end in the bin.
I shifted then to planning the cabling in Fritzing. Things have improved but I have also discovered some of Fritzing’s limitations (amazingly, my mini-Pro element in Fritzing does not match the 1/10” pin spacing of the board, my version does not create symmetries and therefore modelling the back of the PCB is not automatic, the creation of new elements is not at all obvious, rendering is slow, . . .).
I managed to complete the prototyping of the motor controller PCB with no major issues. Well, I mean that I only had to do: a lot of continuity testing, remove one extra cable which I had added seemingly in dreams, I included an LED protecting-resistor of 100 kΩ (while, of course, it should had been just some 100 ohm; I couldn’t remove it, so I added the new one in parallel), and my abilities to link two adjacent board holes with one sole drop of tin (sorry, plastinshit) are still quite inconsistent. Oh, and the diameter of the drill of my PCBs is smaller than the bolts I have. . .
But all in all, I have done a reasonably clean prototyping PCB which works!
Step 8: THE RC CONTROLLER
I had done some control testing of the vehicle with infrared signals, and it was working great, but . . . I swapped VCC and GND in one test and I burnt the only receiver that I had at the time. . . I then ordered a new batch and I had to shift to RC because I could not wait until receiving the new infrared hardware!
I am using a 433 MHz emitter and receiver bought from here: http://www.dhgate.com/product/2pcs-lot-433mhz-wir...
For the communication I use VirtualWire library, which is simple and good enough for my purposes. I have read somewhere that this library is now superseded by RadioHead (http://www.airspayce.com/mikem/arduino/RadioHead/) but I have not checked for the changes.
Unlike with the infrared, with its nice off the shelf device, for the RC I had to create my own controller. . . I used a 4*4 membrane pad connected to another mini-Pro small breadboard fed from a USB power adaptor. The pins of the pad are very short, so it’s moving out every time. . .
And no, for the part of the emitter I’m not using a prototype PCB . . .
Step 9: THE CODE
And if you were not interested in the building details but in the results, here is the code, which is working for me.
I include here three sketches: one for the RC emitter, another for the RC receiver, and the last one for the 2WD with the receiver integrated.
I had some problems integrating the RC receiver sketch with the motor control. Both parts worked fine separately, but they didn’t when combined in one single sketch. I read that VirtualWire uses some interrupts (Timer1) which interfere with (some of) the PWM, and this seems to be the reason for the problem. I made some trial-and-error tests, and I managed to find a configuration of pins that was both controlling the L293D and receiving the RC signal.
There is nothing special with the code, I guess. Regarding the hardware I added LEDs on the emitter and receiver to have an indication of the communication; on the 4*4 control pad, only 7 keys are operational (2 – ahead; 8 – back; 4 – left; 6 – right; 0 – stop; A – accelerate; D – decelerate).
I wrote a small document with the Kinematic Equations of a 3DOF 2WD veihicle which can be found here:
Step 10: REFERENCES
The sketches include due record of the software parts used from elsewhere.
The pictures are mine, or from the webpages mentioned in the text.
Distributed under Creative Commons License: CC BY.