Skip to content
  • OpenHardware.io
  • Categories
  • Recent
  • Tags
  • Popular
Skins
  • Light
  • Brite
  • Cerulean
  • Cosmo
  • Flatly
  • Journal
  • Litera
  • Lumen
  • Lux
  • Materia
  • Minty
  • Morph
  • Pulse
  • Sandstone
  • Simplex
  • Sketchy
  • Spacelab
  • United
  • Yeti
  • Zephyr
  • Dark
  • Cyborg
  • Darkly
  • Quartz
  • Slate
  • Solar
  • Superhero
  • Vapor

  • Default (No Skin)
  • No Skin
Collapse
Brand Logo
  1. Home
  2. My Project
  3. Solar Powered Soil Moisture Sensor
  • Getting Started
  • Controller
  • Build
  • Hardware
  • Download/API
  • Forum
  • Store

Solar Powered Soil Moisture Sensor

Scheduled Pinned Locked Moved My Project
79 Posts 19 Posters 37.8k Views 35 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • F Offline
    F Offline
    flopp
    wrote on last edited by flopp
    #1

    I have build an Solar panel-powered Soil moisture sensor.

    Photos

    I bought the lamps on Jula.
    Lamp1 Battery 2/3 AAA 100 mAh, 10 SEK, 1 euro
    Lamp2 Battery 2/3 AA 200 mAh, 5 SEK, 0,5 euro
    Lamp3 Battery LR44 40 mAh, 10 SEK, 1 euro, NOT TESTED YET

    I removed all the electronic on the PCB and used the PCB as a connection board.
    The solar panel gives around 1,4 V during a very sunny day.
    I had to add a step-up(0,8->3,3V) to be able to run a ATMEGA. My first idea was to connect 2 batteries in series, but that was too much work. Now everything fits in the parts that is included.

    Lamp1 is using a Pro Mini(fake), glued soil sensor on "arrow"
    Lamp2 is using my designed PCB with ATMEGA328p, soil sensor just put in soil, not glued at all.
    Both MCU are using Optiboot, https://forum.mysensors.org/topic/3018/tutorial-how-to-burn-1mhz-8mhz-bootloader-using-arduino-ide-1-6-5-r5.
    Pro Mini:Power-on LED removed and also step-down. Activity-LED is still in use.
    My designed PCB:https://oshpark.com/shared_projects/F7esJEMY, also with LED for startup and send OK

    I am using @mfalkvidd sketch, thank you. I have only add a few rows(LED and resend function)
    It sends data(Humidity/Volt/VoltPercent every 10 second, just for testing the hardware later on I will send maybe twice an hour or once an hour.
    I am measuring the battery voltage on a analog input.

    #include <SPI.h>
    #include <MySensor.h>
    
    #define round(x) ((x)>=0?(long)((x)+0.5):(long)((x)-0.5))
    #define N_ELEMENTS(array) (sizeof(array)/sizeof((array)[0]))
    
    #define CHILD_ID_MOISTURE 0
    #define CHILD_ID_BATTERY 1
    #define SLEEP_TIME 10000 // Sleep time between reads (in milliseconds)
    #define THRESHOLD 1.1 // Only make a new reading with reverse polarity if the change is larger than 10%.
    #define STABILIZATION_TIME 1000 // Let the sensor stabilize before reading
    default BOD settings.
    const int SENSOR_ANALOG_PINS[] = {A4, A5}; // Sensor is connected to these two pins. Avoid A3 if using ATSHA204. A6 and A7 cannot be used because they don't have pullups.
    
    MySensor gw;
    MyMessage msg(CHILD_ID_MOISTURE, V_HUM);
    MyMessage voltage_msg(CHILD_ID_BATTERY, V_VOLTAGE);
    long oldvoltage = 0;
    byte direction = 0;
    int oldMoistureLevel = -1;
    float batteryPcnt;
    float batteryVolt;
    int LED = 5;
    
    void setup()
    {
      pinMode(LED, OUTPUT);
      digitalWrite(LED, HIGH);
      delay(200);
      digitalWrite(LED, LOW);
      delay(200);
      digitalWrite(LED, HIGH);
      delay(200);
      digitalWrite(LED, LOW);
      
      gw.begin();
    
      gw.sendSketchInfo("Plant moisture w solar", "1.0");
    
      gw.present(CHILD_ID_MOISTURE, S_HUM);
      delay(250);
      gw.present(CHILD_ID_BATTERY, S_MULTIMETER);
      for (int i = 0; i < N_ELEMENTS(SENSOR_ANALOG_PINS); i++) {
        pinMode(SENSOR_ANALOG_PINS[i], OUTPUT);
        digitalWrite(SENSOR_ANALOG_PINS[i], LOW);
      }
    }
    
    void loop()
    {
      int moistureLevel = readMoisture();
    
      // Send rolling average of 2 samples to get rid of the "ripple" produced by different resistance in the internal pull-up resistors
      // See http://forum.mysensors.org/topic/2147/office-plant-monitoring/55 for more information
      if (oldMoistureLevel == -1) { // First reading, save current value as old
        oldMoistureLevel = moistureLevel;
      }
      if (moistureLevel > (oldMoistureLevel * THRESHOLD) || moistureLevel < (oldMoistureLevel / THRESHOLD)) {
        // The change was large, so it was probably not caused by the difference in internal pull-ups.
        // Measure again, this time with reversed polarity.
        moistureLevel = readMoisture();
      }
      gw.send(msg.set((moistureLevel + oldMoistureLevel) / 2.0 / 10.23, 1));
      oldMoistureLevel = moistureLevel;
      
      int sensorValue = analogRead(A0);
      Serial.println(sensorValue);
      float voltage=sensorValue*(3.3/1023);
      Serial.println(voltage);
      batteryPcnt = (sensorValue - 248) * 0.72;
      batteryVolt = voltage;
      gw.sendBatteryLevel(batteryPcnt);
      resend((voltage_msg.set(batteryVolt, 3)), 10);
    
      digitalWrite(LED, HIGH);
      delay(200);
      digitalWrite(LED, LOW);
      
      gw.sleep(SLEEP_TIME);
    }
    
    void resend(MyMessage &msg, int repeats)
    {
      int repeat = 1;
      int repeatdelay = 0;
      boolean sendOK = false;
    
      while ((sendOK == false) and (repeat < repeats)) {
        if (gw.send(msg)) {
          sendOK = true;
        } else {
          sendOK = false;
          Serial.print("Error ");
          Serial.println(repeat);
          repeatdelay += 500;
        } repeat++; delay(repeatdelay);
      }
    }
    
    
    int readMoisture() {
      pinMode(SENSOR_ANALOG_PINS[direction], INPUT_PULLUP); // Power on the sensor
      analogRead(SENSOR_ANALOG_PINS[direction]);// Read once to let the ADC capacitor start charging
      gw.sleep(STABILIZATION_TIME);
      int moistureLevel = (1023 - analogRead(SENSOR_ANALOG_PINS[direction]));
    
      // Turn off the sensor to conserve battery and minimize corrosion
      pinMode(SENSOR_ANALOG_PINS[direction], OUTPUT);
      digitalWrite(SENSOR_ANALOG_PINS[direction], LOW);
    
      direction = (direction + 1) % 2; // Make direction alternate between 0 and 1 to reverse polarity which reduces corrosion
      return moistureLevel;
    }
    
    

    0_1465299264398_IMG_1337.JPG
    0_1465928822164_SolarPanel (2).png

    mfalkviddM 1 Reply Last reply
    10
    • F flopp

      I have build an Solar panel-powered Soil moisture sensor.

      Photos

      I bought the lamps on Jula.
      Lamp1 Battery 2/3 AAA 100 mAh, 10 SEK, 1 euro
      Lamp2 Battery 2/3 AA 200 mAh, 5 SEK, 0,5 euro
      Lamp3 Battery LR44 40 mAh, 10 SEK, 1 euro, NOT TESTED YET

      I removed all the electronic on the PCB and used the PCB as a connection board.
      The solar panel gives around 1,4 V during a very sunny day.
      I had to add a step-up(0,8->3,3V) to be able to run a ATMEGA. My first idea was to connect 2 batteries in series, but that was too much work. Now everything fits in the parts that is included.

      Lamp1 is using a Pro Mini(fake), glued soil sensor on "arrow"
      Lamp2 is using my designed PCB with ATMEGA328p, soil sensor just put in soil, not glued at all.
      Both MCU are using Optiboot, https://forum.mysensors.org/topic/3018/tutorial-how-to-burn-1mhz-8mhz-bootloader-using-arduino-ide-1-6-5-r5.
      Pro Mini:Power-on LED removed and also step-down. Activity-LED is still in use.
      My designed PCB:https://oshpark.com/shared_projects/F7esJEMY, also with LED for startup and send OK

      I am using @mfalkvidd sketch, thank you. I have only add a few rows(LED and resend function)
      It sends data(Humidity/Volt/VoltPercent every 10 second, just for testing the hardware later on I will send maybe twice an hour or once an hour.
      I am measuring the battery voltage on a analog input.

      #include <SPI.h>
      #include <MySensor.h>
      
      #define round(x) ((x)>=0?(long)((x)+0.5):(long)((x)-0.5))
      #define N_ELEMENTS(array) (sizeof(array)/sizeof((array)[0]))
      
      #define CHILD_ID_MOISTURE 0
      #define CHILD_ID_BATTERY 1
      #define SLEEP_TIME 10000 // Sleep time between reads (in milliseconds)
      #define THRESHOLD 1.1 // Only make a new reading with reverse polarity if the change is larger than 10%.
      #define STABILIZATION_TIME 1000 // Let the sensor stabilize before reading
      default BOD settings.
      const int SENSOR_ANALOG_PINS[] = {A4, A5}; // Sensor is connected to these two pins. Avoid A3 if using ATSHA204. A6 and A7 cannot be used because they don't have pullups.
      
      MySensor gw;
      MyMessage msg(CHILD_ID_MOISTURE, V_HUM);
      MyMessage voltage_msg(CHILD_ID_BATTERY, V_VOLTAGE);
      long oldvoltage = 0;
      byte direction = 0;
      int oldMoistureLevel = -1;
      float batteryPcnt;
      float batteryVolt;
      int LED = 5;
      
      void setup()
      {
        pinMode(LED, OUTPUT);
        digitalWrite(LED, HIGH);
        delay(200);
        digitalWrite(LED, LOW);
        delay(200);
        digitalWrite(LED, HIGH);
        delay(200);
        digitalWrite(LED, LOW);
        
        gw.begin();
      
        gw.sendSketchInfo("Plant moisture w solar", "1.0");
      
        gw.present(CHILD_ID_MOISTURE, S_HUM);
        delay(250);
        gw.present(CHILD_ID_BATTERY, S_MULTIMETER);
        for (int i = 0; i < N_ELEMENTS(SENSOR_ANALOG_PINS); i++) {
          pinMode(SENSOR_ANALOG_PINS[i], OUTPUT);
          digitalWrite(SENSOR_ANALOG_PINS[i], LOW);
        }
      }
      
      void loop()
      {
        int moistureLevel = readMoisture();
      
        // Send rolling average of 2 samples to get rid of the "ripple" produced by different resistance in the internal pull-up resistors
        // See http://forum.mysensors.org/topic/2147/office-plant-monitoring/55 for more information
        if (oldMoistureLevel == -1) { // First reading, save current value as old
          oldMoistureLevel = moistureLevel;
        }
        if (moistureLevel > (oldMoistureLevel * THRESHOLD) || moistureLevel < (oldMoistureLevel / THRESHOLD)) {
          // The change was large, so it was probably not caused by the difference in internal pull-ups.
          // Measure again, this time with reversed polarity.
          moistureLevel = readMoisture();
        }
        gw.send(msg.set((moistureLevel + oldMoistureLevel) / 2.0 / 10.23, 1));
        oldMoistureLevel = moistureLevel;
        
        int sensorValue = analogRead(A0);
        Serial.println(sensorValue);
        float voltage=sensorValue*(3.3/1023);
        Serial.println(voltage);
        batteryPcnt = (sensorValue - 248) * 0.72;
        batteryVolt = voltage;
        gw.sendBatteryLevel(batteryPcnt);
        resend((voltage_msg.set(batteryVolt, 3)), 10);
      
        digitalWrite(LED, HIGH);
        delay(200);
        digitalWrite(LED, LOW);
        
        gw.sleep(SLEEP_TIME);
      }
      
      void resend(MyMessage &msg, int repeats)
      {
        int repeat = 1;
        int repeatdelay = 0;
        boolean sendOK = false;
      
        while ((sendOK == false) and (repeat < repeats)) {
          if (gw.send(msg)) {
            sendOK = true;
          } else {
            sendOK = false;
            Serial.print("Error ");
            Serial.println(repeat);
            repeatdelay += 500;
          } repeat++; delay(repeatdelay);
        }
      }
      
      
      int readMoisture() {
        pinMode(SENSOR_ANALOG_PINS[direction], INPUT_PULLUP); // Power on the sensor
        analogRead(SENSOR_ANALOG_PINS[direction]);// Read once to let the ADC capacitor start charging
        gw.sleep(STABILIZATION_TIME);
        int moistureLevel = (1023 - analogRead(SENSOR_ANALOG_PINS[direction]));
      
        // Turn off the sensor to conserve battery and minimize corrosion
        pinMode(SENSOR_ANALOG_PINS[direction], OUTPUT);
        digitalWrite(SENSOR_ANALOG_PINS[direction], LOW);
      
        direction = (direction + 1) % 2; // Make direction alternate between 0 and 1 to reverse polarity which reduces corrosion
        return moistureLevel;
      }
      
      

      0_1465299264398_IMG_1337.JPG
      0_1465928822164_SolarPanel (2).png

      mfalkviddM Offline
      mfalkviddM Offline
      mfalkvidd
      Mod
      wrote on last edited by
      #2

      Very nice @flopp! Have a few lamps from Jula myself but haven't gotten round to use them yet.

      F 1 Reply Last reply
      0
      • F Offline
        F Offline
        flopp
        wrote on last edited by
        #3

        New schematic. I forgot the step-up

        1 Reply Last reply
        0
        • mfalkviddM mfalkvidd

          Very nice @flopp! Have a few lamps from Jula myself but haven't gotten round to use them yet.

          F Offline
          F Offline
          flopp
          wrote on last edited by
          #4

          @mfalkvidd
          I hope this can help you to use them.
          It takes maybe 1 hour to one lamp.

          1 Reply Last reply
          0
          • F Offline
            F Offline
            flopp
            wrote on last edited by flopp
            #5

            update
            I've let it be outdoor in the sun during 2-3 days now and it works well.
            yesterday I took one of them and placed it in the garage, totally black whole day not even a lamp.
            red line is when I moved it to the garage.
            it is sending every 10 second. After ~20 hours the battery was to low to be able to run Pro Mini
            0_1465505284492_volt.png

            dougD 1 Reply Last reply
            1
            • P Offline
              P Offline
              punter9
              wrote on last edited by
              #6

              this is genious

              1 Reply Last reply
              0
              • F Offline
                F Offline
                flopp
                wrote on last edited by flopp
                #7

                Do not let it run out of battery. I had to disconnect the power from solar panel to step-up and charge it(sun)for a few hours to get it to work again, or you could use some kind of connectors to disconnect. I was "smart" and solder it directly to step-up.

                martinhjelmareM 1 Reply Last reply
                0
                • F flopp

                  Do not let it run out of battery. I had to disconnect the power from solar panel to step-up and charge it(sun)for a few hours to get it to work again, or you could use some kind of connectors to disconnect. I was "smart" and solder it directly to step-up.

                  martinhjelmareM Offline
                  martinhjelmareM Offline
                  martinhjelmare
                  Plugin Developer
                  wrote on last edited by
                  #8

                  @flopp

                  I like this design. Do you think it will survive the Swedish winter days with their limited sun hours?

                  F 1 Reply Last reply
                  0
                  • martinhjelmareM martinhjelmare

                    @flopp

                    I like this design. Do you think it will survive the Swedish winter days with their limited sun hours?

                    F Offline
                    F Offline
                    flopp
                    wrote on last edited by
                    #9

                    @martinhjelmare said:

                    @flopp

                    I like this design. Do you think it will survive the Swedish winter days with their limited sun hours?

                    Yes, I think so. Today I send data every 10 seconds so if I send it once an hour it should not be a problem during winter. It will test to simulate rain and see if it is sealed enough.

                    1 Reply Last reply
                    1
                    • NeverDieN Offline
                      NeverDieN Offline
                      NeverDie
                      Hero Member
                      wrote on last edited by
                      #10

                      What kind of soil moisture sensor is it?

                      1 Reply Last reply
                      0
                      • mfalkviddM Offline
                        mfalkviddM Offline
                        mfalkvidd
                        Mod
                        wrote on last edited by mfalkvidd
                        #11

                        It is just a simple pitchfork, like this http://www.aliexpress.com/item/10pcs-Soil-Hygrometer-Detection-Module-Soil-Moisture-Sensor-Probes/2051713873.html

                        NeverDieN 1 Reply Last reply
                        1
                        • dbemowskD Offline
                          dbemowskD Offline
                          dbemowsk
                          wrote on last edited by
                          #12

                          I love this concept. This kind of setup could be used for outdoor temp, light, humidity, and other things and not having to worry about power with it being solar. It also keeps the arduino shielded from weather and such also which is nice. I may use this design for some of my new sensors.

                          Vera Plus running UI7 with MySensors, Sonoffs and 1-Wire devices
                          Visit my website for more Bits, Bytes and Ramblings from me: http://dan.bemowski.info/

                          F 1 Reply Last reply
                          0
                          • dbemowskD dbemowsk

                            I love this concept. This kind of setup could be used for outdoor temp, light, humidity, and other things and not having to worry about power with it being solar. It also keeps the arduino shielded from weather and such also which is nice. I may use this design for some of my new sensors.

                            F Offline
                            F Offline
                            flopp
                            wrote on last edited by
                            #13

                            @dbemowsk
                            If you have the solar in the sun and the sensors in the shadow and protected from rain that will work.
                            My idea is to use a solar for all my outdoor sensors but have a bigger solar panel and a bigger(more mah) that feeds my nodes, rain, temp, hum, pressure, light, UV and in future lightning.

                            breimannB 1 Reply Last reply
                            0
                            • mfalkviddM mfalkvidd

                              It is just a simple pitchfork, like this http://www.aliexpress.com/item/10pcs-Soil-Hygrometer-Detection-Module-Soil-Moisture-Sensor-Probes/2051713873.html

                              NeverDieN Offline
                              NeverDieN Offline
                              NeverDie
                              Hero Member
                              wrote on last edited by
                              #14

                              @mfalkvidd
                              Thanks for posting that link! Even though I don't believe in these types of sensors, I used your link to buy some anyway just because they're so darn cheap!

                              1 Reply Last reply
                              0
                              • mfalkviddM Offline
                                mfalkviddM Offline
                                mfalkvidd
                                Mod
                                wrote on last edited by mfalkvidd
                                #15

                                @NeverDie
                                If you just want to know when it is time to water regular home plants (0.5-2 times per week normally) , they are more than good enough.

                                If you want to maximize growth in a farming situation, you'll probably need to go for more advanced measurement methods.

                                1 Reply Last reply
                                0
                                • NeverDieN Offline
                                  NeverDieN Offline
                                  NeverDie
                                  Hero Member
                                  wrote on last edited by
                                  #16

                                  Good to know! I'll give it a try--I guess two months from now after they arrive. :wink: My wife has two dozen house plants, and so it would be nice if I could automate the monitoring.

                                  1 Reply Last reply
                                  0
                                  • F Offline
                                    F Offline
                                    flopp
                                    wrote on last edited by flopp
                                    #17

                                    I have noisy measurement on analog input for battery voltage.

                                    Anyone that know how I can solve that?

                                    All pictures during night so there shouldn't be any sun that create power. See schematic above how it is connected.

                                    First Node
                                    No cap. Measures every 10 seconds, picture is 5 minute average.
                                    0_1465806103475_volt.png

                                    Second Node.
                                    10uF electrolyte cap between GND and A0. Measure every 30 minute. Picture is 5 min average.
                                    0_1465806108764_volt2.png

                                    Third Node
                                    No cap. Measure every 30 minute. Picture is 5 min average.
                                    0_1465806821657_volt3.png

                                    I see a slightly better measurement on Seconds Node but can it be better? This is power directly from the battery and I think the battery should be more stable than this. I have other nodes were I measure the VCC on Arduino and that measurement is extremely stable. Maybe the analog input isn't better than what I get in the pictures?

                                    AWIA 1 Reply Last reply
                                    0
                                    • HuczasH Offline
                                      HuczasH Offline
                                      Huczas
                                      wrote on last edited by
                                      #18

                                      Could you show better scetch how you connect electicaly everything? how you sending data from arduino pro mini to Domoticz?

                                      In your scetch I see only power->battery->step-up->MCU

                                      F 1 Reply Last reply
                                      0
                                      • F flopp

                                        I have noisy measurement on analog input for battery voltage.

                                        Anyone that know how I can solve that?

                                        All pictures during night so there shouldn't be any sun that create power. See schematic above how it is connected.

                                        First Node
                                        No cap. Measures every 10 seconds, picture is 5 minute average.
                                        0_1465806103475_volt.png

                                        Second Node.
                                        10uF electrolyte cap between GND and A0. Measure every 30 minute. Picture is 5 min average.
                                        0_1465806108764_volt2.png

                                        Third Node
                                        No cap. Measure every 30 minute. Picture is 5 min average.
                                        0_1465806821657_volt3.png

                                        I see a slightly better measurement on Seconds Node but can it be better? This is power directly from the battery and I think the battery should be more stable than this. I have other nodes were I measure the VCC on Arduino and that measurement is extremely stable. Maybe the analog input isn't better than what I get in the pictures?

                                        AWIA Offline
                                        AWIA Offline
                                        AWI
                                        Hero Member
                                        wrote on last edited by
                                        #19

                                        @flopp I had exactly the same problem with a solar powered node. I solved it by moving the battery measurement around in the sketch. The analog measurement is sensitive..

                                        F 2 Replies Last reply
                                        0
                                        • HuczasH Huczas

                                          Could you show better scetch how you connect electicaly everything? how you sending data from arduino pro mini to Domoticz?

                                          In your scetch I see only power->battery->step-up->MCU

                                          F Offline
                                          F Offline
                                          flopp
                                          wrote on last edited by
                                          #20

                                          @Huczas said:

                                          Could you show better scetch how you connect electicaly everything? how you sending data from arduino pro mini to Domoticz?

                                          In your scetch I see only power->battery->step-up->MCU

                                          Electric connection as the attached schematic and NRF you connect according to MySensors instruction.
                                          Data is sent through the NRF with attached sketch

                                          1 Reply Last reply
                                          0
                                          Reply
                                          • Reply as topic
                                          Log in to reply
                                          • Oldest to Newest
                                          • Newest to Oldest
                                          • Most Votes


                                          4

                                          Online

                                          11.7k

                                          Users

                                          11.2k

                                          Topics

                                          113.0k

                                          Posts


                                          Copyright 2019 TBD   |   Forum Guidelines   |   Privacy Policy   |   Terms of Service
                                          • Login

                                          • Don't have an account? Register

                                          • Login or register to search.
                                          • First post
                                            Last post
                                          0
                                          • OpenHardware.io
                                          • Categories
                                          • Recent
                                          • Tags
                                          • Popular