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.
Python:
import serial
ser = serial.Serial('/dev/ttyACM0', 9600)
ser.write(struct.pack('>3B', red_value, green_value, blue_value))
Sketch:
// 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:
Serial.begin(9600);
// set digital pin modes
pinMode(digitalOutputPinForRedLED,OUTPUT);
pinMode(digitalOutputPinForGreenLED,OUTPUT);
pinMode(digitalOutputPinForBlueLED,OUTPUT);
}
void loop() {
if (Serial.available()) {
if (x==1) {
valueOfRed = Serial.read();
Serial.print("Red: ");
Serial.println(valueOfRed);
analogWrite(digitalOutputPinForRedLED, valueOfRed);
}
else if (x==2) {
valueOfGreen = Serial.read();
Serial.print("Green: ");
Serial.println(valueOfGreen);
analogWrite(digitalOutputPinForGreenLED, valueOfGreen);
}
else if (x==3) {
valueOfBlue = Serial.read();
Serial.print("Blue: ");
Serial.println(valueOfBlue);
analogWrite(digitalOutputPinForBlueLED, valueOfBlue);
}
x++;
}
else {
x = 1;
}
delay(1);
}
Specs:
LED type: 5050
SMDColor: RGB
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
