COMPUTER SCIENCE CAFÉ
  • WORKBOOKS
  • BLOCKY GAMES
  • GCSE
    • CAMBRIDGE GCSE
  • IB
  • A LEVEL
  • LEARN TO CODE
  • ROBOTICS ENGINEERING
  • MORE
    • CLASS PROJECTS
    • Classroom Discussions
    • Useful Links
    • SUBSCRIBE
    • ABOUT US
    • CONTACT US
    • PRIVACY POLICY
  • WORKBOOKS
  • BLOCKY GAMES
  • GCSE
    • CAMBRIDGE GCSE
  • IB
  • A LEVEL
  • LEARN TO CODE
  • ROBOTICS ENGINEERING
  • MORE
    • CLASS PROJECTS
    • Classroom Discussions
    • Useful Links
    • SUBSCRIBE
    • ABOUT US
    • CONTACT US
    • PRIVACY POLICY
ROBITICS ENGINEERING | RASPBERRY PI BOAT
ON THIS PAGE
ABOUT THIS PROJECT
​SECTION 1 | COMPONENTS NEEDED
SECTION 2 | ABOUT THE RASPBERRY PI PIN OUTPUTS
SECTION 3 | WIRING THE DC MOTOR
SECTION 4 | CODE YOUR DC MOTORS
SECTION 5 | WIRE YOUR SERVO MOTOR
SECTION 6 | CODE YOUR SERVO MOTOR
SECTION 7 | MAKE BOTH SET OF CODE WORK TOGETHER
SECTION 8 | BUILD YOUR BOAT
SECTION 9 | REMOTE CONNECTION
SECTION 10 | EXTENDED TASK IDEAS
Picture
ABOUT THIS PROJECT
This project will build a boat connected to WIFI that you can control through a web-browser. When you add a camera to the car you will be able to sit at your computer and pilot the boat anywhere within range of WIFI.

BE VERY CAREFUL when working with electronics and MAKE SURE YOU HAVE AN IN-LINE FUSE directly from your power supply with a 2A or 3A fuse installed. Failure to do this could result in components to heat and even catch fire. REMEMBER - THIS IS NOT A TOY  - SAFETY FIRST 


OBJECTIVES
To build a boat that can be controlled from your computer, connect to wifi and be operated anywhere on the network whilst you sit at your computer and view the boats position from the on board camera. 

EXPECTED EXPREIENCE GAINED
  • Gain an understanding of electrical components such as: LEDs, Resistors, Jumper wires, Diodes, Relays, Motor shields, capacitors, breadboard, power supplies. 
  • Gain experience and develop techniques of using tools such as: Spanners, Ratchets, Soldering Iron, Screwdrivers, Cable Strippers, Cutters 
  • Gain knowledge and experience of using a multi meter to measure voltage and continuity. 
  • Gain practical experience of using the Raspberry pi including using the GPIOs, remote access networking, using the external camera port. 
  • Develop your programming skills using Python programming language to program keyboard – keypress control of your vehicle. 
  • This project should be fun and is expected to take a minimum of 12 hours to complete, however more time is recommended to deepen understanding of robotics engineering, electronics and programming. 
SECTION 1 | COMPONENTS NEEDED
RASPBERRY PI - For the control of the boat, the Pi needs wi-fi capability.
MOTOR SHIELDS - To power your motors and separate the circuit from the Raspberry Pi

POWER PACK - To power your motors and other components
IN-LINE FUSE - To protect yourself and your circuit from damage

POWER BANK - To power Raspberry Pi
WIRES - To connect components together
DC MOTORS,  SERVO MOTORS, PROPELLERS AND BASE - The boat structure
NUTS AND BOLTS - A selection of nuts and bolts to connect everything together
TOOLS REQUIRED
SCREWDRIVERS - Various size screwdrivers for the motor shield and build screws
SIDE CUTTERS - A small set of side cutters to cut and strip wires
SOLDERING IRON - A small soldering iron to solder wires

OTHER USEFUL TOOLS
WIRE STRIPPERS - To make it easy for you to strip wires
MULTI-METER - To test and problem shoot your circuit
COMPONENTS WE USED IN THIS EXAMPLE
The components we used in the project are fairly cheap and easily obtained. The components with image are listed below, all components can be found on Amazon, Lazada, Temu and AliExpress.
Picture
Picture
Picture
MOTOR SHIELDS
​We used LN298N motor shields from Amazon. You will need 1 of these. When you fit then on your car remember that you will need access to connect the cables to the blue terminals.
IN-LINE FUSE
To reduce the risk of damage, burning or possibly fire. Make sure you use a fuse and ensure the fuse is fitted close to the power supply. In this project we used a mini blade fuse and fuse holder. From Amazon.
POWER PACK
Two battery packs or equivalent could be used for this project. You can either wire the power in series or parallel (See Circuits). In this guidance we have wired in series. Remember to fit a fuse to prevent damage. You should be looking to supply between 5v - 10v. 
SECTION 2 | ABOUT THE RASPBERRY PI PIN OUTPUTS
The Raspberry Pi's General Purpose Input/Output (GPIO) pins, an essential component for many Raspberry Pi projects, including the one you're about to undertake!

What are GPIO Pins?
GPIO pins on a Raspberry Pi are physical points on the board that allow you to connect various electronic components like LEDs, sensors, and motors. These pins can be programmed to either send out a signal (output) or receive one (input), enabling your Raspberry Pi to interact with the outside world.

