Raspberry Pi based wall avoiding robot – FabLab NerveCentre

Please note: This instructable is not complete – but may be helpful

Published to allow the excellent people at Derry's NerveCentre to take the code out to schools

I hope to get back to this but my current job is keeping me from it for now.

This instructable is an alternative to my other wall avoiding robot found here:

http://www.instructables.com/id/Arduino-wall-avoid…

The intention is to offer an alternative platform and coding in order to achieve the same result.

For this project we use the Raspberry Pi and the familiar L293D dual h-bridge chip. The ultrasonic sensor is the widely used HC-SR04.

The coding is done in Python, which I find to be considerably easier to interpret for those who haven't done a lot of coding.

Enjoy the project and please give any feedback you can so that any necessary improvements can be made.Raspberry Pi based wall avoiding robot - FabLab NerveCentre

Step 1: What you need

A Raspberry Pi – I've used a B+ but any RPi will work with some edits to pin numbers used to drive each motor.

A motor driver – I've used the L293D PCB kit from here: http://www.rkeducation.co.uk/L293D-Project-PCB.php… – Due to a job change, I am unlikely to be able to answer questions on alternatives so I hope the information later on will be enough.

2 X right angle geared DC motors & wheels – you can use any DC motors for this.

A HC-SR04 ultrasonic sensor – very widely used and available for RPi & Arduino projects.

A 9V battery and battery snap – this is to run the motors.

A 5V battery – I've used an Anker battery to run the RPi.

Wiring – a selection of female-female and female-male wires.

Resistors – just 2 are needed to create a voltage divider. I have used a 100Ohm and a 220 Ohm pairing. See details below about creating a voltage divider – ultimately though one resistor needs to be as close to twice the resistance of the other.

A small breadboard – you could do without this if you use insulating tape or something instead.

Step 2: Let's look at using the Pi to get a reading from the Ultrasonic Sensor

I learned how to do this through the tutorial on ModMyPi.com which is available here:

https://www.modmypi.com/blog/hc-sr04-ultrasonic-ra…

Attached is a schematic which shows how to apply the voltage divider.

Briefly, this is used to drop the voltage on the signal back from the ECHO pin on the sensor. 5V leaves the pin and goes through a resistor which creates a voltage drop. At this point, there is a split – one branch goes to GND through a resistor which takes away twice as much voltage – the other branch has only gone through one of these resistors and so only reduces the voltage to 3.3V.

The Pi needs this signal to be reduced to 3.3V otherwise the US sensor will work but will return spurious readings. Thus the need for the voltage divider.

You can refer to the attached link if you need to breadboard this. I have attached (later) some manufacturing files for producing a small voltage divider if you have the capabilities for it.

To test the ultrasonic sensor you can use the attached code (if not working from my image available on Github). To do this, simply download the file and in LXTerminal on the RPi navigate to the folder where you have downloaded the file. Then type β€œsudo python FILENAME.py”.

Step 3: Now let's look at getting some motors to drive

Now we can hook up some motors.

Everything can be connected as per the image. I find it very helpful to try to avoid repeating any colours so that you can easily see where each connects.

In the code attached (which demonstrates motor movement) you will notice that I have used a naming standard for the 3 pins which link the RPi to the motor driver. For example:

Motor1A = 36 – this indicates a pin to connect IP1 or IP2 to.

Motor1B = 38 – this indicates a pin to connect IP1 or IP2 to.

Motor1E = 40 – this indicates a pin to connect EN1 to.

The same is true for the β€œMotor2*” series:

Motor1A = 33 – this indicates a pin to connect IP3 or IP4 to.

Motor1B = 35 – this indicates a pin to connect IP3 or IP4 to.

Motor1E = 37 – this indicates a pin to connect EN2 to.

Once these are connected, we need to connect each motor terminal up also. Connect one motor to MA and the other to MB – which wire goes into each side for the motors is quite arbitrary as no damage will be done.

Again, you can download the file attached and run the python code as per previous instructions.Raspberry Pi based wall avoiding robot - FabLab NerveCentre schematic

Step 4: Getting it all running together

At this point, you probably have a mess of wiring something like the picture attached!

Other than building a chassis, you're all set to get the whole thing working together.

Attached is a python script (which is again run as per previous instructions) that will make a distance measurement using the ultrasonic sensor every 0.5 of a second. If this measurement falls below 10cm one of the wheels reverses. When mounted all together on a chassis, this will mean the robot will drive around and turn if it senses anything close by.

 

For more detail: Raspberry Pi based wall avoiding robot – FabLab NerveCentre


About The Author

Ibrar Ayyub

I am an experienced technical writer holding a Master's degree in computer science from BZU Multan, Pakistan University. With a background spanning various industries, particularly in home automation and engineering, I have honed my skills in crafting clear and concise content. Proficient in leveraging infographics and diagrams, I strive to simplify complex concepts for readers. My strength lies in thorough research and presenting information in a structured and logical format.

Follow Us:
LinkedinTwitter

Leave a Comment

Your email address will not be published. Required fields are marked *

Scroll to Top