How to adjust brightness of an RGB LED strip with Arduino Uno?

I have an RGB LED strip working with an Arduino Uno and would like to be able to control the brightness.

Below is my current working code and attached is diagram of setup.

Am using these MOSFET’s:

IRLB8721PbF (Datasheet)

LED strip specs are at end of post.

I’ve tried searches for:

“adjust rgb led strip brightness python serial”

“rgb led strip dimming python serial”

But any possible matches relate to implementations that are a bit over my head, or slightly off topic.


import serial

ser = serial.Serial('/dev/ttyACM0', 9600)

ser.write(struct.pack('>3B', red_value, green_value, blue_value))


// digital output pin numbers
const int digitalOutputPinForRedLED = 9;
const int digitalOutputPinForGreenLED = 10;
const int digitalOutputPinForBlueLED = 11;

// global variables
int valueOfRed = 0;
int valueOfGreen = 0;
int valueOfBlue = 0;
int x = 1;

void setup() {
  // initialize serial communications at 9600 bps:

  // set digital pin modes

void loop() {
  if (Serial.available()) {
    if (x==1) {
     valueOfRed =;
     Serial.print("Red: ");
     analogWrite(digitalOutputPinForRedLED, valueOfRed);
    else if (x==2) {
     valueOfGreen =;
     Serial.print("Green: ");
     analogWrite(digitalOutputPinForGreenLED, valueOfGreen);
    else if (x==3) {
     valueOfBlue =;
     Serial.print("Blue: ");
     analogWrite(digitalOutputPinForBlueLED, valueOfBlue);
    else {
      x = 1; 


RGB LED strip

LED type: 5050
LED quantity: 300LED
Package: 5 Meter/REEL
Voltage: 12V DC
Working Power: 14.4W
Working temperature: -20° to 50°
Size: ⌀180mm
Length: 5m
Life Span: 50000+hours
Weight: 0.3kg

Why the Python? The Arduino runs on C++.

A bit rubbish that code but it should do something. Use the serial monitor to put single bytes to the read. Note you will be typing ASCII and the code is expecting a binary value, but it should give you something if your hardware is set up right.

Why do you have the Vin pin going to the 5V rail of the breadboard, which is powering the strip? Then you have some kind of supply going to the same 5V rail of the breadboard. And you have a 12V supply going into the barrel jack of the board.

Bad things are going to happen.

There is no 5V rail on the bread board it is just a rail.

Mind you the power for the strip will have to go through the reverse protection diode which has a limit of 1A but apart from that the circuit will work.