Introduction: USA Arduino Interrupt LED Brightness

In this project, we will be creating a Red, White, and Blue LED display with a potentiometer and a push button. Sounds easy, but also we will be using interrupts for this. So when the push button is pressed, the value from the potentiometer will set the brightness of the LEDs. The materials needed include:

-Arduino Uno R3

-breadboard

-male to male wires

-three LEDs (red, white, blue)

-potentiometer

-push button

-220ohm resistor

Step 1: Power and Ground

First, connect the ground and 5v power to the breadboard.

Step 2: Connecting LEDs

Place all three LEDs on the breadboard. Connect the cathode to the ground for each one. Connect a 220 ohm resistor to the anode and then connect that to the arduino, pins 9-11.

Step 3: Push Button

For the push button, make sure you connect it exactly in the picture. Power to power, 220ohm resistor to ground, and then opposite end to pin 3. This will be used as the interrupt.

Step 4: Potentiometer

Just like the push button, connect the potentiometer just like the picture shows. This will serve the purpose for adjusting the brightness.

Step 5: Possible Errors

Make sure the pins are connected like the code and pictures show, and that they match. Also, make sure the anode and cathode are connected accordingly.

Step 6: Code

const byte ledBlue = 11; //sets LED blue at pin 11
const byte ledRed = 10; //sets LED red at pin 10

const byte ledWhite = 9; //sets LED white to pin 9

const byte interruptPin = 3; //the push button as the interrupt

const byte potPin = 1; //potentiometer is pin A1

volatile int bright; //LEDbrightness

void setup() {

pinMode(ledBlue, OUTPUT); //blue LED as OUTPUT

pinMode(ledRed, OUTPUT); //red LED as OUTPUT

pinMode(ledWhite, OUTPUT); //white LED as OUTPUT

pinMode(interruptPin, INPUT_PULLUP); //button pin as INPUT_PULLUP

pinMode(potPin, INPUT); //potentiometer pin as INPUT

//sets up the interrupt with input pin and brightness to RISING

attachInterrupt(digitalPinToInterrupt(interruptPin), light, RISING);

}//end setup

void loop() {

analogWrite(ledBlue, bright); //Sets the blue LED to the set level of brightness

analogWrite(ledRed, bright); //Sets the red LED to the set level of brightness

analogWrite(ledWhite, bright); //Sets the white LED to the set level of brightness

}//end loop

void light() {

bright = analogRead(potPin); //Reads in value from potentiometer

bright = map(bright, 0, 1023, 0, 255); //Maps values for LED brightness

}//end brighter