Showing posts with label computer. Show all posts
Showing posts with label computer. Show all posts

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.

IMG_0033[1]

 

// 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);
}
else{
digitalWrite(Relay_2, RELAY_OFF);
}

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

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

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

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

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

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


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

Sunday, March 25, 2012

my linux today

I am doing some construction on my new site so i redirected everyone to the old site for Entre drops for today while I get everything put back together, I just didnt have time the last few weeks to sort it all out.

Sunday, October 30, 2011

Collage Creater

Today I was in need of a program to create a collage of pictures for something and I discovered this program that seems to fit my needs nicely. just thought I might share it.

Monday, October 3, 2011

Ubuntu 11.04

So today I made the jump and updated to Ubuntu's Natty release I will admit I did my research on it and tried the live cd first and was a little concerned with the Unity desktop but I updated anyhow.


I used it with the Unity desktop for a few hours and then reverted back to Gnome, I then discovered that I had become accustomed to Unity and for some strange reason It appeals to me.Now i'm sure its not for everyone and you do have the option of switching to the classic look on the login screen.



Here is a great page with a lot of useful tips for anyone who decides to try for themselves. I am going to stick to the Unity desktop for a while and I will do a follow up post. I am also installing it on a family members computer this coming weekend, she is using Mandriva at the moment but wishes to try Ubuntu.

Sunday, October 2, 2011

HAF case


I recently got a new case for myself the its a Cooler master HAF case, I really like the fact that you can easily hide the wires inside of it, the power supply is also on the bottom. The air flow in the case is remarkable compared to my old case. Wish I had  got one sooner. I also like the Hard drive tray they use its simple to exchange drives quickly.








It also came with two 120mm fans installed and I installed two more and a fan controller.

Wednesday, September 21, 2011

Dusty System

It always seems that whenever someone asks me to look at a computer its usually a complete mess inside as far as dust and pet hair, A clogged up heat sink can fry your system quick and it also makes cool popping sounds.

Needless to say if money is no object to you then don't worry about cleaning out your computer however if you are frugal like me then you should try and clean your computer out once a month or so. The compressed air works great or a shop vac with the hose reversed to blow air (be mindful not to get to close) this one was just dropped off to me this evening but i believe its got more serious problems than some dirt.

Friday, April 29, 2011

Computer Prank

I ran across this today and thought I would share it.