ESP32 RGB Color Picker Code
For the code to work, you need to have the app called Arduino Bluetooth Control and you will need to have the BluetoothSerial.h library.
#include <BluetoothSerial.h>
BluetoothSerial SerialBT;
// Your pin assignments
#define RED_PIN 12
#define GREEN_PIN 14
#define BLUE_PIN 27
void setup() {
Serial.begin(115200);
SerialBT.begin(“ESP32_LED”);
ledcAttachPin(RED_PIN, 0);
ledcAttachPin(GREEN_PIN, 1);
ledcAttachPin(BLUE_PIN, 2);
ledcSetup(0, 5000, 8);
ledcSetup(1, 5000, 8);
ledcSetup(2, 5000, 8);
}
void loop() {
if (SerialBT.available()) {
String data = SerialBT.readStringUntil(‘\n’);
if (data.length() == 9) {
int r = data.substring(0, 3).toInt();
int g = data.substring(3, 6).toInt();
int b = data.substring(6, 9).toInt();
// Direct, unmodified output
ledcWrite(0, r);
ledcWrite(1, g);
ledcWrite(2, b);
Serial.printf(“RGB set to: %d, %d, %d\n”, r, g, b);
}
}
}


