Author Topic: Uno watering system  (Read 3717 times)

Bondo2

  • Newbie
  • *
  • Posts: 9
  • Country: ae
Uno watering system
« on: February 25, 2016, 09:01:31 AM »
I built a small water system with Arduino Uno, soil humidity sensor and a water pump. The system runs on a 5000 mAh solar power bank (solar charging 5.5V, 1.2W). The Uno and the pump are both powered from the bank and the pump runs for very short durations and infrequently (pump is 5V and 180 mA). The battery was depleted in around 40-42 hours. The pump simple driver circuit is at pin 7
I am trying to use Lightweight Low Power Arduino Library and here is my code but I am not sure if I am doing it right.
Code: [Select]
#include "LowPower.h"

const int VAL_PROBE = 0; //Analog pin 0
const int MOISTURE_LEVEL = 250;

void setup() {
  pinMode(7, OUTPUT);
}
void loop() {
  // put your main code here, to run repeatedly:
    LowPower.powerDown(SLEEP_4S, ADC_OFF, BOD_OFF);
  int moisture = analogRead(VAL_PROBE);

  if(moisture > MOISTURE_LEVEL)
  {
    digitalWrite(7,HIGH);
  }
  else
  {
    digitalWrite(7,LOW);
  }
}
« Last Edit: February 25, 2016, 09:03:03 AM by Bondo2 »

Felix

  • Administrator
  • Hero Member
  • *****
  • Posts: 5857
  • Country: us
    • LowPowerLab
Re: Uno watering system
« Reply #1 on: February 25, 2016, 09:24:48 AM »
You have to sleep *everything* in your system.

Bondo2

  • Newbie
  • *
  • Posts: 9
  • Country: ae
Re: Uno watering system
« Reply #2 on: February 25, 2016, 09:49:19 AM »
You have to sleep *everything* in your system.
Would you give me more details ?

Felix

  • Administrator
  • Hero Member
  • *****
  • Posts: 5857
  • Country: us
    • LowPowerLab
Re: Uno watering system
« Reply #3 on: February 25, 2016, 10:09:07 AM »
Everything that uses power needs to be put to sleep when not in use.
The UNO board is not exactly a very low power friendly board.

Bondo2

  • Newbie
  • *
  • Posts: 9
  • Country: ae
Re: Uno watering system
« Reply #4 on: February 25, 2016, 10:12:19 AM »
Everything that uses power needs to be put to sleep when not in use.
The UNO board is not exactly a very low power friendly board.

Thx Felix, I have nothing connected to the Uno except the humidity sensor. The pump only runs when the moisture level goes low
Which board would be better ?
« Last Edit: February 25, 2016, 10:14:06 AM by Bondo2 »

Felix

  • Administrator
  • Hero Member
  • *****
  • Posts: 5857
  • Country: us
    • LowPowerLab
Re: Uno watering system
« Reply #5 on: February 25, 2016, 10:32:29 AM »
Moteino :)))

Bondo2

  • Newbie
  • *
  • Posts: 9
  • Country: ae
Re: Uno watering system
« Reply #6 on: February 25, 2016, 10:49:21 AM »
Moteino :)))
I don't think I can buy around here :D

How can I power down the sensor, I don't was very fine moisture sensing. I would be fine checking the sensor 2-3 time a day (preferably during the day time when it is extremely hot). The problem with powerdown and my code (at least how I understand it) is that the Uno will power down for the 4 sec and during that period the pump will be on so if I sleep longer (maybe looping ?) the pump will run longer. I want to be able to check moisture, if it is low, water it until moisture is right then sleep for few hours. I need to run that setup on battery for up to 2 weeks ideally.

Felix

  • Administrator
  • Hero Member
  • *****
  • Posts: 5857
  • Country: us
    • LowPowerLab
Re: Uno watering system
« Reply #7 on: February 25, 2016, 12:13:02 PM »
How do you power your sensor?
Why don't you power it via a transistor or mosfet? Then you can cut power off, and only turn it on when you do a measurement.

Bondo2

  • Newbie
  • *
  • Posts: 9
  • Country: ae
