Wall Dodging Robot
Summary
This clever robot is the perfect way to get started with robotics. The robot exploresits surroundings as it avoids obstacles and walls in its path. Starting with theprovided code, the robot can easily be expanded upon.
This is the updated version! codename Mini-Tesla - it now has a rechargeable Li-ion battery with an On-Off switch. It also now has a light sensor so it can turn off (or reverse) when it gets into dark places such as under beds or tables, and we use the motor shield to save space on the platform.
There's a lot more that this little robot can do, check out the Exploration section for more ideas once you have finished off the build.
Materials Required
1 | Duinotech UNO r3 Main Board | XC4410 |
1 | ||
1 | 2 Wheel Drive Motor Chassis Robotics Kit | KR3160 |
1 | 2600mAh Metallic Power Bank Space Grey | MB3793 |
1 | Duinotech Arduino Compatible Motor Servo Controller Module | XC4472 |
1 | USB Plug - Type A - Solder type | PP0790 |
1 | Micro USB extension Cable 100mm Pair | WC7756 |
1 | SPDT Sub-Miniature Toggle Switch - Solder Tag | ST0300 |
1 | Duinotech Arduino Compatible Photosensitive LDR Sensor Module | XC4446 |
1 | 28 Pin Header Terminal Strip | HM3211 |
1 | 150mm Socket to Socket Jumper Leads - 40 Piece | WC6026 |
The motor controller (
) fits directly on-top of the uno so you don't have to worry about the pinout of the motor connections. The LDR and ultrasonic sensor (
 andÂ
) connect into the analogue pins on the motor shield, which don't have headers, but we can just solder them in with theÂ
 vertical headers.
