Dual Potentiometer Lab

Description:

I used an Arduino-Uno as a microprocessor to light three LED lights, pulsing at a rate dependent on a reading from a potentiometer, and at a brightness dependent on a different potentiometer.

Components Used:

  • 1 Arduino
  • 3 LEDs (red, green, and blue)
  • 3 Resistor (220Ω)
  • 1 Breadboard
  • 2 Potentiometers

Code:

/*
 Analog Input
 Demonstrates analog input by reading an analog sensor on analog pin 0 and
 turning on and off a light emitting diode(LED) connected to digital pin 13.
 The amount of time the LED will be on and off depends on
 the value obtained by analogRead().

 The circuit:
 * Potentiometer attached to analog input 0
 * center pin of the potentiometer to the analog pin
 * one side pin (either one) to ground
 * the other side pin to +5V
 * LED anode (long leg) attached to digital output 13
 * LED cathode (short leg) attached to ground

 * Note: because most Arduinos have a built-in LED attached
 to pin 13 on the board, the LED is optional.


 Created by David Cuartielles
 modified 30 Aug 2011
 By Tom Igoe

 This example code is in the public domain.

 http://www.arduino.cc/en/Tutorial/AnalogInput

 */

int sensorPin = A0; // select the input pin for the potentiometer for pulse
int sensorPinBrightness = A1; 
int redledPin = 9;
int blueledPin = 10;
int greenledPin = 11; // select the pin for the LED
int sensorValue = 0; // variable to store the value coming from the sensor
int sensorValueBrightness = 0;

void setup() {
 // declare the ledPin as an OUTPUT:
 pinMode(redledPin, OUTPUT);
 pinMode(blueledPin, OUTPUT);
 pinMode(greenledPin, OUTPUT);
}

void loop() {
 // read the value from the sensor:
 sensorValue = analogRead(sensorPin);
 sensorValueBrightness = analogRead(sensorPinBrightness); 
 // turn the ledPin on
 digitalWrite(redledPin, HIGH);
 digitalWrite(blueledPin, HIGH);
 digitalWrite(greenledPin, HIGH);
 // adjust brightness
 analogWrite(redledPin, sensorValueBrightness/4); 
 analogWrite(blueledPin, sensorValueBrightness/4); 
 analogWrite(greenledPin, sensorValueBrightness/4); 
 // stop the program for <sensorValue> milliseconds:
 delay(sensorValue);
 // turn the ledPin off:
 digitalWrite(redledPin, LOW);
 digitalWrite(blueledPin, LOW);
 digitalWrite(greenledPin, LOW);
 // stop the program for for <sensorValue> milliseconds:
 delay(sensorValue);
}

49582925048__3F2AECA0-B12D-46AB-8157-6A311A04527E


			

Leave a Reply