0% found this document useful (0 votes)
54 views

l293d Linear Actuator

1. The document describes using an L293D motor driver with a Raspberry Pi Pico to control a linear actuator based on input from a potentiometer. The L293D requires two GPIO pins for direction control and one PWM pin for speed control. 2. It provides the components needed, including a Pico, linear actuator, L293D driver, potentiometer, breadboard and external power supply. 3. Example MicroPython code is given to read the potentiometer value and control the actuator's speed and direction via the L293D based on mapping the potentiometer reading to PWM duty cycle.

Uploaded by

hdrth
Copyright
© © All Rights Reserved
Available Formats
Download as TXT, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
54 views

l293d Linear Actuator

1. The document describes using an L293D motor driver with a Raspberry Pi Pico to control a linear actuator based on input from a potentiometer. The L293D requires two GPIO pins for direction control and one PWM pin for speed control. 2. It provides the components needed, including a Pico, linear actuator, L293D driver, potentiometer, breadboard and external power supply. 3. Example MicroPython code is given to read the potentiometer value and control the actuator's speed and direction via the L293D based on mapping the potentiometer reading to PWM duty cycle.

Uploaded by

hdrth
Copyright
© © All Rights Reserved
Available Formats
Download as TXT, PDF, TXT or read online on Scribd
You are on page 1/ 2

Using an L293D motor driver with a Raspberry Pi Pico to control a linear actuator

based on a potentiometer's input is quite similar to using an L298N, with some


minor differences due to the L293D's characteristics. The L293D can also control
two motors but we'll use it for one linear actuator in this example. It requires
two GPIO pins for direction control and one PWM-capable pin for speed control.

### Components Needed:

1. Raspberry Pi Pico
2. Linear actuator
3. L293D Motor Driver IC
4. Potentiometer (10k�)
5. Breadboard and jumper wires
6. External power supply for the L293D and the actuator (if needed, depending on
the actuator's requirements)

### Circuit Setup:

- **Linear Actuator:** Connect your actuator's leads to the L293D's output


terminals (OUT1 and OUT2 for one motor channel).
- **L293D Inputs:** Connect two Pico GPIO pins to the L293D's input pins (IN1 and
IN2 for the same motor channel) for direction control. Connect a Pico PWM-capable
pin to the L293D's Enable pin (EN1 for the same channel) for speed control.
- **Potentiometer:** Connect one side to 3.3V on the Pico, the other side to GND,
and the middle pin (wiper) to an ADC-capable pin on the Pico.
- **Power:** Make sure the L293D and the actuator are powered appropriately; the
Pico cannot supply sufficient power for most actuators.

### Example Code:

This example uses MicroPython to read the potentiometer value and control the
actuator's speed and direction via the L293D.

```python
from machine import Pin, PWM, ADC
from time import sleep

# Initialize L293D control pins


in1 = Pin(14, Pin.OUT)
in2 = Pin(13, Pin.OUT)
enable = PWM(Pin(15)) # Use a PWM-capable pin for speed control
enable.freq(1000) # Set PWM frequency to 1 kHz

# Initialize ADC for potentiometer


potentiometer = ADC(Pin(26)) # ADC0 pin (GP26)

def map_value(value, in_min, in_max, out_min, out_max):


# Map a value from one range to another
return (value - in_min) * (out_max - out_min) / (in_max - in_min) + out_min

def set_actuator_speed(speed):
if speed > 0:
in1.high()
in2.low()
enable.duty_u16(abs(speed))
elif speed < 0:
in1.low()
in2.high()
enable.duty_u16(abs(speed))
else:
in1.low()
in2.low()
enable.duty_u16(0)

while True:
# Read potentiometer value and map it from -65535 to 65535 for full
reverse/forward control
pot_value = potentiometer.read_u16() # 16-bit value (0-65535)
speed = map_value(pot_value, 0, 65535, -65535, 65535)

# Set actuator speed and direction


set_actuator_speed(int(speed))

sleep(0.1) # Small delay for responsiveness


```

### Notes:

- The `set_actuator_speed` function controls the actuator's direction and speed.


Positive values move it in one direction, negative values in the opposite, and zero
stops it.
- The `map_value` function now maps the potentiometer reading to a range that
includes negative values for reverse direction, allowing full control over the
actuator.
- Adjust the PWM frequency (`enable.freq(1000)`) according to your actuator's
requirements. The L293D is generally used with frequencies up to a few kHz.
- Be mindful of the power requirements and ensure your power supply and the L293D
can handle the actuator's current without overheating.

This setup provides a simple way to control a linear actuator's direction and speed
using a potentiometer and a Raspberry Pi Pico with an L293D motor driver.

You might also like

pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy