Lab 3 – 3 Potentiometers to Control 3 LEDs

Description

I used an Arduino-Uno as a microprocessor to control the brightness of three LED lights, realized through three different rates, which are translated from data fed in from three different potentiometers.

Components

  • 1 Arduino Uno
  • 1 Breadboard
  • 3 LEDs (red, green, and blue)
  • 3 Resistor (220Ω)
  • 3 Potentiometers
  • 1 USB Cable
  • 21 Jumper Wires
  • 1 Laptop

Code

int sensorPin1 = A0; // select the input pin for the potentiometer
int sensorPin2 = A1; // select the input pin for the potentiometer
int sensorPin3 = A2; // select the input pin for the potentiometer
int ledPin1 = 9; // select the pin for the LED
int ledPin2 = 10; // select the pin for the LED
int ledPin3 = 11; // select the pin for the LED

int sensorValue1 = 0; // variable to store the value coming from the sensor
int sensorValue2 = 0; // variable to store the value coming from the sensor
int sensorValue3 = 0; // variable to store the value coming from the sensor

void setup() {
 // declare the ledPin as an OUTPUT:
 pinMode(ledPin1, OUTPUT);
 pinMode(ledPin2, OUTPUT);
 pinMode(ledPin3, OUTPUT);
 Serial.begin(5600);

}

void loop() {
 // read the value from the sensor:
 sensorValue1 = analogRead(sensorPin1);
 sensorValue2 = analogRead(sensorPin2);
 sensorValue3 = analogRead(sensorPin3);

 // turn the ledPin on
 analogWrite(ledPin1, sensorValue1/5);
 analogWrite(ledPin2, sensorValue2/5);
 analogWrite(ledPin3, sensorValue3/5);
}

Photo

IMG_0677

Leave a Reply