Pages: [1]   Go Down
Author Topic: Universal Alarm System. Need Help  (Read 795 times)
0 Members and 1 Guest are viewing this topic.
Offline Offline
Newbie
*
Karma: 0
Posts: 2
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

Greetings everybody!

I'm in a bit of rush, I'm working on my final High-school project that need to be finished ASAP.
I'm working on universal alarm system that could be mounted pretty much anywhere (but so far its oriented towards houses and cars).

Ok, to the point, I'm running Arduino Uno R2 and I desperately need to hook it up to a Nokia 3310 to send SMS every time the alarm goes off (I don't have money for appropriate shield). Can someone send me links with schematics, codes and tutorials on how to mount it. Also i want to use Nokia's battery as a backup power source.

So far I have mounted PIR sensor, Piezoelectric speaker (to detect vibration) and magnetic field detector as my main sensors (which unfortunately all gave me false-positive and false-negative output during my lest preservation). I'd also appreciate ideas for new sensors and upgrades for present ones.
I'm currently working on creating infrared tripwire (it should work with PIR sensor to prevent it being triggered by small house animals) and a smoke detector (based on a CD-player laser). Also it would be great to be able to control alarm via cellphone by sending SMS.

P.S. When I finish the project I am going to release code, schematics and assembly tutorial to the Arduino community for home assembly.
Logged

Offline Offline
Full Member
***
Karma: 2
Posts: 175
View Profile
WWW
 Bigger Bigger  Smaller Smaller  Reset Reset

Hello,I have a similar project there http://www.power7.net/GSM_tutorial.html
You can modify it to sends SMS or call to administrator number( without cost ) when digitalRead(pinAlarmSensor) == HIGH from an Alarm sensor.....
« Last Edit: June 07, 2013, 05:30:52 am by power7net » Logged

Web / sms / bluetooth / arduino / android remote control. Home Automation projects.
http://www.power7.net

Offline Offline
Newbie
*
Karma: 0
Posts: 2
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

Thanks a lot power7net that helped a lot!
I have a new problem though. I have to present my project to my teachers for pre-evaluation tomorrow, but I have this new bug in my project. Here's the code:
Code:
//CONST
  //UNIVERSAL
    const int ledPin1 = 13;
    const int ledPin2 = 12;
    const int ledPin3 = 11;
    const int ledPin4 = 10;
    const int speaker = 9;
    const int onoff = 4;
  //PIR SENSOR
    const int pirPin = 8;
    const int calibrationTime = 15;
    const long unsigned int  interval = 3000;
  //PIEZO SENSOR
    const int knockInput = A3;
    const int knockSensativity =50;
   //REED SENSOR
    const int ReedPin = 7;
   //PROTECTION CIRCUIT
   const int protPin = A1;

//VARS
   //UNIVERSAL
     boolean stendby = true;
     boolean alarm = false;
     int i=0;
     int isTone = 0;
     int day = 0;
     int hour = 0;
     int mn = 0;
     int sec = 0;
     long unsigned alrmTime;
   //PIR SENSOR
     boolean firstMovDetected = false;
     boolean lowTime;
     long unsigned int lowIn;
   //REED SENSOR
     boolean ReedPrevState = true;
   //PROTECTION CIRCUIT
     boolean PCPS = true;
    
//VOID PREP
  //UNIVERSAL
    void universalSetup()
    {
      pinMode(ledPin1, OUTPUT);
      pinMode(ledPin2, OUTPUT);
      pinMode(ledPin3, OUTPUT);
      pinMode(ledPin4, OUTPUT);
      pinMode(onoff, INPUT);
      Serial.begin(9600);
    }
  //PIR SENSOR  
    void PIRSetup()
    {
      pinMode(pirPin, INPUT);
      digitalWrite(pirPin, HIGH);      
    }
  //REED SENSOR
    void ReedSetup()
    {
      pinMode(ReedPin, INPUT);
    }
  //PIR SENSOR PREPARAÇÃO
    void PIRPrep()//PIR SENSOR PREPARAÇÃO
    {
      Serial.println("A calibrar o sensor IR");
      for( i = 0; i < calibrationTime; i++)
      {
        Serial.print(".");
        delay(1000);
      }
      Serial.println("");
      Serial.println("O sensor IR agora esta calibrado!");
      delay(500);
      Serial.print("SENSOR LIGADO");    
    }
  
//VOID APP
//UNIVERSAL
  void timePrnt()
  {
    while (alrmTime >= 1000)
    {
      if (alrmTime >= 1000)
      {
        sec += 1;
        alrmTime -= 1000;
        if (sec >= 60)
        {
          mn += 1;
          sec = 0;
          if(mn >= 60)
          {
            hour += 1;
            mn = 0;
            if(hour >= 24)
            {
              day += 1;
              hour = 0;
            }
          }
        }
      }
    }

    Serial.print("d:");Serial.print(day);Serial.print(" h:");Serial.print(hour);Serial.print(":");Serial.print(mn);Serial.print(":");Serial.print(sec);
    Serial.println(" sec.");
  }
  void alrm()
  {  
       if (alarm == true)
       {
         for(isTone = 0; isTone <=255; isTone +=10)
         {
           digitalWrite(ledPin3, HIGH);
           analogWrite(speaker, 0);         
           delay(20);
           digitalWrite(ledPin3, LOW);
           analogWrite(speaker, 0);          
           delay(20);          
         }
         for(isTone = 255; isTone >=0; isTone -=10)
         {
           digitalWrite(ledPin3, HIGH);
           analogWrite(speaker, 0);
           delay(20);
           digitalWrite(ledPin3, LOW);
           analogWrite(speaker, 0);
           delay(20);
         }
         alarm = false;
       }
       PiezoDet();
       PIRDet();
       REEDDet();
       protCirc();
  }
