Skip to main content

Interfacing Raspberry Pi 3 B+ with DC Motor using L298N ЁЯЪАЁЯФз

 Controlling a DC motor with a Raspberry Pi 3 B+ is an essential project for robotics and automation. In this tutorial, we will interface a DC motor with Raspberry Pi 3 B+ using the L298N motor driver. Let’s get started! ЁЯЪЧ⚡


ЁЯУЭ Components Required

ComponentQuantityDescription
Raspberry Pi 3 B+1Main Controller
L298N Motor Driver1To control the DC motor
DC Motor1The motor to be controlled
Power Supply (12V)1External power for motor
Jumper WiresAs neededTo connect components
Breadboard1For connections (optional)

ЁЯФМ Circuit Connections

L298N PinConnects To
12V12V Power Supply
GNDRaspberry Pi GND & Power Supply GND
5VNot Connected (Raspberry Pi provides 3.3V)
IN1Raspberry Pi GPIO 17 (BCM)
IN2Raspberry Pi GPIO 18 (BCM)
ENARaspberry Pi GPIO 22 (BCM)
OUT1 & OUT2DC Motor Terminals

ЁЯФ┤ Note: The L298N module needs an external power supply (12V) to drive the DC motor efficiently. The Raspberry Pi should not power the motor directly.

ЁЯУ╖ Circuit Diagram

(Attach a circuit diagram showing Raspberry Pi, L298N, and DC motor connections.)


ЁЯТ╗ Python Code for Motor Control

python
import RPi.GPIO as GPIO import time # Pin configuration IN1 = 17 # GPIO 17 IN2 = 18 # GPIO 18 ENA = 22 # GPIO 22 (Enable Pin) # Setup GPIO.setmode(GPIO.BCM) GPIO.setup(IN1, GPIO.OUT) GPIO.setup(IN2, GPIO.OUT) GPIO.setup(ENA, GPIO.OUT) # PWM setup pwm = GPIO.PWM(ENA, 1000) # 1kHz frequency pwm.start(50) # 50% duty cycle # Function to move motor forward def motor_forward(): GPIO.output(IN1, GPIO.HIGH) GPIO.output(IN2, GPIO.LOW) print("Motor moving forward") # Function to move motor backward def motor_backward(): GPIO.output(IN1, GPIO.LOW) GPIO.output(IN2, GPIO.HIGH) print("Motor moving backward") # Function to stop motor def motor_stop(): GPIO.output(IN1, GPIO.LOW) GPIO.output(IN2, GPIO.LOW) print("Motor stopped") # Test motor motor_forward() time.sleep(2) motor_backward() time.sleep(2) motor_stop() # Cleanup GPIO.cleanup()

ЁЯУЭ Working Explanation

  1. GPIO Setup: The Raspberry Pi controls the motor via the L298N module using GPIO 17 (IN1), GPIO 18 (IN2), and GPIO 22 (ENA - PWM speed control).

  2. Motor Control:

    • Motor Forward: IN1 = HIGH, IN2 = LOW

    • Motor Backward: IN1 = LOW, IN2 = HIGH

    • Motor Stop: IN1 = LOW, IN2 = LOW

  3. PWM Speed Control: The ENA pin is controlled using PWM (Pulse Width Modulation) to adjust the motor speed.


ЁЯЫа️ Troubleshooting Tips

ЁЯФ╣ Motor not running? Check power connections and GPIO setup.
ЁЯФ╣ Motor moves in the wrong direction? Swap IN1 and IN2 connections.
ЁЯФ╣ PWM not working? Ensure correct frequency and duty cycle settings.


ЁЯЪА рд░ाрд╕्рдкрдмेрд░ी рдкाрдИ 3 B+ рд╕ोрдмрдд DC рдоोрдЯрд░ рдЖрдгि L298N рдЗंрдЯрд░рдлेрд╕िंрдЧ

