Raspberry Pi Pico - Actuator
by DIYables in Circuits > Raspberry Pi
9 Views, 0 Favorites, 0 Comments
Raspberry Pi Pico - Actuator
This is a compact build guide. The full tutorial, with the wiring diagram and a line-by-line walkthrough of the code, is here: https://newbiely.com/tutorials/raspberry-pico/raspberry-pi-pico-actuator
This guide shows how to control a linear actuator with a Raspberry Pi Pico using an L298N motor driver. You wire the actuator to the driver's output, drive IN1 and IN2 from the Pico to set direction, and use PWM on ENA to control speed. The guide covers linear actuators without position feedback.
Supplies
Everything below is what the build uses. The links go to the parts we make and test.
- Raspberry Pi Pico W
- Raspberry Pi Pico
- Micro USB Cable
- Linear Actuator
- L298N Motor Driver Module
- DC Power Jack
- Jumper Wires
- Breadboard
- DIYables Sensor Kit (18 sensors/displays)
Wiring
Remove all three jumpers from the L298N module before wiring anything. Connect the L298N VCC pin to the 12V power adapter (via the DC power jack) and GND to common ground. Connect the L298N 5V pin to the Pico's 5V output to power the module logic. Connect IN1 and IN2 to two GPIO pins on the Pico to control direction, and ENA to a PWM-capable GPIO to control speed. Wire the linear actuator's red (positive) and black (negative) wires to OUT1 and OUT2 on channel A.
How It Works
The Pico's GPIO signals are too weak to drive the actuator directly, so the L298N sits between them, boosting the signal and switching the polarity of the 12V supply to set direction. Setting IN1 HIGH and IN2 LOW extends the actuator; reversing them retracts it. Setting both HIGH or both LOW stops it, as does leaving ENA low. Since the actuator runs at a fixed 12V, speed is controlled not by changing voltage but by applying a PWM signal to ENA: a higher duty cycle moves the actuator faster.
Code
The example code sets IN1 and IN2 to extend the actuator quickly, waits, stops it by setting both pins LOW, retracts it by reversing the pins, then stops it again. A second version replaces the fixed HIGH on ENA with a PWM signal, letting you vary the duty cycle to slow down or speed up extension and retraction instead of only running at full speed. Upload and run the code from Thonny IDE with MicroPython installed on the Pico.
raspberry-pi-pico-actuator.py - the sketch from the tutorial, unchanged.
Full Tutorial
The complete tutorial, wiring diagram and code explanation: https://newbiely.com/tutorials/raspberry-pico/raspberry-pi-pico-actuator