ARDUINO GROUP DIMMING TUTORIAL
INTRODUCTION
Arduino is a
microcontroller which can be programmed to do certain operations like lighting
led, controlling servo, etc. This is a DIY Arduino project intended to achieve
group dimming of LED’s. The group dimming or segregated dimming gives the
flexibility of dimming a batch of LED’s at a time rather than dimming all at
once. Group dimming is best observed during light shows where different colors
of lights fade at different time. Dimming or fading is a process of gradually
increasing or decreasing the brightness of light. The group dimming setup
consists of 9 LED’s (3 each of red, white and blue). The 3 LED’s switch on and
off gradually within a specified time. The delay time or the time interval used
here is 200 millisecond.
COMPONENTS
REQUIRED
1. Perfboard
and Breadboard
2. Arduino
Mega 2560 and USB cable
3. 5mm
Red LED’s (3)
4. 5mm
White LED’s (3)
5. 5mm
Blue LED’s (3)
6. 20
Ohm resistors (9)
7. Jumpers
8. A 5V DC Power supply
CIRCUIT SCHEMATICS
Fig1 Group dimming schematic |
Make
the appropriate connections as shown in the schematic above
CODE
This
is the code for simulating Group fading or dimming of LED’s. Note that this
code is valid only for the particular schematic represented in figure1. The
values and choice of ports can always be changed but ensure only analog pins or
PWM pins are selected. Analog pins are usually marked with a ‘~’ in front of
the pin number. You must use Arduino Mega Board since it contains 12 PWM pins
and we require 9 PWM pins. Copy and paste the code in Arduino IDE sketch area.
/*
Group
LED dimming/fading
This
example shows how to fade LED in groups
use
Arduino mega, it has PWM pins 2 through 13
Created
by Srinath Srinivasan
This
code is in the public domain
*/
int
ledPin1 = 2; // LED connected to PWM
pin 2
int
ledPin2 = 3; // LED connected to PWM
pin 3
int
ledPin3 = 4; // LED connected to PWM
pin 4
int
ledPin4 = 5; // LED connected to PWM
pin 5
int
ledPin5 = 6; // LED connected to PWM
pin 6
int
ledPin6 = 7; // LED connected to PWM
pin 7
int
ledPin7 = 8; // LED connected to PWM
pin 8
int
ledPin8 = 9; // LED connected to PWM
pin 9
int
ledPin9 = 10; // LED connected to PWM
pin 10
void
setup() {
// nothing happens in setup
}
void
loop() {
// fade
in from min to max in increments of 5 points:
for (int fadeValue = 0 ; fadeValue <= 255;
fadeValue += 5) {
// sets the value (range from 0 to 255):
analogWrite(ledPin1, fadeValue);
analogWrite(ledPin2, fadeValue);
analogWrite(ledPin3, fadeValue);
// wait for 200 milliseconds to see the
dimming effect
delay(200);
}
for (int fadeValue = 0 ; fadeValue <= 255;
fadeValue += 5) {
// sets the value (range from 0 to 255):
analogWrite(ledPin4, fadeValue);
analogWrite(ledPin5, fadeValue);
analogWrite(ledPin6, fadeValue);
// wait for 200 milliseconds to see the
dimming effect
delay(200);
}
for (int fadeValue = 0 ; fadeValue <= 255;
fadeValue += 5) {
// sets the value (range from 0 to 255):
analogWrite(ledPin7, fadeValue);
analogWrite(ledPin8, fadeValue);
analogWrite(ledPin9, fadeValue);
// wait for 200 milliseconds to see the
dimming effect
delay(200);
}
// fade out from max to min in increments of
5 points:
for (int fadeValue = 255 ; fadeValue >= 0;
fadeValue -= 5) {
// sets the value (range from 0 to 255):
analogWrite(ledPin1, fadeValue);
analogWrite(ledPin2, fadeValue);
analogWrite(ledPin3, fadeValue);
// wait for 200 milliseconds to see the
dimming effect
delay(200);
}
for (int fadeValue = 255 ; fadeValue >= 0;
fadeValue -= 5) {
// sets the value (range from 0 to 255):
analogWrite(ledPin4, fadeValue);
analogWrite(ledPin5, fadeValue);
analogWrite(ledPin6, fadeValue);
// wait for 200 milliseconds to see the
dimming effect
delay(200);
}
for (int fadeValue = 255 ; fadeValue >= 0;
fadeValue -= 5) {
// sets the value (range from 0 to 255):
analogWrite(ledPin7, fadeValue);
analogWrite(ledPin8, fadeValue);
analogWrite(ledPin9, fadeValue);
// wait for 200 milliseconds to see the
dimming effect
delay(200);
}
}
No comments:
Post a Comment