рд░ाрд╕्рдкрдмेрд░ी рдкाрдИ 3 B+ рдЖрдгि L298N рдоोрдЯрд░ рдб्рд░ाрдпрд╡्рд╣рд░ рд╡ाрдкрд░ूрди DC рдоोрдЯрд░ рдХंрдЯ्рд░ोрд▓ рдХрд░рдгे рд╢िрдХूрдпा! ЁЯЪЧ⚡

ЁЯЫа️ рдЖрд╡рд╢्рдпрдХ рд╕ाрд╣िрдд्рдп

рдШрдЯрдХрдк्рд░рдоाрдгрд╡рд░्рдгрди
рд░ाрд╕्рдкрдмेрд░ी рдкाрдИ 3 B+1рдоुрдЦ्рдп рдХंрдЯ्рд░ोрд▓рд░
L298N рдоोрдЯрд░ рдб्рд░ाрдпрд╡्рд╣рд░1DC рдоोрдЯрд░ рдХंрдЯ्рд░ोрд▓ рдХрд░рдг्рдпाрд╕ाрдаी
DC рдоोрдЯрд░1рдлिрд░рдгाрд░ी рдоोрдЯрд░
12V рдкॉрд╡рд░ рд╕рдк्рд▓ाрдп1рдоोрдЯрд░рд╕ाрдаी рд╡ीрдЬрдкुрд░рд╡рдаा
рдЬрдо्рдкрд░ рд╡ाрдпрд░्рд╕рдЧрд░рдЬेрдк्рд░рдоाрдгेрдХрдиेрдХ्рд╢рдирд╕ाрдаी
рдм्рд░ेрдбрдмोрд░्рдб1рд╕рд░्рдХिрдЯ рдХрдиेрдХ्рд╢рдирд╕ाрдаी (рдкрд░्рдпाрдпी)

ЁЯФМ рд╕рд░्рдХिрдЯ рдХрдиेрдХ्рд╢рди

L298N рдкिрдирдЬोрдбрдгी
12V12V рдкॉрд╡рд░ рд╕рдк्рд▓ाрдп
GNDрд░ाрд╕्рдкрдмेрд░ी рдкाрдИ GND рдЖрдгि рдкॉрд╡рд░ рд╕рдк्рд▓ाрдп GND
5VрдХाрд╣ीрд╣ी рдиाрд╣ी (рд░ाрд╕्рдкрдмेрд░ी рдкाрдИ 3.3V рд╡ाрдкрд░рддे)
IN1рд░ाрд╕्рдкрдмेрд░ी рдкाрдИ GPIO 17 (BCM)
IN2рд░ाрд╕्рдкрдмेрд░ी рдкाрдИ GPIO 18 (BCM)
ENAрд░ाрд╕्рдкрдмेрд░ी рдкाрдИ GPIO 22 (BCM)
OUT1 рдЖрдгि OUT2DC рдоोрдЯрд░ рдЬोрдбрдгी

ЁЯФ┤ рдЯीрдк: L298N рдоॉрдб्рдпूрд▓рд▓ा рдмाрд╣्рдп 12V рд╡ीрдЬрдкुрд░рд╡рдаा рдЖрд╡рд╢्рдпрдХ рдЖрд╣े. рдоोрдЯрд░рд▓ा рд░ाрд╕्рдкрдмेрд░ी рдкाрдИ рдеेрдЯ рдкॉрд╡рд░ рджेрдК рд╢рдХрдд рдиाрд╣ी.

ЁЯУ╖ рд╕рд░्рдХिрдЯ рдбाрдпрдЧ्рд░ाрдо

(рдЗрдеे рд░ाрд╕्рдкрдмेрд░ी рдкाрдИ, L298N, рдЖрдгि DC рдоोрдЯрд░рдЪे рдЬोрдбрдгी рдбाрдпрдЧ्рд░ाрдо рджाрдЦрд╡ा.)


ЁЯТ╗ рдоोрдЯрд░ рдХंрдЯ्рд░ोрд▓рд╕ाрдаी Python рдХोрдб