Re: Uno watering system
« Reply #8 on: February 25, 2016, 12:17:13 PM »
How do you power your sensor?
Why don't you power it via a transistor or mosfet? Then you can cut power off, and only turn it on when you do a measurement.
I power it directly from the 5V on the Uno, I use this  instructable. How do I power it with 2N2222A ?. That would reduce a lot of power but I want to reduce more to run longer on the power bank battery (which is compensated by solar charging).
Can I have the power down duration longer than the pump run duration ?
I need to consume approximately 1400 mAh a day
« Last Edit: February 25, 2016, 12:20:18 PM by Bondo2 »

Felix

  • Administrator
  • Hero Member
  • *****
  • Posts: 5857
  • Country: us
    • LowPowerLab
Re: Uno watering system
« Reply #9 on: February 25, 2016, 12:51:53 PM »
You can probably get much better than 1400mah a day.
See this: http://forum.arduino.cc/index.php?topic=152578.0
You can sleep anywhere from 16ms to 8sec, even unlimited sleeping is possible.

Bondo2

  • Newbie
  • *
  • Posts: 9
  • Country: ae
Re: Uno watering system
« Reply #10 on: February 25, 2016, 12:56:14 PM »
You can probably get much better than 1400mah a day.
See this: http://forum.arduino.cc/index.php?topic=152578.0
You can sleep anywhere from 16ms to 8sec, even unlimited sleeping is possible.
My code at the OP is using 4s sleep, the problem is the time spent sleeping means the pump will be on and pumping water so long sleeps are not good. The motor driver is on pin 7, the same driver can be used to power on/off the sensor I guess

Code: [Select]
void loop() {
  // put your main code here, to run repeatedly:
  LowPower.powerDown(SLEEP_4S, ADC_OFF, BOD_OFF);
  int moisture = analogRead(VAL_PROBE);
  if(moisture > MOISTURE_LEVEL)
  {
    digitalWrite(7,HIGH);
  }
  else
  {
    digitalWrite(7,LOW);
  }

Ropo

  • Newbie
  • *
  • Posts: 3
  • Country: cz
Re: Uno watering system
« Reply #11 on: February 25, 2016, 03:47:51 PM »
Can you modify the schema of watering system? You use deep sleep mode of arduino and interrupt to wake up atmega from deep sleep if the measured value is change.

Bondo2

  • Newbie
  • *
  • Posts: 9
  • Country: ae
Re: Uno watering system
« Reply #12 on: February 25, 2016, 11:18:32 PM »
Can you modify the schema of watering system? You use deep sleep mode of arduino and interrupt to wake up atmega from deep sleep if the measured value is change.
That's a good idea but I don't know how to implement it. How do I read the sensor when the board is in deep sleep?, how do I interrupt the deep sleep to water the plant?

Bondo2

  • Newbie
  • *
  • Posts: 9
  • Country: ae
Re: Uno watering system
« Reply #13 on: February 28, 2016, 01:45:27 AM »
The water sensor I have has a digital output pin (in addition to analog one which am using), how do I use the this digital pin to wake up the controller, then I can check the analog pin and decide to water or not ?
The above approach would mean I have to keep the sensor powered up always., any ideas ?

p.s. with the lowpower library I have been running for almost 4 days now and I think I can make it to 6 but I want to make at least 14 days.

Bondo2

  • Newbie
  • *
  • Posts: 9
  • Country: ae
Re: Uno watering system
« Reply #14 on: February 29, 2016, 06:50:55 AM »
My new modified code, trying to change the duty cycle (now I water for 4 sec. sleep for 8 and check moisture again). Let's see how long I can run.

Code: [Select]
#include "LowPower.h"

const int VAL_PROBE = 0; //Analog pin 0
const int MOISTURE_LEVEL = 250; // the value after the LED goes on

void setup() {
  // put your setup code here, to run once:
  pinMode(7, OUTPUT);
}

void loop() {
  // put your main code here, to run repeatedly:
  int moisture = analogRead(VAL_PROBE);
  if(moisture > MOISTURE_LEVEL)
  {
    digitalWrite(7,HIGH);
    LowPower.powerDown(SLEEP_4S, ADC_OFF, BOD_OFF);
    digitalWrite(7,LOW);
  }
  LowPower.powerDown(SLEEP_8S, ADC_OFF, BOD_OFF);
}