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...

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...

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.