Monday, October 14, 2013

Sainsmart 8 Channel Relay

I recently purchased a Sainsmart 8 channel relay for use with some holiday lighting with my Arduino, I had some sketches already typed up for use with another project however I soon discovered that the relay board does not simply turn off with the normal LOW command with the digital output pins.I basically spent half a day writing up a new sketch and trying it until I got it to perform the way that I wanted it to. I have an ITEAD Mp3 shield I am using with it, so I cant guarantee this sketch will work for anyone else, But it’s a starting point since I found hardly any information on this relay board.This page is the best information I found but it only loops the relays so I had to us his example to formulate the code to do as I wished.If you look at your serial output and adjust the sense limit and smoothing you can get it to react to some some degree to the music.



// Sainsmart 8 channel relay v1.0

#define NUMREADINGS 70 // raise this number to increase data smoothing

int senseLimit = 400; // raise this number to decrease sensitivity (up to 1023 max)
int probePin = 3; // analog 3
int val = 0; // This is the reading from the probePin

#define RELAY_ON 1
#define RELAY_OFF 0

#define Relay_1 4 // Arduino Digital I/O pin number
#define Relay_2 5
#define Relay_3 6
#define Relay_4 7
#define Relay_5 8
#define Relay_6 9
#define Relay_7 10
#define Relay_8 11

// variables for smoothing

int readings[NUMREADINGS]; // the readings from the current analog input
int index = 0; // the index of the current reading
int total = 8; // the running total (Realys)
int average =0; // final average of the probe reading

void setup() {

pinMode(Relay_8, OUTPUT); // specify Relay Outputs
pinMode(Relay_7, OUTPUT);
pinMode(Relay_6, OUTPUT);
pinMode(Relay_5, OUTPUT);
pinMode(Relay_4, OUTPUT);
pinMode(Relay_3, OUTPUT);
pinMode(Relay_2, OUTPUT);
pinMode(Relay_1, OUTPUT);

Serial.begin(9600); // initiate serial connection for debugging/etc

for (int i = 0; i < NUMREADINGS; i++)
readings[i] = 0; // initialize all the readings to 0

void loop() {

val = analogRead(probePin); // take a reading from the probe

if(val >= 1){ // if the reading isn't zero, proceed

val = constrain(val, 1, senseLimit); // turn any reading higher than the senseLimit value into the senseLimit value
val = map(val, 1, senseLimit, 1, 1023); // remap the constrained value within a 1 to 1023 range

total -= readings[index]; // subtract the last reading
readings[index] = val; // read from the sensor
total += readings[index]; // add the reading to the total
index = (index + 1); // advance to the next index

if (index >= NUMREADINGS) // if we're at the end of the array...
index = 0; // ...wrap around to the beginning

average = total / NUMREADINGS; // calculate the average

if (average > 250){ // if the average is over 250 ...
digitalWrite(Relay_1, RELAY_ON); // Turn on the first Relay*
else{ // and if it's not ...
digitalWrite(Relay_1, RELAY_OFF); // turn that Relay off

if (average > 300){ // and so on ...
digitalWrite(Relay_2, RELAY_ON);
digitalWrite(Relay_2, RELAY_OFF);

if (average > 350){
digitalWrite(Relay_3, RELAY_ON);
digitalWrite(Relay_3, RELAY_OFF);

if (average > 375){
digitalWrite(Relay_4, RELAY_ON);
digitalWrite(Relay_4, RELAY_OFF);

if (average > 400){
digitalWrite(Relay_5, RELAY_ON);
digitalWrite(Relay_5, RELAY_OFF);

if (average > 450){
digitalWrite(Relay_6, RELAY_ON);
digitalWrite(Relay_6, RELAY_OFF);

if (average > 550){
digitalWrite(Relay_7, RELAY_ON);
digitalWrite(Relay_7, RELAY_OFF);

if (average > 600){
digitalWrite(Relay_8, RELAY_ON);
digitalWrite(Relay_8, RELAY_OFF);

Serial.println(val); // use this output to aid in calibrating

Tuesday, April 9, 2013

Raspberry PI Case


I finally bought a case for my Raspberry PI, this case was much better than I had expected, It fit perfectly and even has light tubes for the led’s so you can see them.



I am running XBMC on mine at the moment, It seems to work flawlessly, I am very pleased with it so far It streams fine over my network and I can hardly notice it on my entertainment center.

Wednesday, March 6, 2013

My New Project

I received my new Raspberry PI yesterday. Took me a few minutes to get it all figured out and Debian Loaded up but here we are.I am actually doing this post from it as i wanted to try out its internet capabilities.I have it hooked up by HDMI to a 32" tv and have not had any issues with speed or anything so far. I can see many uses for these as they are a very inexpensive type of technology. More to follow..

Here is a picture of it in action.

Sunday, March 3, 2013

Hard Drive Replacement

Today I was in a bind with an OEM win 7 and a failing hard drive, LINUX to the rescue. I had a new Western digital hard drive for the swap, However the software they recommend Acronis True Image sounds ok but refused to do the task at hand, I checked my ISO image no problems there, Arronis just kept locking up and rebooting at the selection screen when I tried to select my source drive. Not to worry I new there were a few flavors of a LINUX clone out there. After a few searches I found REDO Backup and Recovery (and its free). After a quick download and burn I had the OEM on its way to a new home, The whole process took maybe 2 hours, So with a little patience I got everything moved and back up and running and no more disc error message. I was worried some of the data might have been corrupt but so far it all seems ok.

On another note I ordered an Raspberry PI the other day and I cant wait till it gets here.I got revision B with Ethernet and HDMI out,I am rather interested in how much it can handle for the size of it. My intentions are to use it in some form for my personal weather station to transmit to the web.

Sunday, February 24, 2013


I have been playing around with my arduino I have never really spent a lot of time getting my Ethernet shield working, Today I set out to try and get it so I could read the sd card from a browser without a whole lot of trouble, all went very quick, Now I am going to move forward now that I have the Arduino communicating . what I am thinking about is doing something with home automation as far as my HVAC equipment, I am not sure how intense its going to get or if its even worth my time.

Screenshot at 2013-02-24 19_03_41

I have also been looking at the Raspberry PI as my next platform to build on. I have wanted to get one for a while now and finally getting around to it.

Sunday, February 17, 2013

Back Again

I was paying for hosting and such but I really didn’t have the time to devote to it and it didn’t make sense for me to keep paying for a service I wasn’t able to keep up with. I never deleted this blog It just kind of sat here in limbo so I decided to start using it again. So I am going to try and get things going on here again and try my best to keep up with it.I do still use LINUX I have been using LINUX mint for the past few months and I really like it a lot, I also installed LINUX mint on my moms computer a while back and she loves it.It is based on UBUNTU however I like it better and it hasn’t let me down yet.