Showing posts with label door open arduino. Show all posts
Showing posts with label door open arduino. Show all posts

Sunday, August 25, 2013

Remote Door Open by SMS using Arduino



GSM Module used:

SIM900
Wiki
Testing the module


Video:


Code:
// this code was tested using the modem SIM900

/*

this code turn "On" and "Off" an LED by SMS.

Commands:

$ON$
$OFF$

Note: the commands are case sensitive.

*/


#include <SoftwareSerial.h>

SoftwareSerial mySerial(7, 8); // RX, TX

byte led = 13;   // use "byte" instead of "int" to save memory.
byte led_on = 0;
byte led_off = 0;
byte dollar_count = 0;

long last_millis = 0;
const int delay_time = 5000;

const int buff_size = 10;
char buffer[buff_size];

void setup()  
{
  pinMode(led, OUTPUT);
  mySerial.begin(9600);
  Serial.begin(9600);
 
   mySerial.println("AT\r\n"); // check communication with the modem.
   delay(500);
   mySerial.println("AT\r\n");
   
   //delete all read SMS
   
   for(int x=1; x<=20; x++){
   mySerial.print("AT+CMGD=");
   mySerial.print(x);
   mySerial.print(",");
   mySerial.print("3");
   mySerial.print("\r\n");  
   delay(1000);
   }
   
  
 
}

void loop(){

     
     if ((millis() - last_millis) > delay_time ){
       mySerial.print("AT+cmgl=\"REC UNREAD\"\r\n");
       last_millis = millis();
     }
  

  if (mySerial.available() > 0){

    char inchar = mySerial.read(); // print in data to  software serial port for debug perpose.
    
    Serial.print(inchar);

    if(inchar == '\r' || inchar == '\n'){
      dollar_count = 0;
      led_on = 0;
      led_off = 0;
    }

    if(inchar == '$'){
      dollar_count++; 
     } 
    

      switch (dollar_count){
      case 1:
      
      if(inchar == 'O' || inchar == 'N'){
        led_on++;
      }
      
      if(inchar == 'O' || inchar == 'F'){
        led_off++;
      }
      
      if(led_on == 2){
        digitalWrite(led, HIGH);
      }
      
      if(led_off == 3){
        digitalWrite(led, LOW);
      }
      
      break;
        
      }  


  }


}




                                                                                           By: Elimeléc 




















Saturday, June 8, 2013

Door Open with Dallas iButton Arduino

 
 Requirements
 
 
 Video

 
Schematic 

 
 
 
 
 Breadboard Connection

 


 Code

 
 #include <OneWire.h>

OneWire ibutton (2); // I button connected on PIN 2.

byte ibuttonid[10] = {1,144,74,165,21,0,0,143}; // Ibutton ID must be typed in Decimal in the following order: Family code (01 for DS1990); numbers from R. to L.; CRC. 
byte buffer[10]; //array to store the readed Ibutton ID.

boolean result;  // this variable will hold the compare result

int doorpin = 13; // the output pin to activate the door.

void setup(){
    Serial.begin(9600); 
    pinMode(doorpin,OUTPUT);
   
}

void loop(){
   
 if (!ibutton.search (buffer)){//read attached ibutton and asign value to buffer
    ibutton.reset_search();
    delay(200);
    return;
 }
  
  for (int x = 0; x<8; x++){  
    Serial.print(buffer[x],HEX); //print the buffer content in LSB. For MSB: for (int x = 8; x>0; x--) 
    Serial.print(" "); // print a space
   }
   Serial.println("\n"); // print new line
   
   // compare the ibutton id
   
  result = true; // set variable equal to one.
  for (int x=0; x<10; x++){ 
  int compare1 = ibuttonid[x];// asign each index of arrays to test, one by one and compare
  int compare2 = buffer[x];
  
  
  if(compare1 != compare2){ // if any index comparison is not equal, then the arrays are not equal and result will be 0.
   result = false; 
  }
  
  }
  if(result == true){ // if the arrays are equal, do something.
   Serial.println("Door open for 5 seconds."); 
   digitalWrite(doorpin,HIGH); // Turn on LED on pin 13 (build-in on the Arduino board)
   delay(5000); // wait five seconds. (1 second = 1000 milliseconds)
   Serial.println("Door closed");
   digitalWrite(doorpin,LOW); // turn off LED.
 }
   
    //set buffer back to cero.
    
    for (int x=0; x<10; x++){
     buffer[x] = 0 ;
    }                
}



/* by Elimeléc 
  Jun-07-2013
*/