CASE FOR RASPBERRY PI PICO W 2
Print Profile(2)


Description
built this case to wrap the conveyor into a nice clean box.
here is the print file and my script for the pi.
if requested i can provide the mount for the reed switch as well.
*******************************************pico pi script *****************************************************************
from machine import ADC, Pin
from time import ticks_ms, sleep
# === INPUT PINS ===
reed_sensor = ADC(26) # GP26 - Reed switch
ir_sensor = Pin(0, Pin.IN) # GP0 - IR fallback
# === OUTPUTS: Stepper via ULN2003 (GP2–GP5)
IN1 = Pin(2, Pin.OUT)
IN2 = Pin(3, Pin.OUT)
IN3 = Pin(4, Pin.OUT)
IN4 = Pin(5, Pin.OUT)
# === LED Indicators
blue_led = Pin(6, Pin.OUT) # GP6 - Trigger blink
yellow_led = Pin(7, Pin.OUT) # GP7 - Motor active
red_led = Pin(8, Pin.OUT) # GP8 - Wait countdown
green_led = Pin(15, Pin.OUT) # GP15 - Heartbeat
heartbeat_led = Pin("LED", Pin.OUT)
# === Timing + Thresholds
heartbeat_timer = 0
heartbeat_interval = 2000
motor_running = False
motion_start = 0
motion_confirmed = False
motion_hold_time = 1000 # debounce
LOW_THRESHOLD = 0.5
HIGH_THRESHOLD = 1.5
# === Stepper Sequence
sequence = [
[1,0,0,1],
[1,0,0,0],
[1,1,0,0],
[0,1,0,0],
[0,1,1,0],
[0,0,1,0],
[0,0,1,1],
[0,0,0,1]
]
def set_step(step):
IN1.value(step[0])
IN2.value(step[1])
IN3.value(step[2])
IN4.value(step[3])
def spin_motor(duration_ms=30000, delay=1):
global motor_running
print("⏳ Wait timer started — 10 seconds")
for _ in range(10):
red_led.high()
sleep(0.5)
red_led.low()
sleep(0.5)
print("🔁 Stepper motor spinning for 30 seconds")
motor_running = True
yellow_led.high()
start_time = ticks_ms()
while ticks_ms() - start_time < duration_ms:
for step in sequence:
set_step(step)
sleep(delay / 1000)
stop_motor()
def stop_motor():
global motor_running
set_step([0,0,0,0])
yellow_led.low()
motor_running = False
print("⛔ Motor stopped")
def blink_blue(times=3, delay=0.2):
for _ in range(times):
blue_led.high()
sleep(delay)
blue_led.low()
sleep(delay)
def heartbeat():
global heartbeat_timer
now = ticks_ms()
if now - heartbeat_timer > heartbeat_interval:
heartbeat_led.toggle()
green_led.toggle()
heartbeat_timer = now
# === MAIN LOOP ===
print("🚀 Conveyor controller ready")
while True:
heartbeat()
voltage = (reed_sensor.read_u16() / 65535) * 3.3
if voltage < LOW_THRESHOLD and not motor_running:
print(f"🧲 Magnet trigger: {voltage:.2f}V")
blink_blue(2)
spin_motor()
elif int(not ir_sensor.value()) == 1 and not motor_running:
if motion_start == 0:
motion_start = ticks_ms()
elif ticks_ms() - motion_start > motion_hold_time and not motion_confirmed:
print("👁️ IR fallback trigger")
blink_blue(3)
spin_motor()
motion_confirmed = True
else:
motion_start = 0
motion_confirmed = False
sleep(0.01)
**********************************************wiring setup*******************************************************************
GP2 Motor driver IN1-white
GP3 Motor driver IN2-tan
GP4 motor driver IN3-orange
GP5 motor driver IN4-yellow
GP6 green LED — blinks when magnet detected
GP7 Yellow LED — ON while motor is active
GP8 Red LED — wait to start motor spin delay GP15 blue LED — heartbeat (pairs with onboard)
GP26 Reed sensor (ADC input for magnet trigger)
LED Onboard LED — heartbeat toggle
3.3V Powers pull-up resistor for reed sensor
GND Common ground for all components





Comment & Rating (9)