Introduction: USA Arduino Interrupt LED Brightness

Picture of 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

Picture of Power and Ground

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

Step 2: Connecting LEDs

Picture of 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

Picture of 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

Picture of 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

Picture of 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

Comments

Swansong (author)2017-10-30

That's a neat setup :) Do you have any photos of the finished project?

About This Instructable

19views

0favorites

More by crockettcal:Arduino Micro Servo KeypadLED Row Fade ArduinoSimple IOT Alarm
Add instructable to: