arduinoAlarm

/*
This code is show how Arduino Wave Module works with Arduino and alarm implementation
Code is not optimized. Any improving work on it is encouraged.
http://sites.google.com/site/venvirupa/arduinoa it is made with a wave shield a Arduino Uno and a computer speaker system to give you a personal alarm in your bedroom when your front house door opens 
Features:

30 second activation delay lets you leave house before alarm starts ( not very usefull yet as a away alarm as it only rings in your bedroom with computer speaker power so external audibility isnt great for neighbours etc ..... but you could put more powerful speakers or pre amplfier here ( circuit required )).

Alarm latches on state so if door is closed you stilll get alarm until the user resets

*/
int RST = 3;
int CLK = 9;
int DAT = 8; 
const int buttonPin = 12;     // the number of the pushbutton pin
const int ledPin =  13;      // the number of the LED pin
int buttonState = 1;  unsigned long time;
int activatedbool = 0;
    
    
void setup() {   
    
    
    pinMode(RST, OUTPUT);
    pinMode(CLK, OUTPUT); 
    pinMode(DAT, OUTPUT);
    // initialize the LED pin as an output:
  pinMode(ledPin, OUTPUT);      
  // initialize the pushbutton pin as an input:
  pinMode(buttonPin, INPUT); 
    
    
    digitalWrite(RST, HIGH);
    digitalWrite(CLK, HIGH);
    digitalWrite(DAT, HIGH);
    
    digitalWrite(RST, LOW);
    delay(5);
    digitalWrite(RST, HIGH);
    delay(300);Serial.begin(9600);
}

void loop() {
// read the state of the pushbutton value:
  buttonState = digitalRead(buttonPin);
   // check if the magnetic switch is activated or is pressed.
  // if it is, the buttonState is HIGH: time = millis();  Serial.println(time);
 time = millis();  //Serial.println(time);
//delay(1000);

  if (buttonState == LOW) {   
 // 30 second delay to leave active zone
  if (time > 30000) { activatedbool = 1;

    send(0x0000);//play file 0000.wav (alarm 8 bit wave sound
     delay(3000);//delay 10 seconds
  }
  }
  // if alarm has been activated then latch on and continue
  // even if tester has closed the door alarm only stop on power down
  // of microcontroller
  
  if (activatedbool == 1) {
  
  send(0x0000);
  delay(3000);
  }
  send(0xfffe);//play
  
  
  
 // while(100);
}
void send(int data)
{
  digitalWrite(CLK, LOW);
  delay(2);
  for (int i=15; i>=0; i--)
  { 
    delayMicroseconds(50);
    if((data>>i)&0x0001 >0)
      {
        digitalWrite(DAT, HIGH);
        //Serial.print(1);
      }
    else
       {
         digitalWrite(DAT, LOW);
        // Serial.print(0);
       }
    delayMicroseconds(50);
    digitalWrite(CLK, HIGH);
    delayMicroseconds(50);
    
    if(i>0)
    digitalWrite(DAT, LOW);
    else
    digitalWrite(DAT, HIGH);
    delayMicroseconds(50);
    
    if(i>0)
    digitalWrite(CLK, LOW);
    else
    digitalWrite(CLK, HIGH);
  }
  
  delay(20); 
}
ċ
arduinoWave.ino
(2k)
Stephen P,
Jan 22, 2013, 1:23 PM
Comments