Showing posts with label JAVA. Show all posts
Showing posts with label JAVA. 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
}
}

Wednesday, March 4, 2009

Enable JAVA In OPERA

I like a fast browser and it seems FireFox has been somewhat sluggish lately so I installed OPERA i was amazed that everything except java worked immediately.I have been using it for a few minutes and so far I like it I am going to give it a workout and see how well it holds up. as for getting java to work assuming you allready have the latest version installed on your computer, if you go to Tools/preferences/advanced/content on the toolbar of OPERA you can enable java and then you must point opera in the directory where your java is stored.


From linux if you have trouble finding java you can go to the terminal and put in
[find / -name libjava.so 2> /dev/null ] That will tell you the location to put in the opera window. now you can validate the java plugin to be sure it works. Thats it now you can enjoy a fast browser.