Just wanted to send an update and perhaps some insight for others that use these relays....and perhaps get some advice.
As a recap, I wanted to control flashing sequence of glass block christmas decorations I made last year. Basically flashing them to music. I did purchase the SainSmart 8 channel relay (mechanical, not solid state) and although they are loud, I am able to mute the clicking enough with a box and insulation. At first, I powered the relay from the Arduino power. Big mistake, the regulator chip was so hot it damn near burned my finger. I figured it was a power issue and after some reading on line I realized I should supply both the Arduino and the relay with their own power supplies.
My sketch is working well (included below) based on readings from the analog pin 5....which is connected to headphone output from laptop, iPhone, iPod, etc. Be careful, I was using an old boom box with Line In connections to piggy back the headphone feed so I could hear the music while feeding it to the analog pin, and there seemed to be a loop back voltage or spike that disabled my USB connections from the laptop. Freaked out for a while thinking I blew the USB port, but a hard reboot brought them back (whew...changed connections to isolate my poor Arduino and laptop). I've included the sketch just in case someone wants to copy and mess with it.
My question is this....What I really want to do is read frequency ranges, so that I can flash specific lights based on (or at least associated closely with) notes from instruments or singing. I was able to build a project (my first) where the Arduino plays a song by using the tones and melody controls. I mapped all the notes and delays to play the song and it worked pretty well. I've also seen projects that use Vixen to map light sequencing to the music patterns, but that means you have to map every song. I'd like to read the analog input and sequence from whatever song was being fed to Arduino on-the-fly - so to speak. I'm thinking I have to use an A to D (or the other way around) converter to be able to capture notes or frequencies, but I'm not sure. And...since just about everything in life is math, I would think there is a way to do it with calculations against the readings in the analog input.
I have photos and a video of this project, so if someone is interested just let me know and I can post them or provide links.
So there's the update. Thanks to the smart people on this forum for their continued assistance and knowledge.
(Be kind, you'd have to have a vivid imagination to call me a programmer.)
/* Lights to Music Analog Input (pin A5) via Headphone Output
* --------------
*
* @author: rfbase
* @hardware: Arduino Uno
* SainSmart 8 Channel DC 5V Relay Module - therefore the digitalWrite(relayPinX...) is driving LOW
* Sending data from a headset outlet on laptop, iPhone, or iPod - volume is typically very high on the client device
* Analog read is typically between 10 and 140 with the volume all the way up
*/
unsigned char relayPin2 = {2};
unsigned char relayPin3 = {3};
unsigned char relayPin4 = {4};
unsigned char relayPin5 = {5};
unsigned char relayPin6 = {6};
unsigned char relayPin7 = {7};
unsigned char relayPin8 = {8};
unsigned char relayPin9 = {9};
int analogPin = 5;
int sensorValue = 0;
int pause = 85;
void setup(){
Serial.begin(9600);
pinMode(relayPin2,OUTPUT);
pinMode(relayPin3,OUTPUT);
pinMode(relayPin4,OUTPUT);
pinMode(relayPin5,OUTPUT);
pinMode(relayPin6,OUTPUT);
pinMode(relayPin7,OUTPUT);
pinMode(relayPin8,OUTPUT);
pinMode(relayPin9,OUTPUT);
}
void loop() {
sensorValue = analogRead(analogPin); // read the data/voltage from the input pin
if (sensorValue > 10 and sensorValue < 17) { //if the voltage is in this range hit the LED
digitalWrite(relayPin2,LOW);
delay(pause);
digitalWrite(relayPin2,HIGH);
Serial.println(sensorValue);
}
if (sensorValue > 18 and sensorValue < 22) { //if the voltage is in this range hit the LED
digitalWrite(relayPin3,LOW);
delay(pause);
digitalWrite(relayPin3,HIGH);
Serial.println(sensorValue);
}
if (sensorValue > 23 and sensorValue < 28) { //if the voltage is in this range hit the LED
digitalWrite(relayPin4,LOW);
delay(pause);
digitalWrite(relayPin4,HIGH);
Serial.println(sensorValue);
}
if (sensorValue > 29 and sensorValue < 35) { //if the voltage is in this range hit the LED
digitalWrite(relayPin5,LOW);
delay(pause);
digitalWrite(relayPin5,HIGH);
Serial.println(sensorValue);
}
if (sensorValue > 36 and sensorValue < 48) { //if the voltage is in this range hit the LED
digitalWrite(relayPin6,LOW);
delay(pause);
digitalWrite(relayPin6,HIGH);
Serial.println(sensorValue);
}
if (sensorValue > 49 and sensorValue < 59) { //if the voltage is in this range hit the LED
digitalWrite(relayPin7,LOW);
delay(pause);
digitalWrite(relayPin7,HIGH);
Serial.println(sensorValue);
}
if (sensorValue > 60 and sensorValue < 69) { //if the voltage is in this range hit the LED
digitalWrite(relayPin8,LOW);
delay(pause);
digitalWrite(relayPin8,HIGH);
Serial.println(sensorValue);
}
if (sensorValue > 70) { //if the voltage is above 70 hit the LED
digitalWrite(relayPin9,LOW);
delay(pause);
digitalWrite(relayPin9,HIGH);
Serial.println(sensorValue);
}
}