in my previous post, Forget_me_not : My Smart Home Post#6 Week-5 Smart Mailbox and doorbell with pi-camera I have shared my smart mailbox and doorbell with Pi camera..
Today in this post I will share my remote arduino which uses sleep mode for power optimization... and used as sensor node to interface remote smoke, LPG Gas leakage and Soil moisture level sensor....
Parts Used :
1. ATmega328P with Arduino bootloader
2. USB to UART converter FT232 based
3. LPG Leakage Sensor and Smoke Sensor (As output of this sensor is digital I have mimic it with switch)
4. Soil moisture sensor (I have Home Made but you can buy from here...)
5. RF transceiver (Wireless RF Serial Link 865-869MHz 2KM range [WIR-1186] - $12.00 : Robokits India, Easy to Use, Versatile Robotics Kits.…)
6. crystal and some Descrete components for place arduino on custom PCB.
Before moving ahead let me make this clear that My remote sensor nodes are no way compatible with enocean sensors in term of security and power optimization... But I have tried my best to optimize power, improve security and make it reliable too...
Some description on Important parts...
RF Transceiver (Wireless RF Serial Link 865-869MHz 2KM range [WIR-1186] - $12.00 : Robokits India, Easy to Use, Versatile Robotics Kits.…)
I am using this because It supports Sleepmode (only 10uA) , Encryption so its possible to fulfill Low power requirement of battery operated sensor node and its secure too... As it supports wide input voltage (5-9V DC) range as per Datasheet... and it works fine with 4.2V lithium battery... As It works on 3.25V DC (BA325 LDO on Transceiver)
So there is no need of power hungry voltage regulator at sensor node... I will be simply use 4.2V Rechargeable Lithium battery from my old cell phone to power-up both Arduino and Transceiver at remote sensor node...
DataSheet : http://www.robokits.co.in/datasheets/WIR-1186_RobokitsIndia.pdf
This Blog Arduino, Zigbee and Embedded Development: Sleeping Arduino - Part 1 is very useful for using arduino with sleep modes...and I have used this for my arduino code...
Here is video of my openHAB url....
A short video of my arduino based low power soil moisture sensor node....
Here is My Arduino code with sleep mode for both mcu and transceiver for Soil moisture sensor for remote monitoring of my Basil plant ....
here I have set Sampling interval for sensor is 8 second so sleep time is 8 second... it can be easily increased by counting and compering a variable.... as per need
/* * Sketch for Plant moisture sensor with Sleep mode. * Attribute : Donal Morrissey */ #include <avr/sleep.h> #include <avr/power.h> #include <avr/wdt.h> const int LED_Blue = 8; const int Config_TRX = 7; const int analogInPin = A4; volatile int f_wdt=1; /*************************************************** * Name: ISR(WDT_vect) * Returns: Nothing. * Parameters: None. * Description: Watchdog Interrupt Service. This * is executed when watchdog timed out. ***************************************************/ ISR(WDT_vect) { if(f_wdt == 0) { f_wdt=1; } else { Serial.println("WDT Overrun!!!"); } } /*************************************************** * Name: enterSleep * Returns: Nothing. * Parameters: None. * Description: Enters the arduino into sleep mode. ***************************************************/ void enterSleep(void) { set_sleep_mode(SLEEP_MODE_PWR_SAVE); /* EDIT: could also use SLEEP_MODE_PWR_DOWN for lowest power consumption. */ sleep_enable(); /* Now enter sleep mode. */ sleep_mode(); /* The program will continue from here after the WDT timeout*/ sleep_disable(); /* First thing to do is disable sleep. */ /* Re-enable the peripherals. */ power_all_enable(); } /*************************************************** * Name: setup * Returns: Nothing. * Parameters: None. * Description: Setup for the serial comms and the * Watch dog timeout. ***************************************************/ void setup() { Serial.begin(9600); delay(100); //Allow for serial print to complete. pinMode(LED_Blue,OUTPUT); pinMode(Config_TRX,OUTPUT); digitalWrite(LED_Blue, LOW);// turn off LED digitalWrite(Config_TRX, HIGH); // disable config mode of TRX by put 1 /*** Setup the WDT ***/ /* Clear the reset flag. */ MCUSR &= ~(1<<WDRF); /* In order to change WDE or the prescaler, we need to * set WDCE (This will allow updates for 4 clock cycles). */ WDTCSR |= (1<<WDCE) | (1<<WDE); /* set new watchdog timeout prescaler value */ WDTCSR = 1<<WDP0 | 1<<WDP3; /* 8.0 seconds */ /* Enable the WD interrupt (note no reset). */ WDTCSR |= _BV(WDIE); Serial.println("Initialisation complete."); delay(100); //Allow for serial print to complete. } /*************************************************** * Name: enterSleep * Returns: Nothing. * Parameters: None. * Description: Main application loop. ***************************************************/ void loop() { if(f_wdt == 1) { digitalWrite(LED_Blue, HIGH); // Flash LED for visulize that arduino is weaked up sending sample to PI delay(30); digitalWrite(Config_TRX, HIGH); Serial.println('X'); // wake up TRX sensorValue = analogRead(analogInPin); // Take Sample if (sensorValue>600) sensorValue=600; else if (sensorValue<300) sensorValue=315; outputValue = map(sensorValue, 300, 600, 0, 100);//for My Sensor only you need to take different maping based on your sensor Serial.print("AA*" ); // AA Sensor ID Serial.print(outputValue); Serial.println("#XX"); // XX is Home ID delay(30); digitalWrite(Config_TRX, LOW);//enter config mode TRX Serial.println('Z');//enable sleep mode for TRX digitalWrite(LED_Blue, LOW); /* Don't forget to clear the flag. */ f_wdt = 0; /* Re-enter sleep mode. */ enterSleep(); } else { /* Do nothing. */ } }
Here My Transceiver already configured with encryption enabled...
Communication rule of Sensor Nodes with raspberry pi is as follows...
Sensor Node Packet: <SensorID>*<Value>#<HomeID>
where,
SensorID Range AA,AB,AC.... to ZZ
HomeID Range AA,AB,AC..... to ZZ
Value Range As per Double Variable
example: AA*-3.47#XX
AA=SensorID
Value=-3.47
XX=HomeID
Here is openHAB demo.rules
import org.openhab.core.library.types.* import org.openhab.core.persistence.* import org.openhab.model.script.actions.* import org.openhab.binding.* import org.openhab.action.* import org.apache.commons.mail.* import java.util.Date var Number mail_count = 0 var Number visitor_count = 0 /** When My_trx received update change item states depending upon ID of sensor who sent update * SENSOR_ID Range is AA ---> ZZ (total 26*26) So Multiple Sensor can Talk with OpenHAB * HOME_ID Range is AA ---> ZZ (total 26*26) So Only Your Home Sensors can Talk with OpenHAB, * and there is no interface from your neighbour home sensors * format : <SENSOR_ID>*<UPDATE>#<HOME_ID> * example: AA*23.9#XX where, AA=Sensor_ID, 23.9=Update, XX=Home_ID */ rule "My_trx" when Item My_trx received update then var String My_trxUpdate=My_trx.state.toString.trim if (My_trxUpdate.endsWith("XX")) { var int rxStart=My_trxUpdate.indexOf("*")+"*".length var String rx=My_trxUpdate.mid(rxStart,My_trxUpdate.indexOf("#")-rxStart) var Double rxDouble=new Double(rx) if (My_trxUpdate.startsWith("AA")) { postUpdate(BasilPlant_tstamp, new DateTimeType()) postUpdate(My_BasilPlant, rxDouble) if(rxDouble<20) sendTweet("BasilPlant : Your Basil Plant needs water urgently!!! ("+ new Date + ")") } else if (My_trxUpdate.startsWith("AB")) { postUpdate(SmokeSensor_tstamp, new DateTimeType()) if(rxDouble==0) { postUpdate(My_SmokeSensor, "Its Emergency!!!") sendTweet("SmokeSensor : Smoke Detected....Its EMERGENCY !!! ("+ new Date + ")") } else postUpdate(My_SmokeSensor, "Nothing to worry") } else if (My_trxUpdate.startsWith("AC")) { postUpdate(LpgSensor_tstamp, new DateTimeType()) if(rxDouble==0) { postUpdate(My_LpgSensor, "Its Emergency!!!") sendTweet("LpgSensor : LPG Leakege Detected....Its EMERGENCY !!! ("+ new Date + ")") } else postUpdate(My_LpgSensor, "Nothing to worry") } } end /** When system starts update all items with its default value */ rule "Initialization at system startup" when System started then postUpdate(No_new_mail, mail_count) postUpdate(No_visitor, visitor_count) postUpdate(My_LpgSensor, "Nothing to worry") postUpdate(My_SmokeSensor, "Nothing to worry") sendTweet("My SmartHome : Tweet enabled.....!!! ("+ new Date + ")") end /** * This rule sends email to home owner when doorbell switch pressed with photo as attachment * here execute command line is just for demo it actually takes photo from PI Camera and save this image in specified folder * So far I am waiting for PI camera so its not implemented */ rule "send mail doorbell" when Item EnOcean_switch received update ON then executeCommandLine("/opt/openhab/cam.sh") visitor_count=visitor_count+1 postUpdate(Doorbell_tstamp, new DateTimeType()) postUpdate(No_visitor, visitor_count) playSound("doorbell.mp3") var String tweet_doorbell="Doorbell:You have visitor at home (" + new Date + ")\nTotal visitor so far = " + visitor_count sendTweet(tweet_doorbell) //sendMail("ravi.butani03@gmail.com", "My Smart Home (Doorbell)",tweet_doorbell +".\nOpen attachment to see latest visitor's image" ,"http://localhost:8080/doorcam/visitor.jpg") sendCommand(My_trx,tweet_doorbell) end rule "send mail manual image" when Item Send_pic_email received update ON then sendMail("ravi.butani03@gmail.com", "My Smart Home (Door image latest)"," Open attachment to see latest manually captured image at ("+ new Date +")" ,"http://localhost:8080/doorcam/man_pic.jpg") postUpdate(Send_pic_email, OFF) end rule "take manual image of door step" when Item Take_doorstep_pic received update ON then executeCommandLine("/opt/openhab/cam_manual.sh") postUpdate(Manual_tstamp, new DateTimeType()) postUpdate(Take_doorstep_pic, OFF) end rule "reset visitor count" when Item Reset_visitor_count received update ON then visitor_count=0 postUpdate(No_visitor, visitor_count) var String tweet_reset_visitor_count="Doorbell:You have Reset visitor count at (" + new Date + ")" sendTweet(tweet_reset_visitor_count) //sendMail("ravi.butani03@gmail.com", "My Smart Home (Doorbell)", tweet_reset_visitor_count) postUpdate(Reset_visitor_count, OFF) end /** * This rule sends email to home owner when new mail dropped in mail box */ rule "send mail update Mailbox " when Item EnOcean_contact changed from CLOSED to OPEN then mail_count=mail_count+1 postUpdate(No_new_mail, mail_count) postUpdate(Mail_tstamp, new DateTimeType()) var String tweet_mailbox="Mailbox : You have " + mail_count+" new mail. latest at (" +new Date + ")" sendTweet(tweet_mailbox) //sendMail("ravi.butani03@gmail.com", "My Smart Home (Mailbox)" , tweet_mailbox) end rule "send mail collect Mailbox " when Item EnOcean_contact_collect changed from CLOSED to OPEN then mail_count=0 postUpdate(No_new_mail, mail_count) postUpdate(Mail_tstamp, new DateTimeType()) var String tweet_mailbox_collect="Mailbox : You have collected all mails at (" +new Date + ")" sendTweet(tweet_mailbox_collect) //sendMail("ravi.butani03@gmail.com", "My Smart Home (Mailbox)" , tweet_mailbox_collect) end
Here is openHAB demo.items
/* My Smart Home items */ Switch EnOcean_switch "Doorbell" <doorbell1> (enocean) {enocean="{id=00:17:D3:AD, eep=F6:02:01, channel=A, parameter=I}"} Switch EnOcean_switch_B "DoorbellB" <doorbell1> (enocean) {enocean="{id=00:17:D3:AD, eep=F6:02:01, channel=B, parameter=I}"} Number EnOcean_sensor_temp "Temperature [%.1f °C]" <temperature> (enocean) {enocean="{id=00:83:02:70, eep=A5:04:01, parameter=TEMPERATURE}"} Number EnOcean_sensor_humd "Humidity [%.1f %%]" <humidity> (enocean) {enocean="{id=00:83:02:70, eep=A5:04:01, parameter=HUMIDITY}"} Contact EnOcean_contact "MailBox [MAP(en.map):%s]" <mailbox> (enocean) {enocean="{id=00:83:4A:99, eep=D5:00:01, parameter=CONTACT_STATE"} Contact EnOcean_contact_collect "MailBox collect [MAP(en.map):%s]" <mailbox> (enocean) {enocean="{id=00:82:B9:65, eep=D5:00:01, parameter=CONTACT_STATE"} String My_trx "My_trx [%s]" {serial="/dev/ttyUSB0"} Number My_BasilPlant "BasilPlant Moisture [%d %%]" <tree> String My_SmokeSensor "Smoke Sensor [%s]" String My_LpgSensor "LPG Sensor [%s]" Switch Take_doorstep_pic "Capture image" <click> Switch Send_pic_email "Send me image as email" <email> Switch Reset_visitor_count "Reset Visitor count" <reset> Number No_new_mail "Mailbox [%d New mails]" <mailbox> Number No_visitor "Latest Visitors [%d Latest visitors]" <doorbell> /* Time stamp items */ DateTime Date "Date [%1$tA, %1$td.%1$tm.%1$tY]" <calendar> DateTime Mail_tstamp "Mailbox [%1$tA, %1$td.%1$tm.%1$tY, %1$tI:%1$tM %1$tp]" <clock1> DateTime Doorbell_tstamp "Doorbell [%1$tA, %1$td.%1$tm.%1$tY, %1$tI:%1$tM %1$tp]" <clock1> DateTime BasilPlant_tstamp "Basil Plant [%1$tA, %1$td.%1$tm.%1$tY, %1$tI:%1$tM %1$tp]" <clock1> DateTime LpgSensor_tstamp "LPG Sensor [%1$tA, %1$td.%1$tm.%1$tY, %1$tI:%1$tM %1$tp]" <clock1> DateTime SmokeSensor_tstamp "Smoke Sensor [%1$tA, %1$td.%1$tm.%1$tY, %1$tI:%1$tM %1$tp]" <clock1> DateTime Manual_tstamp "Latest image [%1$tA, %1$td.%1$tm.%1$tY, %1$tI:%1$tM %1$tp]" <clock1> /* This portion will be used in application soon */ String UnknownDevices "Unknown Devices in Range: [%s]" { bluetooth="?" } Number NoOfPairedDevices "Paired Devices in Range: [%d]" { bluetooth="!" }
Here is openHAB demo.sitemap
sitemap demo label="My Smart Home" { Frame label="Latest Events and Sensor Status" { Text item=EnOcean_sensor_temp valuecolor=[>25="orange",>15="green",>5="orange",<=5="blue"] Text item=EnOcean_sensor_humd valuecolor=[>25="orange",>15="green",>5="orange",<=5="blue"] //Text item=Date Text item=No_new_mail valuecolor=[==0="blue",>=1="green",>5="orange"] Text item=No_visitor valuecolor=[==0="blue",>=1="green",>5="orange"] Text item=My_BasilPlant Text item=My_SmokeSensor Text item=My_LpgSensor } Frame label="Latest Events Time Stamp" { Text label="Latest Events Time Stamp" icon="clock1"{ Text item=Date Text item=Mail_tstamp Text item=Doorbell_tstamp Text item=BasilPlant_tstamp Text item=SmokeSensor_tstamp Text item=LpgSensor_tstamp } } Frame label="Latest Visitor Image & Manual Camera Control" { Text label="Latest Doorbell image and setting" icon="doorbell1"{ Switch item=Reset_visitor_count Text label="See latest Visitor image..." icon="video"{ Frame label="Latest visitor image.." { Text item=Doorbell_tstamp Image url="http://localhost:8080/doorcam/visitor.jpg" } } } Text label="Manual image capture and settings" icon="video"{ Frame label="Capture and send via email" { Switch item=Take_doorstep_pic Switch item=Send_pic_email } Frame label="See Latest captured Image" { Text label="Latest Image and time" icon="video"{ Frame label="Latest Image.." { Text item=Manual_tstamp Image url="http://localhost:8080/doorcam/man_pic.jpg" } } } } } }
Here are few pics of setup raspberry Pi with my RF Transceiver and FT232 USB to UART converter...
I have changed usb connector for direct plug in with Pi...
Here are few pics of my configurable chip-chap sensor node.... with addon soil moisture sensor...
i am using main MCU atmega328 board I have designed for my Quad.... But in near future I will re design the same only for Sensornode
Next step is designing addon sensor board for my sensor node with gas, smoke and PIR sensors...
In next post I will back with final schematic of arduino sensor node and codes with some more sensor support....
Top Comments