How to make Robot Wall Racers
UPDATE: Code now attached above + Ant has send me some tiny relays, I think they would work in this, and you could make everything 1/4 the size of what I did. Ask him from where he got them if interested :)
Here is a link to the first / original Robot Wall Racers - and the walkthrough on this page shows how to make something like them.
I will keep it open, so you will be able to add plenty more yourself, or make your own version :)
As always, I recomend you to start with the the "Start here"-project, if this is your first robot!
I made this with Picaxe, but it is all simple, and the code is well documented, so any Microprocesser should do - please read more below, in the shopping-list.
I presume that you want to make 2 cars. Of course you can just get half of everything if not.
However, I recomend to take the full step (get 2), because one racer is really not that much fun, and you will not get to make number 2 if you finish just one first. (I just know that!)
2 (cheap) RC-cars
I found these for USD40 for the pack containing 2, in my local Toys R us.
I actually bought 2 packs because I am an adult, and so I can decide what the money should be spend on. And also because it is fun to join in and race them.. or play chicken / try to hit frontal (It is quite hard). And if I fry a motor or a gear, I have spares!
Any RC car will do. Important thing however (to be able to follow this - of course you can break out and make something else) - is that it is controlled by 2 motors; One to drive the rear axle, and one to steer the front wheels.
Front wheels can also be the kind controlled by a coil / magnets - as long as it is steering when a current is on / steering the other direction when it is reversed. No servos, or you will have to think.
How you are going to find out if it is suitable BEFORE you buy it is your own job :D But.. most cheap cars will do, you can rest assured, if it is cheap, it will do. I should think.
8 Relays (The DPDT-kind)
Sure - you can hook this up with a motor-driver etc. But they are so complicated, and some reduce the voltage that is passed on to the motors.. We want the power from the batteries to be fed straight into the motors! This is race! (Which is also why we are going to take off all stupid resistors etc on the motors.)
If your car from the factory is driving on 4 batteries, a typical 5V relay will do.
However - if your car (like mine from the factory) only uses 3 batteries, and you (like me) use rechargeables, you will either have to find relays that will work on the power you feed them with, or do as I: Add an extra battery. (Even more power, this IS race)
More on the batteries later.
2 Picaxe .. something. I strongly recomend the 28 board, and a picaxe 28-something to match.
You do not need a motor driver or anything else - in fact all you need is in the starter-pack that I link to here - but note that you only need to buy 1 starter-pack, and then add up with one board and one picaxe chip extra.
Any Picaxe that can handle 6 outputs and 2 inputs will do! But I recomend the 28-pack, this way you will be able to expand and add more fun like blinking lights or a siren or more sensors, RC etc..
You can also use any other Microcontroller - the code I have made is very simple, amost pseuto-code, and should be easy to port.
4 SRF05 - or other distance sensors. I am using SRF05, and recomend them for this project.
1 Perfboard is a handy thing to keep the relays together.
Tools and extras:
A glue gun, some soldering equipment, screwdrivers, a cutter, some cable, some tape (more about that later)
If you get 5V relays, and your cars only has room for 3 DD cells, you should also get a battery clip that can hold 2 batteries extra (See bottom of instructions)
If your car is runiining more than 5V, you should also get a 5V voltage regulator.
Lets start building!
First thing you should do is take this lesson.
Note that all pictures and more can be found in higher resolution here.
I will show you how to make one car - same procedure on the other :)
First open your RC-car, it will look something like this:
Take out every electronic component that is not motor and switch
We want the thing to be completely stripped, and have wires to everything in a nice central spot.
These are the cables that should be ready at hand:
- 2 to the motor or coil to the steering mechanism in front
- 2 to the driving motor in back
- one from the battery, and one from the on/off-switch, giving 2 from "the power supply".
Next thing is to hook up the relays, so they can feed power to and from these cables.
This paragraph is a little theory, you do not need to read it. I personally would just jump to the next :D
You should have 4 relays for each car.
For your overview, they are to be used like this:
- steer left / right
- turn steering on off
- drive backwards / forwards
- turn "driving" on / off
- has a name in the code
- is controlled by an output on your microcontroller (Picaxe, possibly)
This table shows, for reference (we will get more into details below) what is hooked up to what in my setup:
Name in code
Connected to output
Off = car drives straight ahead
On / Off = Turn Left / right (if 7 is on)
On = Car stops
On = car reverses (if 5 is off)
So, you will be using relay 6 & 4 to revert current (We call them "Cross relays"), and 7 & 5 to feed them (or not feed them - We call them "Feed relays") - with current to revert or go straight.
Perhaps when done, your car is turning left when it should turn right - we will just fix that in the code.
Back to building..
First, if you have a large perfboard, place the relays next to each other, and draw around them. Somehow cut out the place they use (make sure you get holes around to every pin on the relays) - see picture below!
Here is a schematic of a relay that you may want to print out, as It will be referred to below all the time:
From now on I will refer to the pins as "R16" for the buttom left, "R8" for top right etc.
It works like this:
If power is on from the Microcontroller (Picaxe) on R1 & R16, then R13 & R9 are conected. No power, and R13 and R1 are connected.
So.. you feed R13, and voltage goes to R1, and then you let your Microcontroller "turn it on" by adding power to R1 & R16 - and then power from R13 goes to R9.
R4, R6 & R8 works the same way.
To keep power on R1 & R16 does take a little from your battery, but it is not much. How much is depending on your relay. However - we will design this, so that most common action (driving ahead) is what is happening when no power is on the relays Coil (R1 & R16).
Solder cross with wires on 2 relays as shown on the picture (R6 to R9 & R1 to R8). These 2 relays are the ones used to revert current (steerto & forrev in the code). From now on we will call them "Cross relays", and the other 2 "Feed relays", as the other 2 will feed them with current.
Also go ahead and solder a pin here and there to hold everything in place :)
Now it is a good idea to see how you can fit both your (Picaxe) board and the relays in the car. Reason: You want to make all wires as short as reasonable possible from now on (to save space) - but you do not want to make too short wires ;)
Of course make sure that no bare soldering points / stripped cables can touch each other. Perhaps find some piece of plastic from an old dishwasher-thingey or similar to isolate the parts safely.
Also by now consider that you are going to mount 2 SRF05's that are going to have cables in there. They must have room as well.
And consider how you are going to get to the upload cable from outside (you do not want to unscwrewthe car each time you want to alter a little something in the program, trust me :)
There are 2 ways; Either make connections, and solder a female jack on the outside, or simply drill / melt a hole:
Now connect every relay's R1 to V, and also connect the (Picaxe) board to this (see here for more info)
Connect G to the Picaxe board as well, through the car's on / off switch. (Or let the V go through that, just one from batteries has to pass through on / off switch before going anywhere else.)
Now we will connect your motor to a relay, one of the "cross relays". What we want, is to connect it so that when the none of the relays are powered, the motor makes your car drive forward.
That way, the board will just have to "relax", for the car to drive forward; Power will go straight from batteries to motor. We like that, since this is a race car :)
My motor is powered by the 2 blue wires comming from below in the picture. It should be connected like this. However - you may want to do it yourself later: Because in a moment, when we add power, if your motor is taking your car backwards, these 2 cables should be the other way around!
Connect the steering (front motor or coil) to the other "cross-servo", the same way. (not done on the picture above for simplicity)
Now we need to let the 2 feed relays feed the 2 cross-relays with power.
Look at the picture below. Note the 2 large blobs of solder on the feed relays. Make them :)
They connect R1 to R4 on these. So now R4 on the feeding relays has.. V, yes! :)
And since the feeding relay is not powered (no voltage between R1 and R16 on them), then R6 on feeding relay now also has V.
We now will look at the 2 relays in the left side of the picture below, and let them feed the motor to drive your car.
Connect R6 on the feed relay to the cross-relays R9.
Connect R8 on the cross relay to ground.
Now, if you insert batteries (and remember to turn on the car), your motor should take your car to drive forward.
If it drives backwards, switch the wires to the motor. If nothing happens, here is your check list, power should go this route to your motor:
V:(R1-R4) on feed relay -> R6 on feed relay -> R9 on cross relay -> R6 on cross relay -> One motor cable
G: R8 on cross relay -> R1 on cross relay -> Other motor cable
(2 pictures below are of the same, from different angles)
Now we need to do the same with the front motor / steering coil. Only; We do NOT want the car to turn if the Microcontroller does nothing. So this goes, on the 2 rightmost relays:
G to cross relay R8
Cross relay R9 a little blob of solder to feed relay R8
PHEW!! That was the worst part :D
Now all the relays has V on R1, and if the Microcontroller hooks up on any R16 we will turn relays on and off, making motors drive forward / reverse / stop / go..
Let the digital output of your microcontrollers output 7 go to the leftmost R16, then 6, 5, 4..
Hurray, you have made your own motor-controller!
Let us test it!
I assume you find out how to hook up your Picaxe (or other Microcontroller) to your programming editor on your computer.
Now - if you have entered no program in your Microcontroller, what should happen if you insert batteries, and turn it all on?
Microcontroller should get power, no turning to any side, motors driving your car forwards.
Try that, then turn off / insert this code in your Microcontroller:
Run the program, what happens?
Motor should stop. Why? It's feed relay should get power on R1 & R16, switching it off
- Motor should reverse; Cross relay is fed.
- Motor turns front wheel in one direction
high 4 high 5
- Front wheel turns in opposite direction
Your Microcontroller can now control the vehicle :)
Now let's mount the sensors on the car. How you do that is up to you, the design of your car, and weather you want to be able to re-use your sensors, or mount them permanent.
They should have a very good mounting, they will get lots of beating! Good thing you know how to use a hot glue gun!
However you do it, make sure one is free to scan/ping/look ahead in front, and one to the RIGHT side.
Now, let us hook them SRF05's up :) Please see here for more info.
Outs from your Picaxe to Trigger input on SRF05: You want to use output 0 and 1 for the right and front sensor. (0 to front) This can of course also be altered in the code, but if you follow excectly, you should be able to close the thing in the end of the day, turn it on, and off it goes :)
Hook outs from the SRF05's to input 6 & 7 - Right sensor to 7.
V & G to both sensors.
.. Ok, now check again that all cables to the sensors are right! (Things are reversed and stuff! - I admid, I was making a mess and had to re-wire, but luckily nothing was burnt!)
Now.. if your cars only has 3 DD cells, and you use rechargeables, and you are using 5V relays, and you want this thing to act tuned (all things I could say "Yes" to) - you will have to make room for an extra battery somehow, somewhere.
Upgrade from 3 batteries to 4. If you could say "yes" to all the above, but think "I can wait, it seams to be working OK, you are wasting time on something I already wasted time on for you; The relays are not operating how they should EACH time!
So you get strange behavior!
I could only find a clip with for 2 batteries, and I did not want to have 5 DD-cells in it (That would possibly fry something too fast) - so I stuck some metal in, instead of one of the batteries in the original battery cell holder - and added the clip for 2 on the outside of the car:
- And now we are at it; Look at the rear wheel on the picture above; It has black tape on it!
You will have to experiment; One kind of tape made my car really stupid to program / drive; It was just wheelin all the time. No tape, and it was really hard to get good skidding / slide turns, and it looked boring. What ever you do, you will just have to ajust in the code / driving style to fit the grip that you have.
Stay sharp, drive fast, and stay close to the wall :)