Python code - Ocean trash collector
Instruction
Open the provided Barradhan_pycode2.txt file.
Copy all the code inside the file.
Upload to Pico W
Connect your Raspberry Pi Pico W to your computer
Open Thonny IDE
Select interpreter:
👉 MicroPython (Raspberry Pi Pico)
Paste the code into Thonny
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:
Pico W will automatically start
It will create Wi-Fi hotspot:
barradhanPicoBoat-01
Connect your phone/laptop to this Wi-Fi
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

