I'm planning on using my Arduino Uno (Third revision) for an EL wire ambient lighting system in my car. I want to tap into an always on circuit in my car like the dome light fuse, and I was wondering whether I should use some sort of regulator so the spikes don't fry my Arduino. If so, do you have any suggestions? Should I have any problems wiring it into the Vin port?
Additional details:
4 separate 10 foot strands of EL Wire
Seeed EL Shield http://www.seeedstudio.com/depot/EL-Shield-p-1287.html?pageq=2
Seeed Robust EL Inverter http://www.seeedstudio.com/depot/robust-el-inverter-for-el-shield-p-1289.html
I'm going to use a potentiometer to control brightness and a button to cycle between off and four different colors.
I'm also going to put a switch between the power source and the Vin port.
Again, any advice you can give would be very appreciated.
mafrye5853
EDIT:
I wrote a test code (Below) and the for some reason CupValue starts a 1 for a few milliseconds. Any clue why this is happening? Also, could you give me a pointer on how to keep Cstate from changing so fast?
//Assign ports to EL and buttons
const int red = 5;
const int blue = 6;
const int green = 9;
const int purple = 10;
const int Bup = 11;
const int Bdown = 12;
const int Cup = 1;
const int Cdown = 2;
//Create brightness and color state
int Cstate = 1;
int Bstate = 200;
//Create variable for counting
int i = 0;
//Create variables to store the button values
int BupValue = 0;
int BdownValue = 0;
int CupValue = 0;
int CdownValue = 0;
int CupOld = 0;
int CdownOld = 0;
void setup()
{
Serial.begin(9600);
//Set EL's as outputs
pinMode(red, OUTPUT);
pinMode(blue, OUTPUT);
pinMode(green, OUTPUT);
pinMode(purple, OUTPUT);
//Set buttons as inputs
pinMode(Bup, INPUT);
pinMode(Bdown, INPUT);
pinMode(Cup, INPUT);
pinMode(Cdown, INPUT);
//Test red EL
analogWrite(red, 255);
analogWrite(blue, 0);
analogWrite(green, 0);
analogWrite(purple, 0);
delay(250);
//Test blue EL
analogWrite(red, 0);
analogWrite(blue, 255);
analogWrite(green, 0);
analogWrite(purple, 0);
delay(250);
//Test green EL
analogWrite(red, 0);
analogWrite(blue, 0);
analogWrite(green, 255);
analogWrite(purple, 0);
delay(250);
//Test purple EL
analogWrite(red, 0);
analogWrite(blue, 0);
analogWrite(green, 0);
analogWrite(purple, 255);
delay(250);
//Turn EL's off
analogWrite(red, 0);
analogWrite(blue, 0);
analogWrite(green, 0);
analogWrite(purple, 0);
delay(250);
// loop from 0 to 254 (fade in)
for (i = 0; i < 255; i++)
{
//Sets the EL brightness
analogWrite(red, i);
analogWrite(blue, i);
analogWrite(green, i);
analogWrite(purple, i);
delay(10); // Wait 10ms because analogWrite
// is instantaneous and we would
// not see any change
}
// loop from 255 to 1 (fade in)
for (i = 255; i > 0; i--)
{
//Sets the EL brightness
analogWrite(red, i);
analogWrite(blue, i);
analogWrite(green, i);
analogWrite(purple, i);
delay(10);
}
Cstate = 1;
Bstate = 200;
}
void loop()
{
//Read and store input value
BupValue = digitalRead(Bup);
BdownValue = digitalRead(Bdown);
CupValue = digitalRead(Cup);
CdownValue = digitalRead(Cdown);
//Increase Bstate by 10 if Bup is pressed
if(BupValue == HIGH) {
Bstate = Bstate + 1;
}
//Decrease Bstate by 10 if Bdown is pressed
if(BdownValue == HIGH) {
Bstate = Bstate - 10;
}
//Keep Bstate below 256
if(Bstate > 255) {
Bstate = 255;
}
//Keep Bstate above 0
if(Bstate < 0) {
Bstate = 0;
}
if(CupValue == HIGH && CupOld == LOW);
{
//Increse Cstate by 1 if Cup is pressed
if(CupValue == HIGH) {
Cstate = Cstate + 1;
}
}
if(CdownValue == HIGH & CdownOld == LOW);
{
//Decrease Cstate by 1 if Cdown is pressed
if(CdownValue == HIGH) {
Cstate = Cstate - 1;
}
}
//Let Cstate loop if it exceeds 4
if(Cstate > 4) {
Cstate = 1;
}
//Let Cstate loop if it drops below 1
if(Cstate < 1) {
Cstate = 4;
}
Serial.print(BupValue);
Serial.print(" Bup, ");
Serial.print(BdownValue);
Serial.print(" Bdown, ");
Serial.print(Bstate);
Serial.print(" Bstate, ");
Serial.print(CupValue);
Serial.print(" Cup, ");
Serial.print(CdownValue);
Serial.print(" Cdown, ");
Serial.print(Cstate);
Serial.print(" Cstate");
//What to do with different Cstates
switch (Cstate) {
//If Cstate is 1, set red to Bstate brightness
case 1:
analogWrite(red, Bstate);
analogWrite(blue, 0);
analogWrite(green, 0);
analogWrite(purple, 0);
break;
//If Cstate is 2, set blue to Bstate brightness
case 2:
analogWrite(red, 0);
analogWrite(blue, Bstate);
analogWrite(green, 0);
analogWrite(purple, 0);
break;
//If Cstate is 3, set green to Bstate brightness
case 3:
analogWrite(red, 0);
analogWrite(blue, 0);
analogWrite(green, Bstate);
analogWrite(purple, 0);
break;
//If Cstate is 4, set purple to Bstate brightness
case 4:
analogWrite(red, 0);
analogWrite(blue, 0);
analogWrite(green, 0);
analogWrite(purple, Bstate);
break;
//If, in some bizzare, inconceivable set of circumstances, Cstate has a value other than 1-4, flash red
default:
analogWrite(red, 255);
analogWrite(blue, 0);
analogWrite(green, 0);
analogWrite(purple, 0);
delay(250);
analogWrite(red, 0);
analogWrite(blue, 0);
analogWrite(green, 0);
analogWrite(purple, 0);
delay(250);
analogWrite(red, 255);
analogWrite(blue, 0);
analogWrite(green, 0);
analogWrite(purple, 0);
delay(250);
analogWrite(red, 0);
analogWrite(blue, 0);
analogWrite(green, 0);
analogWrite(purple, 0);
delay(250);
analogWrite(red, 255);
analogWrite(blue, 0);
analogWrite(green, 0);
analogWrite(purple, 0);
delay(250);
analogWrite(red, 0);
analogWrite(blue, 0);
analogWrite(green, 0);
analogWrite(purple, 0);
delay(250);
analogWrite(red, 255);
analogWrite(blue, 0);
analogWrite(green, 0);
analogWrite(purple, 0);
delay(250);
analogWrite(red, 0);
analogWrite(blue, 0);
analogWrite(green, 0);
analogWrite(purple, 0);
delay(250);
break;
CupOld = CupValue;
CdownOld = CdownValue;
}
}