Skip to main content

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 from this blog

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.

Interfacing Load Cell with Raspberry Pi 3 (via HX711) ⚖️

Interfacing Load Cell with Raspberry Pi 3 (via HX711) ⚖️ Interfacing Load Cell with Raspberry Pi 3 (via HX711) ⚖️ A load cell is a transducer that converts force (weight) into an electrical signal. The HX711 is a precision 24-bit analog-to-digital converter (ADC) designed for weigh scales. Today we’ll connect a load cell to Raspberry Pi 3 using the HX711 module. 🧪 🔧 Components Required Component Quantity Raspberry Pi 3 1 Load Cell 1 HX711 Module 1 Jumper Wires 6 Breadboard (optional) 1 🔌 Pin Connections HX711 Pin Raspberry Pi Pin Pin Number VCC 5V Pin 2 GND Ground Pin 6 DT GPIO 5 Pin 29 SCK GPIO 6 Pin 31 Figure: Load Cell connected to Raspberry Pi 3 via HX711 💻 Python Code from hx711 import HX711 import RPi.GPIO as GPIO import time hx = HX711(dout_pin=5, pd_sck_pin=6) hx.set_reading_format("MSB", "MSB") hx.set_reference_unit(1) hx.reset()...

Interfacing Sound Sensor with Raspberry Pi 3

🔹 Overview The KY-037 is a high-sensitivity sound detection sensor that can detect noise levels in the environment. It provides both analog and digital outputs. In this tutorial, we’ll interface the digital output of KY-037 with Raspberry Pi 3 Model B+ (without using an ADC like MCP3008) and detect sound events.