top of page

Barradhan Group

Public·8 members

Python code - Ocean trash collector

Instruction

  1. Open the provided Barradhan_pycode2.txt file.

  2. Copy all the code inside the file.


Upload to Pico W

  1. Connect your Raspberry Pi Pico W to your computer

  2. Open Thonny IDE

  3. Select interpreter:

👉 MicroPython (Raspberry Pi Pico)
  1. Paste the code into Thonny

  2. Save the file as:

main.py (IMPORTANT – so it auto runs)

Hardware Setup

Make sure all components are connected:

🔹 Motor (Drive)

  • IN1 → Pin 2

  • IN2 → Pin 3

🔹 Motor (Collector)

  • IN1 → Pin 4

  • IN2 → Pin 5

🔹 Servo (Steering)

  • Signal → Pin 12

🔹 Ultrasonic Sensors

  • Front → TRIG (Pin 6), ECHO (Pin 7)

  • Left → TRIG (Pin 8), ECHO (Pin 9)

  • Right → TRIG (Pin 10), ECHO (Pin 11)

(Optional rear sensor can be added)


Run the System

After saving as main.py:

  1. Pico W will automatically start

  2. It will create Wi-Fi hotspot:

barradhanPicoBoat-01
  1. Connect your phone/laptop to this Wi-Fi

  2. Open browser and go to:


Control Modes

🔹 Manual Mode

  • Use buttons or keyboard:

    • W → Forward

    • S → Backward

    • A → Left

    • D → Right

    • P → Stop

🔹 Auto Mode

  • Boat will:

    • Move forward automatically

    • Detect obstacles using ultrasonic sensors

    • Reverse if blocked

    • Turn to the side with more space


Important Features

  • Built-in Web Controller (no app needed)

  • Auto obstacle avoidance

  • Servo steering control

  • Fail-safe: auto stop if no command (~1.4s)

  • Collector motor always ON


Notes

  • Adjust sensitivity here:

FRONT_BLOCK_CM
SIDE_BLOCK_CM
  • Adjust timing:

TURN_BURST_MS
REVERSE_BURST_MS
  • If motor direction wrong:

REVERSE_DRIVE = True
REVERSE_COLLECTOR = True

26 Views

Copyright © 2026 AUTOBOTIC SDN BHD (Reg. No. 201601042778) (1213720-P). All rights reserved.

bottom of page