Description:
To build this circuit diagram which controlls three LED lights through three potentiometers, I started with soldering the potentiometers. As can be seen in the photo, I carefully soldered three wires with each potentiometer. Then, I wired each potentiometer with three differently colored wires (green: 5V, red:ground, yellow:analog inputs), connecting into the breadboard. The analog inputs were connected to the A0, A1, and A2 on the Arduino side.
In the Sketchbook, I coded the program so that I can control both brightness and blinking of the Blue LED. For Red and Green LEDs, I coded in the way that potentiometers controlls only their brightness. For the Green LED, the maximum brightness is programed to be half of others.
The demo video is shown in the following site.
http://www.youtube.com/watch?v=TEbvjMiqNds
Components used:
1- Arduino Uno
1- Breadboard
3- 220ohms resistors
3- LED lights (red, green, blue)
21- Connecting wires
1- Ping pong ball (diffuser)
3 potentiometers
Code:
// Analog pin settings
int aIn = 0; // Potentiometers connected to analog pins 0, 1, and 2
int bIn = 1; // (Connect power to 5V and ground to analog ground)
int cIn = 2;
// Digital pin settings
int aOut = 9; // LEDs connected to digital pins 9, 10 and 11
int bOut = 10; // (Connect cathodes to digital ground)
int cOut = 11;
// Values
int aVal = 0; // Variables to store the input from the potentiometers
int bVal = 0;
int cVal = 0;
// Variables for comparing values between loops
int i = 0; // Loop counter
int wait = (1000); // Delay between most recent pot adjustment and output
int checkSum = 0; // Aggregate pot values
int prevCheckSum = 0;
int sens = 3; // Sensitivity theshold, to prevent small changes in
// pot values from triggering false reporting
// FLAGS
int PRINT = 1; // Set to 1 to output values
int DEBUG = 1; // Set to 1 to turn on debugging output
void setup()
{
pinMode(aOut, OUTPUT); // sets the digital pins as output
pinMode(bOut, OUTPUT);
pinMode(cOut, OUTPUT);
Serial.begin(9600); // Open serial communication for reporting
}
void loop()
{
i += 1; // Count loop
aVal = analogRead(aIn) / 4; // read input pins, convert to 0-255 scale
bVal = analogRead(bIn) / 4;
cVal = analogRead(cIn) / 8; //set maximum brightness of Green LED to half
analogWrite(aOut, aVal); // Send new values to LEDs
delay(aVal*3);
analogWrite(aOut, 0);
delay(aVal*3);
analogWrite(bOut, bVal);
analogWrite(cOut, cVal);
if (i % wait == 0) // If enough time has passed...
{
checkSum = aVal+bVal+cVal; // ...add up the 3 values.
if ( abs(checkSum - prevCheckSum) > sens ) // If old and new values differ
// above sensitivity threshold
{
if (PRINT) // ...and if the PRINT flag is set...
{
Serial.print("Blue: "); // ...then print the values.
Serial.print(aVal); //when the input of Blue LED from the potentiometers is not 0, it won't allow printing
Serial.print("\t");
Serial.print("Red: ");
Serial.print(bVal);
Serial.print("\t");
Serial.print("Green: ");
Serial.println(cVal);
PRINT = 0;
}
}
else
{
PRINT = 1; // Re-set the flag
}
prevCheckSum = checkSum; // Update the values
if (DEBUG) // If we want debugging output as well...
{
Serial.print(checkSum);
Serial.print("<=>");
Serial.print(prevCheckSum);
Serial.print("\tPrint: ");
Serial.println(PRINT);
}
}
}
- Login to post comments