This is a tutorial on how to make a basic wall-avoiding robot. This project will require a few components and a bit of dedication and time. It would help if you have a small amount of knowledge on electronics but if you are a complete beginner, now is the time to learn! This is just how i learnt electronics; by making other peoples projects even though i had no idea how they were working at all. Gradually though i learnt small pieces that built up into actual knowledge i can apply to my own projects.
After you have completed this tutorial you will have assembled the circuit above and will (hopefully) have picked up some information on electronics. This may look daunting at first but breaking it up into easy to do steps makes it easily doable. Have fun!
Step 1: Components
To begin, you need to gather all the components. To make this project more beginner-friendly, the motors and chassis come together in a kit but of course you can make your own chassis or buy your own motors. Just make sure that they are the correct RPM and power.
Here is the component list:
Arduino Uno (Other models like Mega will work too)
Chassis and Motors (You can try to use the 6V battery pack that comes with this but ive found the 9V works better) - (This is the one i used - https://www.amazon.co.uk/gp/product/B00GLO5SMY/ref...)
L293D Driver (Always good to get 2 in case one breaks)
HC-SR04 Ultrasonic Distance Sensor
SPDT Switch (Like this one - https://thepihut.com/products/adafruit-breadboard-...)
9V Battery (I advise getting a rechargeable one if you intend to use this robot a lot)
9V Battery Connector
Jumper Wires (Male to Male)
Jumper Wires (Male to Female)
I did not have enough colours of wire to replicate my circuit diagram so i had to use the same colour for some things.
Step 2: Assembling the Chassis
The chassis kit i bought had some rubbish instructions but i still managed to put it together. If you buy the same kit as me, try using these images to help. If you dont, then your kit should have clearer instructions. Either way im sure you can do this part without a guide!
Step 3: The Breadboard
The second step is to familiarize yourself with a breadboard if you dont know how one works already. As shown in the image above, the rows in the middle and columns down the sides are connected together. However, the gap in the middle seperates the 2 rows apart. For example, A1 to E1 are connected but they are not connected to F1 to J1. So if we put a signal into hole C1 we could get the same signal at A1, B1, D1 or E1 but not F1 to J1.
The gap is also very useful as it allows us to put components across this gap while not connecting their own pins to themselves as we will see later on.
The columns down the side are commonly used as power rails and that is how we will use them. Refer to the images with the green circles if this is still confusing. All holes with the green circles around are connected together in each respective image.
This may be very easy or very hard to understand right now but you will definitely begin to see how they work by making connections and thats the whole point of this project; to learn by doing.
Step 4: Connecting the Power
Okay. The first step. Before reading the explanation of this part, try to figure out what rows and columns are connected to what.
The most important component is the arduino board. This is the brain of the entire project. Of course we must supply it with power. Using the pin marked Vin, we can connect it to row 29. This will make it easier to do other steps later.
Try to use color coded wires for specific uses for example, 5V is always red wire and GND is always black. This makes it much easier to see problems in wiring (and it also looks quite nice).
The next thing to do is to connect the pins marked 5V to the + rail and the pin marked GND to the - rail. This means the entire length of the rail has been powered and is far easier to access further up the board.
GND is another name for 0V. We can think of electricity like a stream of water flowing downhill. It goes from the higher point of energy (5V) through a path down the hill (the component we want to power) and into the sea (0V) at which point is has no energy.
We will also link the GND rail to the other - rail on the other side of the board for later. We need to connect the battery - terminal to the GND rail as well to ensure it is at 0V.
Step 5: Adding the L293D Chip
Remember how i said the gap in the middle was very useful? Well now we need it to add the L293D driver.
It is crucial you orient the chip so the small half-moon shape is facing towards row 1. Otherwise we may end up connecting power to incorrect parts of the chip that may damage it. Place the legs of the chip across the gap as shown so the chip is in the center of the breadboard. See how this makes sure the legs on each side are not connected?
Connect the wires as shown. The pins' uses are shown in the pinout image. This helps you check you have connected the GND pins to the GND rail. We need to supply 5V to the Enable1,2 pin, the Enable3,4 pin and also Vcc1. This just means the whole chip is activated as the Enable pins activate the input and outpt pins on their respective side while the Vcc pin supplies 5V to the chips internals.
Before moving on to the next step, double check all your wiring. Trust me, it will be so much harder to fix if you leave it and have a problem later.
Step 6: PWM Pins
Again try to use a different color of wire for this step. Referring back to the pinout of the chip, connect the wires. You must use the correct pins on the arduino in this step as they are specifically made to provide a PWM output signal.
Pin 6 ---> Input 1
Pin 5 ---> Input 2
Pin 10 ---> Input 3
Pin 9 ---> Input 4
A PWM signal is a clever way of adjusting motor speed without changing the input power. It works by turning the motor on and off at set intervals. The longer you leave it on per interval, the faster it runs. The ratio between it being at 0V and 5V is called duty cycle.
Its just like pressing the accelerator on a car. Imagine when the signal is at 0V, you dont have your foot on it but when it is at 5V you do. In the 25% duty cycle, you would accelerate for a short time and release for a long time. But in the 75% duty cycle, you would accelerate for a long time and then release for a short time.
At this point the wiring is getting hard to understand. This is why it is important to use colored wires for different purposes. And again, double check your wires once done.
Step 7: Adding a Power Switch
To stop your robot driving off as soon as you connect the battery, we need to attach a switch. This specific type of switch is named an SPDT but we are not using the 3rd pin. This makes it more like an SPST which is the simplest type of switch - 1 pathway and 2 states, on or off. Youve probably seen the circuit symbol for it already as shown in the above image.
So all we need to do is make the power from the battery run through this switch before it reaches anywhere else. Connect the + terminal of the 9V battery to one terminal of the switch and then connect another wire to the Vcc 2 pin of the driver chip. This is the power source the motors will be using.
We cannot use the arduino 5V pin as a power source for the motors as the voltage and current is too low to reach their demands. Motors are rather consuming of current and this is why we need a higher voltage battery (9V) that can supply more current.
You can think of Voltage as the pressure that pushes water out of a tap and the current as the amount of water that comes out. Without enough pressure in the tap (voltage in the power source), you cannot have a high amount of water coming out the tap (current running through the component).
Once your switch is connected, you should be able to power up and power down your arduino.
Step 8: Adding the Ultrasonic Sensor
We must now wire the ultrasonic sensor. Using Male to Female wires, connect Vcc to the 5V rail. GND goes to the GND rail. The TRIG pin goes to pin 3 on the arduino and the ECHO pin goes to pin 4.
The way this sensor works is by sending out a signal using ultrasound and timing how long it takes to come back. A greater distance means a greater time. The arduino can then process this to tell the motors what to do.
I highly recommened you turn the circuit on for about a minute and then touch the L293D chip to feel if it is hot. If the chip gets hot, it means there is a short in the circuit. Simply put, a short is when 2 things that shouldnt be connected, actually are. I accidently connected 2 wires and made this mistake myself. Testing it like this will prevent you from damaging the chip by leaving it on for too long
You have now very nearly completely assembled the circuit.
Step 9: Attaching Circuit to Chassis
Refer back to the pinout for this step. The wires from the motors must be attached accordingly:
Left motor - (black) ---> Output 1
Left motor + (red) ---> Output 2
Right motor - (black) ---> Output 4
Right motor + (red) ---> Output 3
To attach the parts to the chassis, i simply used small amounts of bluetack but you can obviously use better methods than this if you want it to be more permanent. Just make sure the method you use does not short anything, paticularly underneath the arduino. The 'eyes' of the sensor must be level and forward facing. Once you place everyhting on, recheck the wiring to ensure nothing has come out.
You've now done all the wiring and assembling! Nice Job! Only one more step now...
Step 10: Uploading the Code to the Arduino
I will not cover how the code works in this tutorial but if people wish to know, leave a comment asking and i will make an explanation.
Before uploading, make sure your arduino is off. To upload the code to the arduino, you will need to:
1) Plug in your arduino via the arduino cable to a computers usb
2) Download the Arduino software found here: https://www.arduino.cc/en/Main/Software
3) Launch the software and go to 'Tools'
4) For the Board, select 'Arduino/Genuino Uno'
5) For Port, select the option which says '(Arduino/Genuino Uno)'
6) Paste this code into the software - https://pastebin.com/raw/11kFAL6b
7) Click the upload button (the arrow in the top left)
Hopefully the code will upload without a problem. If you cant find the Port, try another usb port. Some arduinos have trouble with USB 3.0 ports.
You can change the speed of the wheels by changing the speed value at the top of the code. You can make it anywhere between 0 (no movement) and 255 (max speed).
Step 11: Testing It!
Congrats! Youve now finished the project!
Try turning powering up the circuit now. The wheels should both turn together if the sensor is not looking at anything close by. Move your hand in front of the sensor to see how the wheels react. One of them should begin to turn in the opposite direction. And when you move your hand away, they will both spin together again. I attached a small video of my robot navigating away from walls.
Ensure your battery is well charged as a low battery can cause a poor supply to the arduino and chip that will cause components to stop working properly.
Thanks for building this project! I tried my best to explain as much as i could in simple terms. If you have any questions or need help, please comment and i will try to help.
Also i HIGHLY recommend playing around with the online program Tinkercad. I did not know about this until i found this project but i really wish i did. I used it to simulate my design of this very circuit without needing to buy the parts first. It is ideal for newcomers to electronics for this reason.
This project was made to submit to the Electronics Tips and Tricks challenge. It would be awesome if you could vote for my project!