Solar Powered Soil Moisture Sensor

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


    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,
    Pro Mini:Power-on LED removed and also step-down. Activity-LED is still in use.
    My designed PCB:, 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);
      digitalWrite(LED, LOW);
      digitalWrite(LED, HIGH);
      digitalWrite(LED, LOW);
      gw.sendSketchInfo("Plant moisture w solar", "1.0");
      gw.present(CHILD_ID_MOISTURE, S_HUM);
      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 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);
      float voltage=sensorValue*(3.3/1023);
      batteryPcnt = (sensorValue - 248) * 0.72;
      batteryVolt = voltage;
      resend((voltage_msg.set(batteryVolt, 3)), 10);
      digitalWrite(LED, HIGH);
      digitalWrite(LED, LOW);
    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 ");
          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
      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_1465928822164_SolarPanel (2).png

  • Mod

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

  • New schematic. I forgot the step-up

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

  • 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

  • this is genious

  • 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.

  • Plugin Developer


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

  • @martinhjelmare said:


    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.

  • Hero Member

    What kind of soil moisture sensor is it?

  • Mod

  • 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.

  • @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.

  • Hero Member

    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!

  • Mod

    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.

  • Hero Member

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

  • 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.

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

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

    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?

  • 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

  • Hero Member

    @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..

  • @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

Log in to reply





Looks like your connection to MySensors Forum was lost, please wait while we try to reconnect.