I have built an external sensor so as to monitor temperature, air humidity, soil humidity of my garden and the battery voltage. The requirements was:
We can of course imagine to use these values to control a water pump. Now let's see hpw to build this.
- waterproof
- long battery life, the atmega328p run at 8mhz with minimal components and functions
- under 10€
- wireless (433Mhz) with good range (2 walls to cross and 10 meters)
Here is the final view:
And some reports from OpenHab displaying the sensor data:
Air humidity
Soil humidity
Air temperature
We can of course imagine to use these values to control a water pump. Now let's see hpw to build this.
Bill of material
The sensors is based on atmega328p(3€),
- a 433 Mhz transmitter (1,5€) ,
- a DHT11(1€) or a DHT22 temperature and humidity sensor,
- a soil moisture sensor (1,6€),
- an electrical box (1€)
- a 433 mhz antenna (0,18€)
- DIP socket adaptor for the ATmega (1€)
- an electronic prototype printed circuit board (0,5€)
- a recycled tube
At total we are around 10€
Principle
Every hour the sensor send the data to a 433Mhz gateway so as to be stored in OpenHAB, the data sent are:
- air temperature
- air humidity
- soild humidity
- voltage of the power supply
The library used to send the data is RCSwitch.
The program to load to atmega328p on the sensor is here Low power sensor
The main principle of the architecture is to power ON the components on needs by using the digital pins of the ATmega328p as power supplies. The dht, the RF emitter and the moisture sensor are powered from pins directly. With this architecture they are consumming only when activated by the program and reducing by the way the power consumption of the whole system.
The current consumption of the system in sleep mode with 3 AA batteries giving 5V is around 6uA (yes 0,006mA), when retrieving and sending data we reach at maximum 20mA . If we consider that the system is going to wake up every hour 3 seconds so as to measure and send data. The theoretical life of this sensor with AA Alkaline battery (2000mAh) is around 10 years !! For this duration i'm not taking into account the discharge rate of this type of battery that can be significant compared to the consumption of the sensor. If we take into account the self discharge of typical alkaline battery (3% per year) the duration of our system go down to 7-8 years. Remaining quite interesting for my use.
After these theroretical things let's go to the practical side of this project.
The current consumption of the system in sleep mode with 3 AA batteries giving 5V is around 6uA (yes 0,006mA), when retrieving and sending data we reach at maximum 20mA . If we consider that the system is going to wake up every hour 3 seconds so as to measure and send data. The theoretical life of this sensor with AA Alkaline battery (2000mAh) is around 10 years !! For this duration i'm not taking into account the discharge rate of this type of battery that can be significant compared to the consumption of the sensor. If we take into account the self discharge of typical alkaline battery (3% per year) the duration of our system go down to 7-8 years. Remaining quite interesting for my use.
After these theroretical things let's go to the practical side of this project.
Steps to follow
1) First we need to set the extended fuses of the ATMega 328p to disable brown out detection permanently and run at 8mhz, this will be done by a bootloader update
Written by Nick Gammon.
Version 1.36
Compiled on Jun 21 2016 at 21:40:08 with Arduino IDE 10605.
Attempting to enter ICSP programming mode ...
Entered programming mode OK.
Signature = 0x1E 0x95 0x0F
Processor = ATmega328P
Flash memory size = 32768 bytes.
LFuse = 0xE2
HFuse = 0xDA
EFuse = 0xFF
Lock byte = 0xEF
Clock calibration = 0x9B
Type 'L' to use Lilypad (8 MHz) loader, or 'U' for Uno (16 MHz) loader ...
newlFuse = 0xE2; // internal 8 MHz oscillator
newhFuse = 0xDA; // 2048 byte bootloader, SPI enabled
newextFuse = 0xFF; // disable Brown Out Detection to save power
So as to do that we will lean on the excellent tutorials of Nick Gammon:
- Load this program on an arduino uno and wire it like that you can follow the chapter Alternate clock source to avoid the use of quartz on the breadboard. I forked the program of Nick Gammon and modified the valued of extended fuse so as to run disable BOD on the chip bootloader.
- Once wired link your arduino uno to the pc, launch the arduino IDE and open the serial monitor at 115200 baud
- If the ATMega328p is detected you will get the details of its current bootloader
Written by Nick Gammon.
Version 1.36
Compiled on Jun 21 2016 at 21:40:08 with Arduino IDE 10605.
Attempting to enter ICSP programming mode ...
Entered programming mode OK.
Signature = 0x1E 0x95 0x0F
Processor = ATmega328P
Flash memory size = 32768 bytes.
LFuse = 0xE2
HFuse = 0xDA
EFuse = 0xFF
Lock byte = 0xEF
Clock calibration = 0x9B
Type 'L' to use Lilypad (8 MHz) loader, or 'U' for Uno (16 MHz) loader ...
- Type L and enter
Using Lilypad 8 MHz loader.
Bootloader address = 0x7800
Bootloader length = 1932 bytes.
Type 'Q' to quit, 'V' to verify, or 'G' to program the chip with the bootloader ...
- Type G and enter
Erasing chip ...
Writing bootloader ...
Committing page starting at 0x7800
Committing page starting at 0x7880
Committing page starting at 0x7900
Committing page starting at 0x7980
Committing page starting at 0x7A00
Committing page starting at 0x7A80
Committing page starting at 0x7B00
Committing page starting at 0x7B80
Committing page starting at 0x7C00
Committing page starting at 0x7C80
Committing page starting at 0x7D00
Committing page starting at 0x7D80
Committing page starting at 0x7E00
Committing page starting at 0x7E80
Committing page starting at 0x7F00
Committing page starting at 0x7F80
Written.
Verifying ...
No errors found.
Writing fuses ...
LFuse = 0xE2
HFuse = 0xDA
EFuse = 0xFF
Lock byte = 0xEF
Clock calibration = 0x9B
Done.
Programming mode off.
Writing bootloader ...
Committing page starting at 0x7800
Committing page starting at 0x7880
Committing page starting at 0x7900
Committing page starting at 0x7980
Committing page starting at 0x7A00
Committing page starting at 0x7A80
Committing page starting at 0x7B00
Committing page starting at 0x7B80
Committing page starting at 0x7C00
Committing page starting at 0x7C80
Committing page starting at 0x7D00
Committing page starting at 0x7D80
Committing page starting at 0x7E00
Committing page starting at 0x7E80
Committing page starting at 0x7F00
Committing page starting at 0x7F80
Written.
Verifying ...
No errors found.
Writing fuses ...
LFuse = 0xE2
HFuse = 0xDA
EFuse = 0xFF
Lock byte = 0xEF
Clock calibration = 0x9B
Done.
Programming mode off.
Your atmega328p is now ready to welcome the sensor program!
2) Load the program
So as to load the program into the ATMega328p I use the following methods:
- remove the Atmega328p chip of an arduino Uno
- place your modified Atmega328p in the place of the stock one
- on the arduino IDE select "Lilypad Arduino"
- Connect the usb to the arduino Uno
- Select the good port
- Load this program:
3) Prototype the sensor
Now we need to do a little bit of hardware, here is the schematic:
and how it looks like on the breadboard:
And on a prototype PCB:
Once packaged in a standard electric box:
Once this is done you need to receive the data and store it to have some charts about your garden environment, so as to receive the data I use the 433Mhz MQTT Gateway sending the data to OpenHab.
Here is how it looks like on the webUI:
And the big question is ; how much does it last?
It is runningsince june 2016, now we need to wait so as to have more feedback in particular I will need to take into account other factor than the system itself like the influence of the temperature to the battery life.
Hi
RépondreSupprimerCan you please tell me how to load the ino code to the atmega328P I already have the bootloader installed in it.
I tried to follow the link you provided but couldn’t understand.
Thanks.
Hello,
SupprimerIf you have used the method above to load you bootloader you can keep your wiring like that.
After load the program ArduinoISP into the Arduino Uno (change the target board to Arduino on IDE settings)
Once the program has been loaded the arduino will act as the atmega328p programmer.
To load the program into the Atmega328p choose the board Lilypad arduino" and "Arduino as ISP" for the programmer instead of AVR ISP.
To upload the program don't choose upload but upload with a programmer
Hi Flo
SupprimerThanks for your response.
I bought the atmega328P from ebay with the bootloader pre-installed and I am not sure as to how I have to program it.
I have an arduino esp8266 as well which I thought I would require it to program the atmega328P but I am lost and dont know how to?
Hello,
SupprimerI don't know how to change the bootloader of an atmega328p with an esp8266 but if you follow this tutorial http://www.gammon.com.au/breadboard you should be able to change the bootloader with an arduino uno. Once the bootloader is loaded you can go with the program upload
Hi thanks for your reply.
RépondreSupprimerIn my previous comment I meant, the atmega 328p that I have already contains the bootloader see here (http://www.ebay.co.uk/itm/131675293038?_trksid=p2057872.m2749.l2649&var=431063272893&ssPageName=STRK%3AMEBIDX%3AIT)
I want to now upload the program but I want to know what components do I require to do this? and what is the wiring? I am new to this sorry.
Thanks.
Hello,
SupprimerYes but you have the standard bootloader which runs at 16mhz and without the low power parameters of the ones proposed on this tutorial.
You can of course load the program but you will not reach low power consumption.
The wiring to load is this one "Uploading Using an Arduino Board"
https://www.arduino.cc/en/Tutorial/ArduinoToBreadboard
Hi
RépondreSupprimerIs it possible to do the same project with a rf receiver instead of a rf transmitter.
If yes the can you please help me with the code. I just need the rf transmitter and no temp and humidity sensors.
Thanks.
I got the current in sleep mode to be 0.06 mA with 5V power supply and 0.04 mA with a 3.3V power supply. I think your 0.006 mA should be 0.06 mA.
RépondreSupprimerhmm, did you changed the bootloader?
SupprimerYes, I did change the boot loader using your forked code above and the remaining files using Gammon's website. Also, I used Lilypad Arduino while burning the code.
SupprimerOne thing I did notice: Gammon uses capacitors and you don't. Do these capacitors need to be removed?
RépondreSupprimerI'm not an electronics expert but following my experiences it works without.
Supprimerwhat kind of other components did you use?
RépondreSupprimerlike the values of the three different resistors on the final result?
for the dht it's a 10K
Supprimerfor the led a 1.2K
I don't think the one for the dht is compulsory
Ce commentaire a été supprimé par l'auteur.
RépondreSupprimerHi, yes I'm using the internal clock and I can assure you that the current measure is around 6uA. Did you changed the ATMega328p fuses ?
Supprimer