UNO (shield) | Device |
---|---|
A5 | LDR Sensor pin |
A4 | Ultrasonic TRIG |
A3 | Ultrasonic ECHO |
Be sure to connect all of the 5V to the 5V pins, and the GND to GND pins.
![](https://images.contentstack.io/v3/assets/blt7eae2e8ef79b5522/blt2ce3bc16451369f5/65a76ba49b1ffed71fe0d522/system_(6).png?branch=prod)
The overall robotic platform is pretty easy to understand. we are using a battery to power the entire system by jacking into the motor controller. This means we have the most amount of current (which with lithium ion - could be a lot!) goes to the motors when we want it to. The LDR and ultrasonic sensor plug into the motor shield but they actually just get passed and controlled by the UNO underneath.
We've broken the assembly instructions into different sections so you can jump around if you need to:
Firstly, we'll assemble the USB connector. Looking at what's in the pack you should have 4 pieces as shown below.
![](https://images.contentstack.io/v3/assets/blt7eae2e8ef79b5522/bltefb1723a02302bd0/65a76c1ac7bb165068a2869f/connector.jpg?branch=prod)
USB is a common standard so we would do best to follow the standard by looking at what the pin out for a USB connector is, we are focused on "USB A" on the cable side, you can google for this easily:
![](https://images.contentstack.io/v3/assets/blt7eae2e8ef79b5522/bltea7e3fb7814892f5/65a76c3e6e0746a06cfb97d1/usb.png?branch=prod)
Flip over the connector, so that the solder tags are facing you, (they have a 'u' shape) and you'll find that the leftmost connector (labelled 4 in the diagram above) is the ground connection. Strip a length of wire (either fromÂ
 or whatever you've got) and twist the wires so they all remain together. Then fill the 'u' shaped channel on the connector with a bit of solder.
![](https://images.contentstack.io/v3/assets/blt7eae2e8ef79b5522/bltc4541791b4055817/65a76c5d2b0bb74a8a33b60b/solder_(2).jpg?branch=prod)
Then, you'll be able to easily place the wire on top of the solder, and heat it through so that it gets absorbed by the melted solder. You can then put some fresh solder over the top so that it's secure in place and completely covered by solder.
![](https://images.contentstack.io/v3/assets/blt7eae2e8ef79b5522/blt44f2c5c1fb5f07cf/65a76c85df87337433cda577/place.jpg?branch=prod)
As long as it's secure and there's no stray wires it should be ok. Continue to do the positive side, which is the opposite end of the connector. Here we used an orange colour to signify that it is not ground. It's important not to get the polarity wrong, so some sort of colour scheming should do good.
![](https://images.contentstack.io/v3/assets/blt7eae2e8ef79b5522/bltb9152497cb0a6b25/65a76cb8b5610401698c2365/polarity.jpg?branch=prod)
Then you can clip the small white cover on top, then place it into the large metal connector.
![](https://images.contentstack.io/v3/assets/blt7eae2e8ef79b5522/blt165eaadee51242dd/65a76ce757316142cfcc6cf0/cover.jpg?branch=prod)
You should find that it only goes one way, and it must be flush on the USB connector side, as shown below.
![](https://images.contentstack.io/v3/assets/blt7eae2e8ef79b5522/blte1ac1f6e64ac4522/65a76d2aa0613ddb5c52978b/casing.jpg?branch=prod)
Then you can place the other metal casing over it; This metal part "hooks" into it, as shown on the above picture, then it can swing close and become a bit tidy, enclosing everything in the metal housing.
![](https://images.contentstack.io/v3/assets/blt7eae2e8ef79b5522/bltbd3334afd769f964/65a76d566e0746b496fb97da/close.jpg?branch=prod)
Once it's all together, and snug, you can gently plug it in and test polarity with a multimeter if you want. It's crucial to get the polarity right; while this battery set up has plenty of protection to keep everything safe, not every battery does.
Once it's good, use a pair of pliers to gently wrap up the cable clamps to make it strong and sturdy.
![](https://images.contentstack.io/v3/assets/blt7eae2e8ef79b5522/blt5864fc2102c824e9/65a76d832b0bb7c25933b613/wrap.jpg?branch=prod)
Then you've finished the USB connector, this will be used to plug into the rechargeable battery later.
![](https://images.contentstack.io/v3/assets/blt7eae2e8ef79b5522/bltca584447ca604364/65a76dbb7a1dd7462ee133f1/finished.jpg?branch=prod)
In the Robot Chassis kit (
) you should find some metal pieces and some long screws, along with the motor gearboxes. Bolt through the motor gearboxes onto the metal mounts as shown below.
![](https://images.contentstack.io/v3/assets/blt7eae2e8ef79b5522/blt0286da433ed8adbd/65a76de2c992b7ef81b89ce8/attaching-mount.png?branch=prod)
We'll do this to both sides, so that they are opposing, with the top screw-mounts on opposite sides:
![](https://images.contentstack.io/v3/assets/blt7eae2e8ef79b5522/bltf39a135320048913/65a76e25c1930f1aeef8a6b1/both-motors.jpg?branch=prod)
You'll find that there's only one real spot where the wheels will actually attach, and you can use the smaller screws to attach the motors to that point.
![](https://images.contentstack.io/v3/assets/blt7eae2e8ef79b5522/blt7b474391aa4162ad/65a76e57a933e552320261ed/position.jpg?branch=prod)
The trolley wheel goes near the flat end of the robotic platform, and you can use the broad-headed screws to mount the wheel to the small brass spacers in the kit, like such:
![](https://images.contentstack.io/v3/assets/blt7eae2e8ef79b5522/bltbbc8e38ca0b33c41/65a76f1702a6659a5992bd8e/mounting-wheel.jpg?branch=prod)
Then use the remaining small screws to mount the wheel assembly to the chassis. If you have some spare washers or nuts, you can space them out a bit so that they fit more securely as shown below, or just mount it straight onto the chassis. It shouldn't cause a problem.
![](https://images.contentstack.io/v3/assets/blt7eae2e8ef79b5522/bltb002f4a1548105cd/65a76f36b5610407d88c237d/wheel.jpg?branch=prod)
The motor controller has plenty of connectors on it, however not all of them have the header pins. You should see 3 rows of 6 solder pads near the analogue connections on the motor controller, this is where we will use some of theÂ
 pins to solder in.
Break off 3 lots of 4 pins. We are only using 4 as that's what we need, but you can break off longer segments if you want. Place one lot in through the top of the motor shield along the analogue connectors and flip the motor controller around so you can solder underneath as shown below.
![](https://images.contentstack.io/v3/assets/blt7eae2e8ef79b5522/bltabf6ae7df35d0eb7/65a76f5ab9be7b7f88c6095f/solder1.jpg?branch=prod)
It might be easier to start with the analogue connections first, then work your way away from the edge; here we've started on the GND row.
![](https://images.contentstack.io/v3/assets/blt7eae2e8ef79b5522/blt0eb30fd8ca5cd9c3/65a76f77d48d3d4a71cebf8d/solderheader.jpg?branch=prod)
Tack them in and be sure not to short any of the connections. The connectors are already done on the board, so we don't need to make any new connections here.
![](https://images.contentstack.io/v3/assets/blt7eae2e8ef79b5522/bltf78668a921e8f6f8/65a76f95c3bf067f6ffdead2/solder3.jpg?branch=prod)
Next up, we'll start positioning the components and building the on-off switch.
Cover the leads of the USB cable that you made previously, and connect both the USB cable and the USB extension into theÂ
 battery pack. Lay out the components under the robot platform as shown below:
![](https://images.contentstack.io/v3/assets/blt7eae2e8ef79b5522/blta469f3bff558c8bc/65a76fb4c7bb16453da286ae/positioning.jpg?branch=prod)
Here we've pushed the motor cables up and through the platform so they are on top, as well as put the USB extension under the 3rd wheel.
Use hot glue to mount the battery case and the USB extension lead in place, so that the battery pack is fairly centred and the usb lead is flush with the side of the robot, as shown below. Note where the switch will end up when we get to finally placing it.
![](https://images.contentstack.io/v3/assets/blt7eae2e8ef79b5522/bltf3f1f74b0da93c5d/65a76fdbdaaa5014149c76d4/switch.jpg?branch=prod)
Now you know the length of wire that you need, you can cut and strip a portion of wire so that you don't have too much wire between the battery and the switch, then solder to one of the side terminals on theÂ
 switch.
![](https://images.contentstack.io/v3/assets/blt7eae2e8ef79b5522/blta87ea3e75ac431bd/65a76ff8a0613d40905297a1/solder_(3).jpg?branch=prod)
Use some more black wire (signifying ground) to the middle terminal, and place the switch back in the hole near the 3d wheel. Use a spanner to tighten the top nut of the switch so that it is sitting firmly in place. You won't need the washers on the switch if they make it more difficult to attach.
Bring the new negative wire up through the same hole as the positive from the USB/battery bank. you should now have 6 wires coming to the top portion of the platform, 2 from each motor and the positive/negative from the USB cable in the battery bank.
![](https://images.contentstack.io/v3/assets/blt7eae2e8ef79b5522/bltfbd4f970d8b42a36/65a7701914eaceef73a5a407/upside.jpg?branch=prod)
Once the motor shield has been soldered and you're happy with it, you can place it on top of the UNO and mount the UNO to the robotic platform. We've found it nicer to mount the uno off to the side a little so that you can still program through the USB-B connector, so we use some double sided tape (
) or hot-glue to keep it in place.
![](https://images.contentstack.io/v3/assets/blt7eae2e8ef79b5522/blt9a833e912851666b/65a77042dbd0c382a9ad294a/connecting.jpg?branch=prod)
Connect the motors to the motor ports (M3 and M4) then connect the battery bank leads to the M+ and GND connections on the shield (remember polarity!). We've used bootlace crimps (
) to make the connections extra secure as the terminals have something extra to grab on-to, but you could also bend the bare wires back a bit and double up inside of the screw terminal. Trim the wires to size as well, so that there's not too much loose wire hanging around. The polarity of the motors don't really matter, as you can just reverse them in code.
Make sure that the "EXT_PWR" jumper is also connected so that the UNO feeds power off the motor controller power.
If you were powering this off a battery that has more than 12v, youÂ
need
 to disconnect this jumper, but this battery is 5v so it is fine.
Next is just the ultrasonic and LDR sensors, which can be placed wherever you wish. Connect the VCC and GND from each sensor to the 5V and GND on the motor shield, from the header connections that were soldered on previously, then connect the S, TRIG, and ECHO wires to the analogue pins.
![](https://images.contentstack.io/v3/assets/blt7eae2e8ef79b5522/bltf7ab4571dbcc9fb9/65a770677fc00024592232a6/top.jpg?branch=prod)
You can do any pin out, but our code sample has LDR on A5, TRIG on A4 and ECHO on A3.
We used hot-glue to fix the sensors in position.
Once everything is connected, you should be able to flick the switch to turn on the battery pack and find the motor controller and UNO lights up. Turn it off again to program. If you plug in a phone charger or otherwise to the side port, the battery bank should shine red to show that it is recharging.
The source code is in the robotCode folder, which you can modify and upload. Once you've uploaded you should see the robot start driving and turn around if it reaches a wall. It will also stop moving if you turn the lights off, or if it goes underneath a table or bed.
The arduino code has information showing in the serial monitor on 9600 baud. You can prop the motor up on a mug or box so that the wheels are off the ground, and see how it responds to moving your hand in front of the sensor, or covering the LDR with your fingers.
If the robot hits walls on an angle, it might not detect the wall properly, something similar to below:
![](https://images.contentstack.io/v3/assets/blt7eae2e8ef79b5522/bltf89f6953d8aa57ba/65a770aaa933e5f21e0261f6/reflect.png?branch=prod)
The only way to combat this is to use two ultrasonic sensors on different angles, so that one of them is going to be a little more perpendicular to the side wall. You can also look in the belowÂ
 section for some ideas, such as using a servo to move the sensor to face the wall.
This is really meant to be a starting platform for robotics, as you can now change the robot in any way that suits; some ideas are below:
Similar projects you may be interested in