Relaysquid_sensor_light_control_small
Reddit Twitter Digg Facebook Delicious Stumbleupon
10 images, 3 parts

RelaySquid light show

I’ve always wanted to make this project, and I finally got to with the RelaySquid (I’m kinda excited about it)... ha. Anyway, this project uses the Parallax sonar Ping sensor (which is a distance sensor), an Arduino, a RelaySquid, and four halogen spotlights. As I move my hand in front of the lights, the sonar sensor detects how far away my hand is, and turns on the light directly underneath my hand. It makes me feel like I’m controlling the lights with just my thoughts! I’m going to try to extend this project to make a virtual, interactive visualizer or equalizer at some point :)

Parts for RelaySquid light show:

The first thing I did was build the circuit with the Parallax Ping sonar sensor, and the Arduino. It wasn’t too hard, either, because all the code existed already, so I was done in like 10 minutes! I followed the directions on the package insert of the Parallax sensor, which told me to connect the far left side pin to Ground, the middle pin to +5v, and the far right pin was the signal pin.

I connected the far right signal pin to Arduino pin 8 (I could have chosen any other digital IO pin). Then, I knew I wanted to control the lights on the RelaySquid with the Arduino, so I used longer wires to connect Arduino pin 4 to RelaySquid port 1, Arduino pin 5 to port 2, pin 6 to port 3, and pin 7 to port 4. The RelaySquid has 4 ports, and I’m using all of them :) However, the RelaySquid also need +5v and Ground, so I took two more longer wires and connected them between the Arduino’s pins and the RelaySquid’s pins.

Here’s a side shot of what the RelaySquid looks like:

I didn’t want to have the Arduino plugged into the computer or power outlet all the time, so I decided to power the whole circuit with a Lithium BackPack:

The last step was to upload the source code to the Arduino, which took advantage of an older function I wrote to read the sonar sensor’s pin (I built the function a long time ago using the instructions on the insert to read the wave form).

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73

//Parallax sonar detector
//Open source from Matt at http://antipastohw.blogspot.com/
void setup()
{
Serial.begin(9600);
Serial.println("Sonar detector");
delay(100);
}

//Here's the readSonar function - pass it the pin of the 
//signal wire from the Sonar sensor, and it will return a 
//long of the distance. If you wanted to use the Sonar 
//module in your own projects, just grab this function, 
//and drop it into your own code!

long readSonar( int signalpin) {
int readsignal = 0;
long counttime = 0;

pinMode(signalpin, OUTPUT);
digitalWrite(signalpin, LOW);
digitalWrite(signalpin, HIGH);
delayMicroseconds(4);
digitalWrite(signalpin, LOW);

pinMode(signalpin, INPUT);

readsignal = digitalRead(signalpin);
while (readsignal == LOW) {
readsignal = digitalRead(signalpin);
}

counttime=0;
while (readsignal == HIGH) {
readsignal = digitalRead(signalpin);
counttime++;
}

return counttime;
}

//Here's the main loop:
void loop()
{
long distance = 0;
int a1,a2,a3,a4;

distance = readSonar(8); //here's where I call the function

Serial.print("Value: ");
Serial.println(distance);

a1=0;a2=0;a3=0;a4=0;
if (distance < 150) {
  a1=1;
} else if ((200 < distance) && (distance < 280)) {
  a2=1;
} else if ((300 < distance) && (distance < 450)) {
  a3=1;
} else if ((475 < distance) && (distance < 650)) {
  a4=1;
} else {

}
digitalWrite(4,a1);
digitalWrite(5,a2);
digitalWrite(6,a3);
digitalWrite(7,a4);

delay(100);
}

0 Comments on RelaySquid light show



Add A Comment: