CRTC Electronics

Click here to edit subtitle

Security Alarm

Use a IOIO board and Android phone to send a text when a sensor is triped

Sensor

Use a Passive Infra Red (PIR) module or a switch and trip wire.  PIR can be found for about $3 and switchers for... less  ??? 

 

IOIO Board

Wire the IOIO board so that your input in will ether be high or low. High 3.3v Low 0v.  You will need to use a pull up or pull down resistors.

 

Software

setup()

setup() is called every time a connection with IOIO has been established
 

Output

variable led_ is an instance of openDigitalOutput
   FIRST argument is the pin number (0 = on-board LED)
   SECOND argument is the initial state of the 

Input 

pin variable pir_ is an instance of openDigitalInput
first argument is the pin number (48 = pin 48)
second argument is the pull up mode. 
FLOATING
PULL_UP
PULL_DOWN
 

protected void setup() throws ConnectionLostException 

{

   showVersions(ioio_, "IOIO connected!");

   led_  = ioio_.openDigitalOutput(0, true);

   pir_ = ioio_.openDigitalInput(48, Mode.FLOATING);

   enableUi(true);

}

loop()

called repetitively while the IOIO is connected

 

 
protected void loop() throws ConnectionLostException 
{
   boolean wasMovement = false;
   try 
   {
       wasMovement = ! pir_.read();;
   } 
   catch (InterruptedException e1) 
   {
       e1.printStackTrace();
   }

   led_.write(! wasMovement); // LED false = on
   if (wasMovement) 
   {
       movementCount ++;
   }

   long now = System.currentTimeMillis();
   if (now > lastTime + 1000) 
   {
       // every second
       lastTime = now;
       if (movementCount > 50) 
       {
            if (now > startTime_ + 10000 && runButton_.isChecked()) 
          {
              handleAlarm();
          }
       }
       movementCount = 0;
   }
   try 
   {
       sleep(10);
    } 

   catch (InterruptedException e) 
   {
   }
}