Presentation is loading. Please wait.

Presentation is loading. Please wait.

Raspberry Pi GPIO PWM Servo Motor

Similar presentations


Presentation on theme: "Raspberry Pi GPIO PWM Servo Motor"— Presentation transcript:

1 Raspberry Pi GPIO PWM Servo Motor

2 PWM(Pulse Width Modulation)?
Modulation technique used to encode a message into a pulsing signal. Control of the power supplied to electrical devices, especially to inertial loads such as motors.

3 PWM + Servo Motor(SG90) 0도 45도 90도

4 Wiring RPi GPIO18 - PWM RPi 5V - Vcc RPi GND - Ground

5 Python code $ python3 servo.py 1 $ python3 servo.py 1.5
import RPi.GPIO as GPIO import time import sys GPIO.setwarnings(False) GPIO.setmode(GPIO.BCM) GPIO.setup(18, GPIO.OUT) pwm = GPIO.PWM(18, 50) # 50Hz pwm.start(1) if len(sys.argv) != 2: print('python servo.py 1~3’) else: ms = float(sys.argv[1]) dcycle = ms / 20.0 * 100 # percent pwm.ChangeDutyCycle(dcycle) time.sleep(2) # wait until the device receiving pwm.stop() GPIO.cleanup() Python code $ python3 servo.py 1 $ python3 servo.py 1.5 $ python3 servo.py 2

6 Exercise 버튼을 3개 연결하고 각 버튼을 누르면 서로 다른 위치로 서보 모터를 동작 시킨다.
서보 모터 대신 LED를 GPIO에 연결해서 결과를 본다.


Download ppt "Raspberry Pi GPIO PWM Servo Motor"

Similar presentations


Ads by Google