Over the summer month I am usual not at home, I I have a plant, wich needs at least wawter every week so this project is to solve this. I am using an ESP8266 to open & close a valve and also messure the resistence of the soil to know when to water.
The main goals of this project are:
keep the plant alive
use as little power as possible
notify me via internet if power/water runs low
log temp, humidity, soil resistence
one charge should last atleast 28 days
Currently I use an ESP8266 and programm it with Arduino. The whole thing should run on battery power.
Maybe if everything works I will try to add a solar panerl for battery recharging.
My NE555 had a power consumption of ~4mA. This was an improvement compared to the powerdown of the ESP8266, but still not good enough. Another problem is, if the ESP finishes earlier and goes powerdown the 555 can not react to this, so we have a high power consumption.
Since Christmas I have some AtTiny13 chips and by using them I can further reduce power consumption. With a little program I wrote I have the same timings but I have also a power off pin. And it only uses 0.3mA which is a great improvement.
I am still alive, kinda. Exams had taken alot of my time away and I used the past weeks to relax and get ready for the next semester.
Anyway, since the EEPROM is working it is time to move to the next step: the external timing.
Thanks to this site I got a formula to calculate the timings for the on and off states. 105 + 1645 seconds is 29.17 minutes so almost half an hour. I have found a website named timezonedb, and it has a relay good API to get timestamps so I will use that to get the real time the timer needs to turn the chip on and off. The website returns a json obj so I am using ArduinoJson from bblanchon.
I messured the time with the timestamps (results where 1569857598 and 1569855755). This means it tackes 1843 seconds (30 min 43 seconds) to do a cycle instead of 1750 seconds (29 min 10 seconds).
This step took way longer then I exoetced. First of I still dont know if the chip was broken or the wirring was wrong but after recabling everything and replacing the chip everything worked as intendet. Getting the communication right was a bit tricky and needed some trial and error as the spec sheet was sometimes not clear enough.
Last weekend the EEPROM 25AA010A arrived. And since Monday I am now trying to communicate via SPI with it, with limited success so far. The IC does respond, somehow. I get for supported command a 255 and for not supported ones 0. The thing is the read status message also retunes 0, even after I did the "write enable" procedure to set the Write enable bit high. I do not know if I am reading the status wrong or if I did the write enable procedure wrong. Reading from adress returns always 255. Writing has not worked so far, so most likely getting always 0 as status is correct.
If one of you wants to ask if I checked the clock speed, bitorder and spi mode: yes I did, in fact I am looping over every possible configuration and doing the the same thing while printing the results. Most promising is MSBFIRST and spi mode 0.
I noticed a mistake I made in the EEPROM lifespan calculation, each value is only measured every 24 hours. If I use something like an offset counter that would have to get refresh every hour but if I just clear all the values after sending them to the server I can reduce the writes to twice a day so 2/24h. 1m/ 2 are 500.000 days which are 1368 years. So that will work.
After the power down I unplugged the ESP8266 and all other components so the battery could charge via solar power. I also directly connected the solar panel and the battery since the power breaks down to ~5V if enough current flows. I did add a diode in between to ensure there is no backflow, the voltage drop is roughly 1V so the battery is not in danger (at least I hope so). Today the charging LED is no longer on, so the battery is full.
My last post was at the 26th (about the power down) this means it took 17 days to recharge. The Battery has 3000mAh at 5V. 17 days are 408 hours. 3000mAh / 408h = 7.3mA . We can double that at day to 14mA and at night we got 0mAh. This means we have to use less than 176mAh per day.
Another major problem is: the soil resistance is very inaccurate. I think one of the wires is broken or the electrodes (steel screws) have connection issues. If the sensor is never detection water, I will probably just drown my plant, so that needs fixing.
I have not digged to deeply into SPI which the ESP8266 yet but I did a lot of SPI projects with the STM32F4 and STM32F3 so I hope its not that hard.
After about 3 weeks (I don't know exactly by I documented the dates here somewhere) I started with a full battery and solar power. The last few days were sunny but still yesterday to power for the microcontroller went out. It also produced weird sensor values the days before so I guess the power supply was instable. Two days ago the microcontroller also was in a weird state were the power led was very slightly on and the wifi led on full power for several minuets. This means there are also software bug/edge cases I have to take care of.
I have reviewed FLASH, EEPROM and FRAM a bit more and FRAM would be ideal but as they are quite pricey I will go with an extern EEPROM for now. The one I am going to use (25AA010A) is rated for 1M write cycles, so if I use the same cells over and over again (which I will not do) this means 24 writes per day. 1M/24 means 41,666 which are about 114 years. So this will probably outlive me. Even if I first clear the EEPROM this means 48 writes per day so only 57 years which is still good enough.
I have not charged the battery since 12 days, which means the setup is working. I have measured the output voltages a bit and noticed at around 8 am is enough sunlight for the DCDC converter to get started, but since the voltage drops when load is connected the 7 V base output drop down to under 4 V and DCDC fails to start. By simply unplugging and replugging the solarpanel the DCDC starts working. At around 9 am the power generated is enough so the DCDC starts on its own, but we are wasting an hour of sunlight here. During summer this can be ignored, but not during winter. So ideally I would need something like a switch or a timer which unplugs everything regularly if not enough power is outputted at the 5 V line.
When the DCDC outputs 5 V the MOSFETS opens and pulls the the Q1 MOSFET to ground and thus closing it, when no power is there the gate is pulled high and thus the mosfet is open. This setup is basically a P-Type depletion mode MOSFET, but build with N-Type enhancing MOSFETS since the P DMOSFTES and rare and pricey. The circuit works, but not very good. The solarinput I get is around 4 V, but the output of Q1 is only about 2.2V and it outputs near zero current, so this is not really what I wanted at all. If I can find a good low power be state relay, I will test that but until then I would leave the solar power part as it is.
Lowering Standby Energy I did not yet decide if I want to use an SD card or an F-RAM chip. FRAM is build for low-power but I can not read it myself. And SD needs more power but I can confirm the data with my PC. Most likely the FRAM chip is more easy to implement since it is just an SPI connection where I write & read some bits into some registers.
The Watering Mechanism Something I kind of avoided this far is the actual watering of the plant. Currently the system is a WIFI connected thermometer but nothing really more. The thing I have to keep in mind are:
Monitoring the water levels of the external tank
Even when if power runs out, I don't want to flood the plant
Needing little energy to trigger the watering mechanism
Honestly I have no Idea how I can achieve all of the above points, I am good with software but not with mechanical engineering. A pump will most likely need way to much energy. This means the tank need to be already above the plant, gravity can do the rest.
I had two ideas how I can increase the lifetime of the whole system. First, I can add a solar panel to charge the powerbank, this will increase the lifespan of the whole system. Second, I am building my own external timer two completly shutdown the ESP board will all its components.
The Solarpanel Idea
This is my current circuit to stabilize the output from the solarpanel to charge the powerbank. The solarpnale outputs somewhat between 0-8V, I feed that into a DC/DC to convert it to 5V and use that to charge the powerbank.
The charging lamp is on so I guess it is working.
All is 5V so I will use Ah instead og Wh or J. If the system needs 10mA at most this will be 240mAh per day, So if I get 50mA over about 5h it will be enough to operate for that day. The only window I have is facing west, so we can say we got 2h at most, lets say it still has gets 100mA somehow, so we have 200mAh. Lets say the ESP only needs 6mA (min I mesured), so we have 144mAh per day.
It can work, I have to see how long the system keeps runningn until it runs out of energy again... It will atleast runs longer than 7 days, so we have an improvment here.
Completly shutting of the ESP8266 has tha major problem of data loose. Currently I am using the volatile memory which will be held as long as the ESP gets some juice, but as long as its unpowered for more the an hour the data is lost. A good low power solution seems to FRAM, I could also use an SD card, but they tend to need more power.
Most likely the external timer will be an NE555. If I get the timing to be about 50min off and 10min on, I can execute longer operatipns (like uploading all the data, or actually watering the plant). To still save energy I can use deep sleep. Actual experimenting will most likely proof better timings.
I have come to the point where the system failes due to power loss. THis happens approxiemntly once a week. It is also winter so it is also colder in the room decresing the battery output a little.
That is why I hocked a Ampmeter between the battery and the ESP to test how much it realy needs. 6.4mA. According to alot of papers and websites deep sleep shoud need ~20µA so 0.02 mA. WHile testing it jumped around a little, so it neeeds about 20mA +/- 6mA for basic operation (reading the sensors) and 150mA when WIFI is active and its sending something. since sensor reading and wifi is only active of some seconds, the "off" power draw is may to high.
I will dig into this, I am currently using a USB power bank as an energy source so maybe th 5V to 3.3V converter uses the 6mA. Also I have to unwire everything to check if any external circuit is causing this.