Sensing: Potentiometers

Assignment: Sensing: Potentiometers

Collaborators:

Assignment: Sensing: Potentiometers
Collaborators:

 

Description


The goal of this assignment was to learn how to use analog inputs in Arduino. We also got to brush up on our soldering skills.

 

 

Components Used


The following components were used:

  • Arduino
  • Breadboard
  • Rubber band (2)
  • USB cable
  • Jumper Cables (several)
  • 220 Ohm resistor (3)
  • LED light (3: red, green, and blue)
  • Potentiometer (2)

 

Arduino Code


The following code allows two potentiometers to be used to control three blinking LEDs. The first controls the rate at which the colors are cycled through, and the second controls the brightness of the LEDs.

/*
* AnalogInputWithPots
* by Eric Mai
* for i262 Fall 2009, HW #3
* September 23, 2009
*
* Allows three LEDs to be controlled by two potentiometers. The
* brightness of all three is controlled by the first and the
* rate at which the colors are cycled through (blinking) is controlled
* by the other.
*
*/

int potPin = 1; // select the input pins for the potentiometers
int potPin2 = 2;

int ledPin = 9; // select the pins for the LEDs
int ledPin2 = 10;
int ledPin3 = 11;

int potVal = 0; // variables to store the value coming from the pots
int potVal2 = 0;

void setup() {
pinMode(ledPin, OUTPUT); // declare the ledPins as OUTPUTs
pinMode(ledPin2, OUTPUT);
pinMode(ledPin3, OUTPUT);
}

void loop() {
potVal = analogRead(potPin); // read the values from the pots
potVal2 = analogRead(potPin2);

analogWrite(ledPin, potVal2/4); // set ledPin to potVal2's brightness
delay(potVal);
analogWrite(ledPin, 0);
analogWrite(ledPin2, potVal2/4);
delay(potVal);
analogWrite(ledPin2, 0);
analogWrite(ledPin3, potVal2/4);
delay(potVal);
analogWrite(ledPin3, 0);
}

Pictures