Hack star
Published © MIT

Drive RGB LED using Arduino- Wokwi Arduino Simulator-2022

Let us see how we can connect and drive an RGB LED with Arduino UNO. Wokwi Arduino simulator enables you to tinker with the code online!

BeginnerProtip1 hour4,140

Things used in this project

Story

Read more

Schematics

Arduino UNO RGB LED project

Arduino UNO RGB LED project

Code

RGB LED and Arduino project

Arduino
RGB LED and Arduino project
// RGB and R, G, B LED demo
// Wokwi Arduino simulator
// Link: https://wokwi.com/arduino/projects/306455554559050306
const int pinR = 3;
const int pinG = 5;
const int pinB = 6;

const int potR = A0;
const int potG = A1;
const int potB = A2;

void setup() {
  pinMode(pinR, OUTPUT);
  pinMode(pinG, OUTPUT);
  pinMode(pinB, OUTPUT);
  pinMode(potR, INPUT);
  pinMode(potG, INPUT);
  pinMode(potB, INPUT);
}

int readPot(int pin) {
  return map(analogRead(pin), 0, 1023, 0, 255);
}

void loop() {
  analogWrite(pinR, readPot(potR));
  analogWrite(pinG, readPot(potG));
  analogWrite(pinB, readPot(potB));
}

Credits

Hack star

Hack star

75 projects • 99 followers
an Arduino enthusiast and an electronic hobbyist

Comments