//PIR
  void PIRDet()
  {
     if(digitalRead(pirPin) == LOW)
     {
       digitalWrite(ledPin1, HIGH);
       if(firstMovDetected == true)
       {
         alarm = true;// Liga o alarme
         firstMovDetected = false;
         Serial.println("_________________________");
         Serial.println("Movimento detectado as: ");
         timePrnt();
         delay(50);
       }
       lowTime = true;
     }
     if(digitalRead(pirPin) == HIGH)
     {
       digitalWrite(ledPin1, LOW);
       if(lowTime == true)
       {
         lowIn = millis();
         lowTime = false;
       }
       if(firstMovDetected == false && millis() - lowIn > interval)
       {
         firstMovDetected = true;
         alrmTime = millis();
         Serial.println("_________________________");
         Serial.println("Movimento desapareceu as: ");
         timePrnt();
         delay(50);
       }
     }  
  }
//PIEZO
  void PiezoDet()
  {
    if (analogRead(knockInput) >= knockSensativity)
     {
        Serial.println("_________________________");
        Serial.println("Vibracoes detectadas as: ");
        timePrnt();
        digitalWrite(ledPin2, HIGH);
        delay(100);
        digitalWrite(ledPin2,LOW);
        delay(100);
        alarm=true;
     }
  }
//REED
  void REEDDet()
  {
     if (digitalRead(ReedPin) == LOW)
     {
       alarm = true;
       if (ReedPrevState == true)
       {
         Serial.println("_________________________");
         Serial.println("ligacao magnetica interrompida as: ");
         timePrnt();
         ReedPrevState = false;
       }
     }
     if (digitalRead(ReedPin) == HIGH && ReedPrevState == false)
     {
       Serial.println("_________________________");
       Serial.println("ligacao magnetica restabelecida as: ");
       timePrnt();
       ReedPrevState = true;
     }
  }
//PROTECTION CIRCUIT
 void protCirc()
 {
   if (analogRead(protPin) > 700)
   {
     alarm = true;
     if(PCPS == true)
     {
       Serial.println("_________________________");
       Serial.println("Circuito protector interrompido as: ");
       timePrnt();
       PCPS = false;
     }
   }
   if (analogRead(protPin) < 650)
   {
     alarm = true;
     if(PCPS == true)
     {
       Serial.println("_________________________");
       Serial.println("Circuito protector ultrapassado as: ");
       timePrnt();
       PCPS = false;
     }
   }
   if (analogRead(protPin) > 650 && analogRead(protPin) < 700 && PCPS == false)
   {
     Serial.println("_________________________");
     Serial.println("Circuito protector voltou a normal as: ");
     timePrnt();
     PCPS = true;
   }
 }
//SWITCH
  void swtch()
  {
    if(digitalRead(onoff) == HIGH)
    {
      digitalWrite(ledPin4, HIGH);
      delay (100);
      digitalWrite(ledPin4, LOW);
      delay (100);
      digitalWrite(ledPin4, HIGH);
      delay (100);
      digitalWrite(ledPin4, LOW);
      delay (100);
      digitalWrite(ledPin4, HIGH);
      delay (100);
      digitalWrite(ledPin4, LOW);
      delay (100);
      if(stendby == false)
      {
        Serial.println("_________________________");
        Serial.println("Alarme em stendby a partir das: ");
        timePrnt();
        stendby = true;
      }
      else
      {
        Serial.println("_________________________");
        Serial.println("Alarme a funcionar a partir das: ");
        timePrnt();
        stendby = false;
        delay(1000);
      }      
    }
  }
  void setup()
  {
    universalSetup();
    PIRSetup();
    ReedSetup();
    PIRPrep();
  }
  void loop ()
  {
    if (stendby == false)
    {
      digitalWrite(ledPin4, HIGH);
      alrm();
      swtch();
    }
    if (stendby == true)
    {
      digitalWrite(ledPin4, HIGH);
      delay (1000);
      digitalWrite(ledPin4, LOW);
      delay (1000);
      swtch();
    }
  }
My problem is that the PIR sensor goes off (sends alarm message that is) as soon as the alarm goes online or when any other sensor goes off. Can someone help me find the bug and optimize the code please. Oh and time function is all messed up, but I'm planning to remove it in favor of the cellular phone.

I have to get this thing done ASAP so any help would be appreciated!
Logged

Pages: [1]   Go Up
Jump to: