✨ Use RCAPP and get 5% off 👇
Skip to content
Free Delivery on Orders Above Rs 999/- 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

Controlling Speed and Led Brightness of Robot Using Raspberry Pi

Controlling Speed and Led Brightness of Robot Using Raspberry Pi
D
Written By Daniel D'Souza
📅 Updated on 17 Jun 2026
Summarize with AI
✅ Prompt copied

 

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.

Components and Supplies

Raspberry Pi 3 Kit – Versatile Official Raspberry Pi kit for beginners & advanced users. -RobocrazeRaspberry Pi 3 Kit – Versatile Official Raspberry Pi kit for beginners & advanced users. -Robocraze

Raspberry Pi 3 Kit

Raspberry Pi 3 Kit Raspberry Pi Starter Kit (including Raspberry Pi 3) contains everything you need to get started with your Raspberry Pi in as little time as possible! We've carefully compatibility tested all components, and only selected the very best manufacturer guaranteed, high-quality parts available! ...
Rs 8,049/-
Rs 8,049/-
Rs 8,990/-
Save Rs 941/-
Raspberry Pi 5MP Camera Module with Cable – 5MP Camera Module with included cable. -RobocrazeRaspberry Pi 5MP Camera Module with Cable – 5MP Camera Module with included cable. -Robocraze

    Raspberry Pi 5MP Camera Module with Cable

    Raspberry Pi 5MP Camera Module with Cable This 5mp Raspberry Pi camera module is a portable lightweight camera that is capable of 1080p video and still images and connects directly to your Raspberry Pi. Connect the included USB/ ribbon cable to the CSI (Camera...
    Rs 289/-
    Rs 289/-
    Rs 449/-
    Save Rs 160/-
    3.2in Raspberry Pi Touch Screen – Interactive Raspberry Pi Accessories for display applications. -Robocraze3.2in Raspberry Pi Touch Screen – Interactive Raspberry Pi Accessories for display applications. -Robocraze

      3.2in Raspberry Pi Touch Screen

      3.2inch Raspberry Pi Touch Screen The 3.2inch standard display, support HDMI input, refresh rate of 60FPS or more. It has a physical resolution 320*240. It can be used as display for raspberry pi, with touch control function (need to install touch drive). It also can be used as a computer...
      Rs 783/-
      Rs 783/-
      Rs 1,999/-
      Save Rs 1,216/-

      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:

       

      Excerpt

      In this blog we will see compete guide on how to control Speed and LED Brightness of Robot Using Raspberry Pi
      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
      ₹999
      ₹2500
      ₹4900
      WhatsApp Chat Chat