Interfacing Raspberry Pi 3 B+ with Servo Motor ✨ (English & Marathi)

 💻 Introduction

A servo motor is widely used in robotics and automation projects. It allows precise control over rotation. In this tutorial, we will learn how to interface a servo motor with Raspberry Pi 3 B+ using Python.

What will you learn?

  • How a servo motor works
  • Wiring the servo with RPi 3 B+
  • Writing Python code to control the servo

🛠 Components Required

        Component Quantity
        Raspberry Pi 3 B+             1
        SG90 Servo Motor         1
        Jumper Wires         3
        External 5V Power Supply (Optional)         1


🛠 Circuit Diagram & Connection : 

Connect the servo motor to Raspberry Pi as follows:   

Servo Pin                                 Raspberry Pi pins
 VCC (Red)      5V  (Pin 2 or 4)
 GND (Black/Brown)      GND (Pin 6)
 Signal (Orange/Yellow)      GPIO 17 (Pin 11)

🔗 Ensure to use an external power supply for multiple servos to prevent overloading the Raspberry Pi.


💻 Python Code to Control Servo

import RPi.GPIO as GPIO
import time

GPIO.setmode(GPIO.BCM)
GPIO.setup(17, GPIO.OUT)
servo = GPIO.PWM(17, 50)  # 50Hz PWM frequency
servo.start(0)

def set_angle(angle):
    duty = 2 + (angle / 18)
    servo.ChangeDutyCycle(duty)
    time.sleep(0.5)
    servo.ChangeDutyCycle(0)

try:
    while True:
        angle = int(input("Enter angle (0-180): "))
        set_angle(angle)
except KeyboardInterrupt:
    servo.stop()
    GPIO.cleanup()

🎉 Testing

  1. Run the script using:
    python3 servo.py
    
  2. Enter different angles (0-180°) and observe the servo movement!

🇮🇳 (मराठीत) Raspberry Pi 3 B+ आणि सर्व्हो मोटर इंटरफेसिंग

💻 परिचय

सर्व्हो मोटर ही अचूक कोन नियंत्रित करण्यासाठी वापरली जाते. या ट्युटोरियलमध्ये आपण Raspberry Pi 3 B+ सोबत सर्व्हो मोटर कशी जोडायची हे शिकू!


🛠 आवश्यक साहित्य

 घटक                                                 प्रमाण
Raspberry Pi 3 B+ 1
SG90 सर्व्हो मोटर 1
जम्पर वायर 3
बाह्य 5V पॉवर पुरवठा (पर्यायी) 1

🛠 वायरिंग डायग्राम आणि कनेक्शन

सर्व्हो पिन                                 Raspberry Pi सोबत कनेक्शन
VCC (Red) 5V (Pin 2 किंवा 4)
GND (Black/Brown) GND (Pin 6)
सिग्नल (Orange/Yellow) GPIO 17 (Pin 11)

💻 सर्व्हो नियंत्रित करण्यासाठी पायथन कोड

import RPi.GPIO as GPIO
import time

GPIO.setmode(GPIO.BCM)
GPIO.setup(17, GPIO.OUT)
servo = GPIO.PWM(17, 50)  # 50Hz PWM frequency
servo.start(0)

def set_angle(angle):
    duty = 2 + (angle / 18)
    servo.ChangeDutyCycle(duty)
    time.sleep(0.5)
    servo.ChangeDutyCycle(0)

try:
    while True:
        angle = int(input("कोन प्रविष्ट करा (0-180): "))
        set_angle(angle)
except KeyboardInterrupt:
    servo.stop()
    GPIO.cleanup()

🎉 चाचणी

  1. खालील कमांड वापरून स्क्रिप्ट चालवा:
    python3 servo.py
    
  2. विविध कोन (0-180°) प्रविष्ट करा आणि सर्व्होचा प्रतिसाद पाहा!

🌟 निष्कर्ष (Conclusion)

आता तुम्ही Raspberry Pi 3 B+ वापरून सर्व्हो मोटर नियंत्रित करू शकता! 🚀


Stay tuned for more Raspberry Pi projects! 💡

Comments

Popular Posts