Feedback Cube
B. Volta
Final Project
Using 4 RS04 ping sensors and a 300w 10″ powered subwoofer, feedback is generated as an individual approaches the 24″ x 24″ x 24″ gray cube. The feedback generated pulses in 3 typed and tones depending on the proximity of the user to the cube. Short bursts as one gets closer, long bursts when one is far away. Two switches are installed for convienience on the under lip of the gray cube. A 12v DC lead acid battery powers the sub woofer and a 9v battery powers the Arduino UNO and the 4 ping sensors. A 12v DC motor is also in place for future modifications to sound and generative feedback.
The code is as follows:
int l3 = 15; // Level 3 is very close, 20 inches or closer
int l2 = 40;// Level 2 is close
int l1 = 52; // Level 1 is nearby
int pingPin = 3; // Out trig
int echoPin = 4; // In echo
int grPin = 13; //green LED
//int r1Pin = 10; //red1 LED
//int r2Pin = 9; //red2 LED
void setup() {
// initialize serial communication:
Serial.begin(9600);
pinMode(grPin, OUTPUT); //sets the Green led pin to output
//pinMode(r1Pin, OUTPUT); //sets the Red1 led pin to output
//pinMode(r2Pin, OUTPUT); //sets the Red2 led pin to output
}
// Function to turn off all LEDs
void off(){
tone (grPin, LOW);
//digitalWrite(r2Pin, LOW);
//digitalWrite(grPin, LOW);
}
void loop()
{
// establish variables for duration of the ping,
// and the distance result in inches and centimeters:
// long duration, inches, cm;
long duration, inches, cm;
off();
// The HC-SR04 is triggered by a HIGH pulse of 2 or more microseconds.
// Give a short LOW pulse beforehand to ensure a clean HIGH pulse:
pinMode(pingPin, OUTPUT);
digitalWrite(pingPin, LOW);
delayMicroseconds(2);
digitalWrite(pingPin, HIGH);
delayMicroseconds(5);
digitalWrite(pingPin, LOW);
// The echoPin reads the returning Ultrasonic Ping: a HIGH
// pulse whose duration is the time (in microseconds) from the sending
// of the ping to the reception of its echo off of an object.
pinMode(echoPin, INPUT);
duration = pulseIn(echoPin, HIGH);
// convert the time into a distance
inches = microsecondsToInches(duration);
cm = microsecondsToCentimeters(duration);
Serial.print(inches);
Serial.print(“in, “);
Serial.print(cm);
Serial.print(“cm”);
Serial.println();
//digitalWrite(r1Pin, LOW);
//digitalWrite(r2Pin, LOW);
digitalWrite(grPin, LOW);
if (inches < 1500 && inches > l2)
{
tone(grPin,50);
delay(900);
noTone(grPin);
delay(600);
}
else off();
if (inches < l2 && inches > l3)
{
tone(grPin,75);
delay(300);
noTone(grPin);
delay(300);
}
else off();
if (inches < l3)
{
tone(grPin,96);
delay(400);
noTone(grPin);
delay(80);
}
else off();
off();
delay(50);
}
long microsecondsToInches(long microseconds)
{
return microseconds / 74 / 2;
}
long microsecondsToCentimeters(long microseconds)
{
return microseconds / 29 / 2;
}