總網頁瀏覽量

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


2011年10月17日 星期一

手機藍牙監控溫度 = Android phone + arduino + MAX6675 + Bluetooth

延續上次做的手機溫度監控,這次為了改善Arduino IO Pin腳不夠用, 把LCD改成I2C介面,以及為了要偵測高溫所以改用K-Type的熱偶合溫度感測器, 可以測到700度C以上的高溫, 配合一顆MAC6675 IC 做數位訊號轉換接到Arduino. 黃色按鈕可以設定cooking temperature and holding temperature(此系統未來設計給BBQ 烤箱用的), 控制馬達(推進燃料)跟風扇(快速加溫)未接上去. 透過藍牙可以傳輸溫度以及馬達風扇的運作情形到Android 手機. 有興趣進一步了解的朋友可以email to me : sinocgtchen@gmail.com.

我使用的材料:

1. Arduino Duemilanove
2.Proto-Screw Shield 擴充板 
3.MAX6675 
4. 5-buttons 擴充板 (analog in 分壓辨識按鈕)
5. K-type 熱偶合溫度 sensor
6. I2C LCD1602 (16x2) 
7. 藍牙模組
8. Android 手機


下圗是組合起來的prototype.








下圗是 proto-screw shield 未疊上的圗


 下圖中間IC是 MAX6675, 只要連接 K-Type Sensor





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

   有任何問題或有興趣朋友,歡迎來信討問,謝謝!!

2011年10月3日 星期一

紅外線遙控車( 坦克車 ) = Arduino + IR receiver + TV remote control + L293D

利用紅外線遙控車子比較不好,容易受障礙物及角度影響. 這次利用家裡電視遙控器攔截五個按鈕訊號作為遙控車子前進,後退,左轉,右轉及停止動作.也順便把手邊組好的履帶式車子做個連結遙控. 影片中兩層板子,上層是自己焊接的Arduino,下層是馬達驅動IC L293D組成的線路板. 想進一步了解或有問題可以email me : sinocgtchen@gmail.com

影片在我的Youtube : http://www.youtube.com/user/sinocgtchen 

使用材料:
1. Arduino board (ATMEGA328P-PU)
2. Motor Driver IC L293D x 1
3. 74HC00D x 1
4. 1.5V battery x 4
5. 9V x 1
6. 38KHz IR Receiver  x 1





2011年9月27日 星期二

Line Tracing Robot (自走車) = Arduino + CNY70 + L298N

這幾天把放一段時間的五顆 CNY70 紅外線sensor拿出來自做了一台自走車,還沒有調整很好,隨手用蝴蝶夾固定sensor,意思到就好! 用家裡也擺一段時間的黑色膠帶黏在白板背面當作車子軌道.9V的電池被我操的快沒電了! 有興趣或有問題的朋友們可以email to me: sinocgtchen@gmail.com 




材料:
1. CNY70 sensor x 5 (三顆也可以)
2.Arduino board x 1
3. L298N board x 1
4. 9V battery x 2
5. 線材幾條


ps.所有材料拍賣網站都可以買到包含平台車.







My email : sinocgtchen@gmail.com
My Youtube: http://www.youtube.com/user/sinocgtchen
Motoduino 參考網站: http://motoduino.com



2011年9月26日 星期一

Arduino Atmega328 supporting

很少人會拿到Atmega328要用在arduino上開發,通常都是用Atmega328P, 如何修改Arduino環境來使用 Atmega328(不是Atmega328p),基本上只有Signature不一樣,Atmega328P是1E950F, Atmega328是1E9514,最簡單方式就是修改arduino signature的check.底下做法也可以用在其他Mega系列.

1.修改AtmegaBoot_168.c
增加底下定義
#elif defined __AVR_ATmega328__
#define SIG2 0x95
#define SIG3 0x14
#define PAGE_SIZE 0x40U //64 words

2.修該Makefile
增加底下定義
atmega328_pro16: TARGET = atmega328_pro_16MHz
atmega328_pro16: MCU_TARGET = atmega328
atmega328_pro16: CFLAGS += '-DMAX_TIME_COUNT=F_CPU>>4' '-DNUM_LED_FLASHES=1' -DBAUD_RATE=57600 -DDOUBLE_SPEED
atmega328_pro16: AVR_FREQ = 16000000L
atmega328_pro16: LDSECTION  = --section-start=.text=0x7800
atmega328_pro16: $(PROGRAM)_atmega328_pro_16MHz.hex

3.產生bootloader的 command :
    >make clean
    >make atmega328_pro16
  將產生  ATmegaBOOT_168_atmega328_pro_16MHz.hex
   
4.修改avrdude.conf

#------------------------------------------------------------
# ATmega328P
#------------------------------------------------------------

 signature = 0x1e 0x95 0x0F;
改成
 signature = 0x1e 0x95 0x14;

5.在 boards.txt修改或增加一項,如下
##############################################################

pro5v328.name=My Arduino Pro(16MHz) w/ ATmega328

pro5v328.upload.protocol=stk500
pro5v328.upload.maximum_size=30720
pro5v328.upload.speed=57600

pro5v328.bootloader.low_fuses=0xFF
pro5v328.bootloader.high_fuses=0xDA
pro5v328.bootloader.extended_fuses=0x05
pro5v328.bootloader.path=atmega328Led
pro5v328.bootloader.file=ATmegaBOOT_168_atmega328_pro_16MHz.hex
pro5v328.bootloader.unlock_bits=0x3F
pro5v328.bootloader.lock_bits=0x0F

pro5v328.build.mcu=atmega328p
pro5v328.build.f_cpu=16000000L
pro5v328.build.core=arduino

6.利用Arduino把bootloader燒錄:
  a.打開arduino選擇Tools的Board: "My Arduino Pro(16MHz) w/ ATmega328"
  b.選擇Burn Bootloader 如USBtinyISP

下圖(手機拍攝不是很清楚)我把Atmega328 mounting上去的arduino板子,一切正常work.
有興趣或有問題的arduino同好,可以mail me: sinocgtchen@gmail.com

2011年9月17日 星期六

手機無線遙控車 = mobile phone + Arduino + WiFi + Car + L298N

這次改用田宮出品的玩具車套件來組裝一台車,Arduino板子可以用螺絲固定在底板上面,電池用雙面膠暫時黏住,提供Arduino電源. 利用 Android 手機來控制 WiFi (http server)車子. 影片在此  http://www.youtube.com/user/sinocgtchen , 架起來拍錄比較容易.

田宮材料表較貴但是質感比較好,拍賣網站可以買到我組裝的所有材料!
想了解如何製作或有興趣可以mail me : sinocgtchen@gmail.com



                                               利用自己寫的簡單web page控制車子.


My email : sinocgtchen@gmail.com
My Youtube: http://www.youtube.com/user/sinocgtchen
Motoduino 參考網站: http://motoduino.com




 有任何問題或有興趣朋友,歡迎來信討問,謝謝!!