✨ DOWNLOAD OUR APP - Use RCAPP
for additional 5% discount! + Redeem RC COINS 👇
Skip to content
Free Delivery on Orders Above Rs 500/- Pan-India
Cash on Delivery Available for Orders above Rs.500/- and Upto Rs 3000/-
SAVE more when you BUY more. Upto 30% Off on BULK PURCHASE
GST Invoices for Your Business
Dedicated Technical Support Team
Safely Delivering Genuine Products PAN INDIA
Ph: +91 812 3057 137   |  Support

Post

Controlling Speed and Led Brightness of Robot Using Raspberry Pi

 

Pulse Width Modulation (PWM) finds a place in numerous applications in the field of embedded systems, robotics and all kinds of automation; be it process control, home automation or industrial automation. PWM signal is basically a digital pulse train signal. The use of PWM signals ranges all the way from basic LED dimming circuits to complex control systems. In the scope of this article, we shall be touching upon some of the more basic applications such as controlling LED brightness.

To begin with, let us go over some concepts that provide intuitive insight into the core concepts behind the working of PWM.

Visit our Raspberry Pi Camera collection page for official Camera.

Duty Cycle

Duty cycle refers to the ratio of on time of the signal to the total time period of the signal. As with any signal, we first define a base frequency of the signal. On this signal, the time for which it is high and low is modulated to change the duty cycle.

Shown below are three different signals with duty cycles of 75%, 50% and 25%. The value of duty cycle of a PWM signal decides the equivalent DC level of the signal.

 

 

The resultant DC level of the signal is calculated by the formula given below.

Where Vdc is the net DC level of the PWM signal. DC is the duty cycle of the PWM signal (from 0 to 1) and Vi is the voltage level of the PWM signal. For example, if we consider a 5v PWM signal, at 25% duty cycle the net DC voltage will be 0.25*5 which is 1.25 volts.

PWM on Raspberry Pi

Moving onto the Raspberry Pi, the circuit diagram below shows the connections to be made for the LEDs.

 

The following image shows all the pins which are available to be configured and used as PWM pins.

PWM pins diagram

 

Code for Controlling LED Brightness:

import time

import RPi.GPIO as GPIO

ledPin1=18

ledPin2=12

GPIO.setmode(GPIO.BCM)

GPIO.setup(ledPin1, GPIO.OUT)

GPIO.setup(ledPin2, GPIO.OUT)

p1 = GPIO.PWM(ledPin1, 50)

p2 = GPIO.PWM(ledPin2, 50)

p1.start(0)

p2.start(0)

try:

GPIO.output(ledPin,GPIO.HIGH)

while True:

for dc in range(0, 101):

p1.ChangeDutyCycle(dc)

p2.ChangeDutyCycle(100-dc)

time.sleep(0.1)

for dc in range(100, -1):

p1.ChangeDutyCycle(dc)

p2.ChangeDutyCycle(100-dc)

time.sleep(0.1)

except KeyboardInterrupt:

pass

p1.stop()

p2.stop()

GPIO.cleanup()

Demonstration for controlling Bot Speed:

 

Prev Post
Next Post

Leave a comment

Please note, comments need to be approved before they are published.

Thanks for subscribing!

This email has been registered!

Shop the look

Choose Options

Edit Option
Back In Stock Notification
Compare
Product SKU Description Collection Availability Product Type Other Details

Choose Options

this is just a warning
Login
Shopping Cart
0 items
FREE SHIPPING!
₹100 OFF
₹200 OFF