Description:
In light of recent events on campus, I thought to construct a campanile like object that contains a tiny crevice for a tiny block of "copper". When the copper is removed from this little crevice, the alarm systems of the campanile go off, playing annoying alarm sounds and blaring red lights to simulate the fire that will ensue.
Components:
1x Arduino
1x LED
1x FSR
1x Piezo speaker
Code:
/* Campanile Copper Alarm System */
/*
if (FSR input < certain_val) {
LEDs go off;
Piezo speakers go off
}
else {
Silence. and Peacefulness
}
*/
int ledPin = 13;
int speakerOut = 7;
byte names[] = {'c', 'd', 'e', 'f', 'g', 'a', 'b', 'C'};
int tones[] = {1915, 1700, 1519, 1432, 1275, 1136, 1014, 956};
byte melody[] = "2d2a1f2c2d2a2d2c2f2d2a2c2d2a1f2c2d2a2a2g2p8p8p8p";
// count length: 1 2 3 4 5 6 7 8 9 0 1 2 3 4 5 6 7 8 9 0 1 2 3 4 5 6 7 8 9 0
// 10 20 30
int count = 0;
int count2 = 0;
int count3 = 0;
int MAX_COUNT = 24;
int statePin = LOW;
int sensorPin = 0; //input pin for the sensor FSR
int ledPin = 11; // select the output pin for the LED
void setup() {
pinMode(ledPin, OUTPUT);
pinMode(speakerOut, OUTPUT);
Serial.begin(9600);
}
void loop() {
val = analogRead(sensorPin); //read the value from the sensor 0-1023
if (val > 500) {
}
else {
digitalWrite(speakerOut, LOW);
for (count = 0; count < MAX_COUNT; count++) {
statePin = !statePin;
digitalWrite(ledPin, statePin);
for (count3 = 0; count3 <= (melody[count*2] - 48) * 30; count3++) {
for (count2=0;count2<8;count2++) {
if (names[count2] == melody[count*2 + 1]) {
digitalWrite(speakerOut,HIGH);
delayMicroseconds(tones[count2]);
digitalWrite(speakerOut, LOW);
delayMicroseconds(tones[count2]);
}
if (melody[count*2 + 1] == 'p') {
// make a pause of a certain size
digitalWrite(speakerOut, 0);
delayMicroseconds(500);
}
}
}
}
}
}
- Login to post comments