STOP RUSSIAN WAR OF AGGRESSION ON UKRAINE

Raspberry Pi – LED dimmer with a PCA9685 servo controller

Raspberry Pi – LED dimmer with a PCA9685 servo controller

Build your own robot car with the Raspberry Pi!

Build your own robot car with the Raspberry Pi!

I build several Raspberry Pi robots over the last years. All of them are using a L298N H-Bridge as motor controller. To generate a perfect PWM signal for the motor controller I decided to generate the PWM signal outside the Raspberry Pi. With a special controller which only generates the PWM signal. With such a controller I will get an extremely accurate signal then the Raspberry Pi could generate it. The best solution would be a chip on a board with an I2C bus. I searched for such a solution and found a servo controller board with a PCA9685 chip. The PCA9685 chip is perfect for this kind of LED dimmer job. Besides controlling the speed of DC motors with a L298N H-Bridge my setup should be able to set the brightness of a LED strip as well.

I connected a short LED strip to the out connector of the L298N H-Bridge. It is a 12V LED strip with white LEDs. It is not an RGB LED strip.

The picture below shows my setup with a PCA9685 servo controller and a L298N H-Bridge as LED driver.

Raspberry Pi - LED dimmer

Raspberry Pi – LED dimmer

The picture below shows the LED dimmer active. The Python program I developed is available for free in the download section.

Raspberry Pi - LED dimmer active

Raspberry Pi – LED dimmer active

List of Components:

Raspberry Pi 3 Model B

Loading ...

I2C Level Converter from Adafruit

Loading ...

L298N H-Bridge as motor driver or LED driver

Loading ...

PCA9685 servo Controller

Loading ...

Software PCA9685

First you need to install the Adafruit library to control the PCA9685 servo controller. This servo controller will generate the PWM signal to dim the LED strip.

Adafruit PCA9685 library

To install the Adafruit library for the servo controller you have to execute some commands in the terminal window. For more details visit the GitHub page from Adafruit or just execute the following commands each after the other. I was connected via SSH with a terminal window on my Raspberry Pi for the installation process. I used for my setup the Raspbian Jessie.

Adafruit GitHub URL: https://github.com/adafruit/Adafruit_Python_PCA9685

Commands to install the Adafruit PCA9685 library:

Command: sudo apt-get install git build-essential python-dev

Command: cd ~

Command: git clone https://github.com/adafruit/Adafruit_Python_PCA9685.git

Command: cd Adafruit_Python_PCA9685

The next command has to be executed in the “Adafruit_Python_PCA9685” folder.

Command: sudo python setup.py install

After installing the library and wiring everything up you could check if the servo controller is available on the I2C bus. Execute the following command and you should see the PCA9685 servo controller with the address 40 or a different address.

Command: sudo i2cdetect -y 1

Now you schould see the servo controller with the address 40 on your I2C bus.

i2c detect bus result

i2c detect bus result

I wrote a small Python program to control the brightness of the LED strip with a PCA9685 and a L298N H-Bridge as LED driver.

Download: Raspberry Pi – LED dimmer

Fritzing Layout

This overview helps you to connect all the wires correctly.

LED dimmer layout

LED dimmer layout

Video:

The video shows a short LED strip which is connected to the L298N H-Bridge. The PCA9685 generates the PWM signal and controls the H-Bridge.

(Visited 6,310 times, 1 visits today)

About The Author

Maker

My name is Ingmar and I build Raspberry Pi robots in my sparetime. I wrote a book about Raspberry Pi robots 2016 which is available in German. I am interested in all kinds of electronic projects like differential GPS, machine learning or robotics.

7 Comments

  1. Tomas

    Hi, Ingmar,

    thanks for sharing this! I got the components and trying to replicate your example, but it’s a bit hard to see all the wiring from the pictures. Maybe you can share more details on which wire goes where?

    Tomas

    Reply
    • Maker

      Hi Tomas,

      I hope the Fritzing overview helps you to build your own LED dimmer…

      Best Regards,

      Maker

      Reply
      • Tomas

        Yep, it looks great! Thanks a lot for sharing it!

        Reply
  2. Tomas

    Hi, Ingmar,

    In June, I tested the setup with one LED channel and as I said – all worked well. Now, I’m trying to figure out how to connect 3 independent LED lights and control dimming separately. I guess I’d need 3x L298N bridges, but then I wonder if I could connect all four (IN1, INT2, INT3, INT4) pins in parallel to 6, 13, 19, 26 and only connect PWM to different channels on the PCA9685. I’ll do my experiments, but any thoughts from your side would be very welcome and would help a lot.

    Reply
    • Maker

      Hi Tomas,
      I am not sure if such a setup will work. If you set the IN1, IN2, IN3 high and IN4 low which GND will you use for the LED lights connected to IN1/IN2 ?
      Ingmar

      Reply
  3. Shaun

    Works like a charm! Thank you o so much!

    Reply

Leave a reply

Your email address will not be published. Required fields are marked *

Book recommendation:

Build your own robot car with the Raspberry Pi!

Build your own robot car with the Raspberry Pi!