總瀏覽量

2011年11月7日 星期一

Email Alarm = Arduino + Ethernet Shield + PIR Motion Sensor

This is a simple E-Mail Alerter/Alarm. If PIR motion sensor detected something or someone active/moving, an E-Mail will be sent to a specified E-Mail account by arduino. I specified my gmail account to receive it.

這次利用手邊放了一陣子的Ethernet Shield來做Email的警報器,如果紅外線人體感測器感測到有人或有東西在移動(測試大約6公尺左右距離都沒問題),馬上發出一封email到我的gmail信箱. 我的手機馬上就會通知我有來信.



使用的材料:
1.Arduino board  x 1
2.Ethernet Shield x 1
3.PIR Motion Sensor
4.I/O Expansion Shield (option)
5.2 Email accounts, one is sender(from), another one is receiver(to)

Sketch: (for Arduino 0022 version)

-----------------------------------------------------------------------

#include <SPI.h>
#include <Ethernet.h>

byte mac[] = { 0xDE, 0xAD, 0xBE, 0xAF, 0xCE, 0xDD }; // whatever mac you want
byte ip[] = { 192, 168, 0, 109};
byte server[] = { 203, 188, 201, 253 }; // Mail server address  smtp.mail.yahoo.com.tw)
Client client(server, 25);  // yahoo's mobile smtp server ip/port 587

/////////////////////////////
//VARS
//the time we give the sensor to calibrate (10-60 secs according to the datasheet)
int calibrationTime = 30;      

//the time when the sensor outputs a low impulse
long unsigned int lowIn;        

//the amount of milliseconds the sensor has to be low
//before we assume all motion has stopped
long unsigned int pause = 5000;

boolean lockLow = true;
boolean takeLowTime;

int pirPin = 3;    //the digital pin connected to the PIR sensor's output
int ledPin = 13;
int nPIR_detect;

void setup()
{
 Ethernet.begin(mac, ip);
 Serial.begin(57600);

  pinMode(pirPin, INPUT);
  digitalWrite(pirPin, LOW);
 
  //give the sensor some time to calibrate
  Serial.print("calibrating sensor ");
    for(int i = 0; i < calibrationTime; i++){
      Serial.print(".");
      delay(1000);
      }
    Serial.println(" done");
    Serial.println("SENSOR ACTIVE");
    delay(50);
     nPIR_detect = 0;
}

void loop()
{
  delay(1000);
  if(PIR_detected())  // PIR : HIGH
  {
     if (client.available()) {
       char c = client.read();
       Serial.print(c);
     }

    Serial.println("connecting...");

     if (client.connect()) {
       Serial.println("connected");
       client.println("EHLO smtp.mail.yahoo.com.tw");
//       client.println("AUTH PLAIN AHNpbm9jZ3RjbGVuQHlhaH9vLmNvbSgwet323tcxYTU=");  // example
       client.println("AUTH PLAIN *************************************************=");  // replace the **'s with your auth info from the perl script.
       client.println("MAIL FROM:<**@yahoo.com.tw>");  // replace the ** with your mail address
       client.println("RCPT TO:<**@gmail.com>");       // replace the ** with to mail address
       client.println("DATA");
       client.println("From: <**@yahoo.com.tw>");
       client.println("TO: <**@gmail.com>");
       client.println("SUBJECT: Something has been detected by PIR");
       client.println();
       client.println("This is PIR testing.");
       client.println("Warning: detected something!!");
       client.println(".");
       client.println(".");
     
       delay(1000);
       client.stop();
       Serial.println("mail sent!!");    
       delay(30000);
     }
     else
     {
       Serial.println("connection failed");
     }
  }
}

boolean PIR_detected()
{
  boolean bPIR;
 
     if(digitalRead(pirPin) == HIGH){
       digitalWrite(ledPin, HIGH);   //the led visualizes the sensors output pin state
       if(lockLow){
         //makes sure we wait for a transition to LOW before any further output is made:
         lockLow = false;          
         Serial.println("---");
         Serial.print("motion detected at ");
         Serial.print(millis()/1000);
         Serial.println(" sec");
         delay(50);
         }        
         takeLowTime = true;
       
         bPIR = true;
       }
   
     if(digitalRead(pirPin) == LOW){      
       digitalWrite(ledPin, LOW);  //the led visualizes the sensors output pin state
     
       if(takeLowTime){
        lowIn = millis();          //save the time of the transition from high to LOW
        takeLowTime = false;       //make sure this is only done at the start of a LOW phase
        }
       //if the sensor is low for more than the given pause,
       //we assume that no more motion is going to happen
       if(!lockLow && millis() - lowIn > pause){
           //makes sure this block of code is only executed again after
           //a new motion sequence has been detected
           lockLow = true;                      
           Serial.print("motion ended at ");      //output
           Serial.print((millis() - pause)/1000);
           Serial.println(" sec");
           delay(50);
           }
           bPIR = false;
       }
    return bPIR;
}


-----------------------------------------------------

my blog: http://sinocgtchen.blogspot.com/
my Youtube: http://www.youtube.com/user/sinocgtchen

相關購買資訊: http://motoduino.com

2011年11月5日 星期六

手機遙控車 = Arduino + XBee (Zigbee) + Bluetooth + Android phone


這次利用兩塊Arduino board, 一塊(arduino duemilanove)是接在車子上,此塊另堆疊著一個XBee模組, 另一塊是arduino mega 2560, 此塊板子上面接者bluetooth跟XBEE(Zigbee),手機透過藍牙(bluetooth)傳輸控制指令到ardui­no mega 2560, ATMEGA2560收到data馬上再利用XBee(Coordinator)傳到車子上的XBee模組(End Device),如此車子就可以得到控制.
好像有點多此一舉,直接用bluetooth遙控即可. 主要利用XBee特性可以長距離遙控.我試著把車子放到房間內,客廳也能操控(隔了一兩座牆). 有興趣或有問題的朋友可以email. 

使用的材料:
1.arduino duemilanove x 1
2.arduino mega 2560  x 1
3.bluetooth module x 1
4.XBee module  x 2
5 XBee shield x 2.
6.android phone x 1
7.L298N Shield x 1
8. Car Chassis  x 1
9. others







相關影片請看: http://www.youtube.com/user/sinocgtchen
   部落格 :  http://sinocgtchen.blogspot.com
   相關購買資訊: http://motoduino.com