Two Ways to Number GPIO Pins: BCM vs Board
When working with GPIO pins, it's crucial to understand the two main systems used to refer to these pins: BCM (Broadcom SOC channel) and Board.
  • BCM Layout | This layout refers to the pin numbers by their Broadcom SOC channel number. For example, when you use BCM numbering, you're referring to the pins by their function as defined by the Broadcom chip at the heart of the Raspberry Pi.
  • Board Layout | This layout refers to the physical pin numbers on the header of the Raspberry Pi. For example, pin 1 is the pin in the top left corner of the header when the USB ports are facing down.

Why We Use the 'Board' Layout
In our project, we will be using the Board layout. This choice is made for its simplicity and intuitiveness, especially for those who are new to electronics and Raspberry Pi projects. With the Board layout, you can easily locate and identify the pins you need by counting their physical position on the board.

As you begin your project, remember to refer to the Raspberry Pi GPIO pinout diagram, which will be your guide in identifying the correct pins. Familiarise yourself with their physical locations according to the Board numbering system, as this will be crucial in successfully completing your project, the pin numbering as can be seen in the centre of the image below where the pins are numbered 1 - 40.
Picture
NOTE | When looking at the Raspberry Pi GPIO header, pin 1 is located at the corner nearest to the SD card slot, while pin 2 is directly opposite pin 1 on the other row. Conversely, pins 39 and 40 are found at the end of the GPIO header closest to the USB ports. It's important to orient yourself correctly with these pins, as this will ensure that you connect your components to the correct GPIOs
SECTION 3 | CONNECTING THE MOTOR SHIELD AND MOTOR FOR THE PROPELLER
To effectively connect and control the DC motor with our Raspberry Pi, we are utilizing the L298N motor shield. This motor shield is a crucial component as it enables the Raspberry Pi to control the rotation of the motor, such as a propeller, in a precise and efficient manner. Additionally, the L298N allows for the use of an external power supply. This is particularly important because it prevents excessive electrical load from being placed directly on the Raspberry Pi. By using an external power source, we ensure that the motor receives sufficient power without straining the Raspberry Pi’s own power limitations, thereby enhancing the overall safety and performance of our project.
Picture
Example wiring diagram
Stages to wire the LN298N motor shield to run the 5v DC motor for your propeller.

Connect the Power Supply to the Motor Shield
  • Connect the positive wire from your power supply to the 5V or 12V input on the motor shield. It's a good practice to use a red wire for this connection to indicate that it's a positive supply.
  • Connect the ground (negative) wire from your power supply to the GND terminal on the motor shield. It's standard to use a black wire for ground to avoid confusion.

Connect the Raspberry Pi to the Motor Shield for Control
  • Use a female-to-female jumper wire to connect GPIO pin 7 from your Raspberry Pi to one of the input terminals on the motor shield. Choose a wire colour that is neither black nor red (like blue, green, yellow, etc.) to signify that it's a control wire.
  • Use another female-to-female jumper wire to connect GPIO pin 11 from your Raspberry Pi to another input terminal on the motor shield. Again, use a non-black, non-red wire.

Connect the Motor Shield to the DC Motor
  • Connect the two output terminals from the motor shield to the DC motor. It's helpful to use wires that are the same colour as the input wires for easy identification.

Establish a Common Ground
  • Use a black male-to-female jumper wire to connect a ground pin from the Raspberry Pi (such as pin 6) to the GND terminal of the motor shield. This should be connected to the same terminal where the negative wire from your power supply is connected. This step is crucial as it establishes a common ground between the Raspberry Pi and the motor shield, which is necessary for proper operation.

Remember, it's important to ensure that all connections are secure and that the Raspberry Pi is powered off when making these connections to prevent any damage. Also, make sure that your power supply voltage matches the requirements of your motor and the L298N motor shield.
SECTION 4 | CODE YOUR DC MOTORS
Please feel free to copy the code from below: IMPORTANT: Please note that if you run this code and your configuration is different from that described above it is possible to damage your components, and it is possible for your project to catch fire. BE VERY CAREFUL when working with electronics and MAKE SURE YOU HAVE AN IN-LINE FUSE directly from your power supply with a 1A fuse installed.
​This script is used to control GPIO pins on a Raspberry Pi using keyboard inputs. It listens for 'w', 's', and 'x' key presses to control two GPIO pins, presumably to control a motor or similar device. The script uses Tkinter to create a GUI window that captures key presses

Remember, if you are copying the code, you do not need to copy any of the text that has a '#' symbol in front of it. These are called comments. They are not executed by the computer and serve only as notes or explanations for the programmer. Comments are helpful for understanding what specific parts of the code are intended to do, especially in complex programs.

    
SECTION 5 | WIRE THE SERVO MOTOR
SECTION 6 | CODE THE SERVO MOTOR

    
SECTION 7 | MAKE BOTH SET OF CODE WORK TOGETHER
DC and Servo Motors from Key Press

    
SECTION 8 | BUILD YOUR BOAT
SECTION 9 | VNC CONNECTION
SECTION 10 | EXTENDED TASK IDEAS
Options for extensions on this task are fairly limitless however, here are a few ideas on how to expand on this project. ​
  • Add ultrasonic distance sensors 
  • Add light dependent automatic lights 
  • Add a tilt and motion sensor 
  • Add a camera to remotely drive your boat from anywhere
  • Add a servo motor to control where the camera points 
  • Define a route and program your boat to automatically navigate the route. 
  • Add a grab net and use your boat to collect plastic waste
Picture
SUGGESTIONS
We would love to hear from you
SUBSCRIBE 
To enjoy more benefits
We hope you find this site useful. If you notice any errors or would like to contribute material then please contact us.