(рд╡рд░ीрд▓ рдЗंрдЧ्рд░рдЬी рдХोрдб рдорд░ाрдаीрдд рд╡рд░्рдгрдиाрд╕рд╣ рд╡ाрдкрд░ा.)


ЁЯОп рдиिрд╖्рдХрд░्рд╖

L298N рдоोрдЯрд░ рдб्рд░ाрдпрд╡्рд╣рд░ рд╡ाрдкрд░ूрди рд░ाрд╕्рдкрдмेрд░ी рдкाрдИ 3 B+ рд╕ोрдмрдд DC рдоोрдЯрд░ рдиिрдпंрдд्рд░िрдд рдХрд░рддा рдпेрддे.
PWM рд╡ाрдкрд░ूрди рд╕्рдкीрдб рдХंрдЯ्рд░ोрд▓ рдХрд░рддा рдпेрддो.
✅ рд╣े рд░ोрдмोрдЯिрдХ्рд╕ рдЖрдгि рдСрдЯोрдоेрд╢рди рдк्рд░ोрдЬेрдХ्рдЯрд╕ाрдаी рдЙрдкрдпुрдХ्рдд рдЖрд╣े.

ЁЯЪА рддुрдордЪ्рдпा рдк्рд░ोрдЬेрдХ्рдЯрдордз्рдпे рдпाрдЪा рд╡ाрдкрд░ рдХрд░ूрди рдмрдШा рдЖрдгि рдЕрдиुрднрд╡ рд╢ेрдЕрд░ рдХрд░ा! ЁЯЫа️⚡


рддुрдо्рд╣ाрд▓ा рд╣ा рдм्рд▓ॉрдЧ рдХрд╕ा рд╡ाрдЯрд▓ा? рдХрдоेंрдЯ рдХрд░ा! ЁЯТмЁЯСЗ

Comments

Popular posts from this blog

IOT : GARDEN WATER SPRINKLER SYSTEM

IoT projects have gained immense popularity due to their ability to leverage the power of interconnected devices and data to create innovative solutions across various domains. IoT projects involve integrating sensors, actuators, and communication technologies to enable the seamless exchange of data between physical devices and the internet. These projects range from simple DIY experiments to complex industrial applications, each offering unique opportunities to transform our lives and improve efficiency. Whether it's creating a smart home automation system, monitoring environmental conditions, optimizing energy usage, or developing intelligent transportation systems, applications of IoT open up a world of possibilities for innovation and connectivity. By harnessing the potential of IoT, we can build intelligent and interconnected systems that revolutionize industries, enhance daily life, and pave the way for a more efficient and sustainable future. In this project we will be using...

TOUCH PLATE BASED DOOR BELL

Title:  Touch plate based door bell  Circuit:  Components: IC 555 Resistors: 1 M, 100k, 330 ohms Transistor: BC547  PN2222A Capacitor: 10n 1 Copper plate : as touch plate. A 6v battery An LED / Ic UM66 Description: This is the simple circuit for touch plate based security system. In this project what basically done is, circuit detects stray voltages produced by mains voltage and electrostatic built  up in the room.If sufficient static voltage is detected by the plate then chip will charge up. Transistor BC 547 or PN2222A is used basically to increase the sensitivity.In place of led just connect IC um 66(melody IC). Applications: In homes, of course. This can be specially used in places like hospitals, when patients need to call doctor by himself.

POWER BI - THE ARCHITECTURE

Power BI Architecture: A Comprehensive Guide to Building Effective Data Analytics Solutions     Understanding Power BI Architecture: Power BI's architecture comprises four main components, each playing a pivotal role in the data analytics process: Data Sources:   Power BI connects to a wide range of data sources, including databases, cloud services, Excel files, web services, and more. This versatility enables organizations to consolidate their data from various systems into a single dashboard. Data Transformation:   Once the data is sourced, it undergoes transformation and cleaning processes to make it suitable for analysis. Power BI's Power Query Editor provides a user-friendly interface to manipulate, filter, and shape data according to specific requirements. Data Model:   The heart of Power BI's architecture lies in its data model, whic...