Back for more advice, but an Easier plugin I think

Moderators: grovkillen, Stuntteam, TD-er

Post Reply
Message
Author
Drum
Normal user
Posts: 300
Joined: 07 Feb 2016, 11:56

Back for more advice, but an Easier plugin I think

#1 Post by Drum » 31 Aug 2016, 23:10

I found something pretty close to what have been trying to make, on Tindie for less than I can build it for. AN ESP Soil Moisture sensor based on the Chirp, but not i2c and with an ESP-12.
ESPSOILMOISRURE.jpg
ESPSOILMOISRURE.jpg (62.27 KiB) Viewed 5146 times
I received 5 of them to try and ESPEasy works with the DHT11 and reading the ADC voltage, but from what I can figure out, it also uses another pin to send voltage. Since they are fixed pins there is no selection so I can probably get away with the same web-menu as the ADC plugin, but not sure how to get that other pin to send out whatever it is sending.
From their code at https://github.com/AprilBrother/esp-soi ... ure-sensor
I see these lines:

I think I understand these

const int pin_clk = 5;
const int pin_soil = A0;
const int pin_led = 12;

pinMode(pin_clk, OUTPUT);
pinMode(pin_soil, INPUT);
pinMode(pin_led, OUTPUT);
digitalWrite(pin_led, LOW);


These I have no idea what they do

analogWriteFreq(40000);
analogWrite(pin_clk, 400);


There are some others related to the DHT11 but I don't know if the pin 5 is sending something specific. Just setting it as Output High or low doesn't do anything
I am hoping it can be a simple tickbox in the ADC plugin, or even a fork, as it is pretty limited by design, so I don't need all the plugins for this.
I have been e-mailing them and they are also working on the same thing but with a tmp112 rather than the DHT11, which should be far more accurate.

Anyone have any thoughts on this? I did attempt to modify the ADC plugin as well as the HC-SR04 plugin,but after I fixed all the errors in the plugins I started getting other errors in ESPEasy.ino. I haven't had time to get back to it yet..

User avatar
costo
Normal user
Posts: 500
Joined: 21 Nov 2015, 15:03
Location: NL, zw-NB

Re: Back for more advice, but an Easier plugin I think

#2 Post by costo » 02 Sep 2016, 21:43

Documentation at https://github.com/esp8266/Arduino/blob ... ference.md says:
Analog output

analogWrite(pin, value) enables software PWM on the given pin. PWM may be used on pins 0 to 16. Call analogWrite(pin, 0) to disable PWM on the pin. value may be in range from 0 to PWMRANGE, which is equal to 1023 by default. PWM range may be changed by calling analogWriteRange(new_range).

PWM frequency is 1kHz by default. Call analogWriteFreq(new_frequency) to change the frequency.
The sensor is feed with the PWM signal and the avarage voltage is measured.
The components that are part of the soil sensor are not in the schematic.

Drum
Normal user
Posts: 300
Joined: 07 Feb 2016, 11:56

Re: Back for more advice, but an Easier plugin I think

#3 Post by Drum » 02 Sep 2016, 23:18

Thanks, that explains it pretty clearly. I will have to do some reading there. I was looking at other plugins today and I think the dust sensor plugin might be a good place to start. I only had time to do some quick changes, which did not work, but I will also check the pwm plugin to see how the code is structured and try some more this weekend.

Schematic for the sensor part is here:
https://github.com/Miceuz/PlantWatering ... matics.png

The ESP soil moisture sensor is based on the chirp, with some changes. There is a chirp sensor board which is I2c and has some other sensors as well. The schematic for this esp board only shows the differences, or the changes they made, I believe. Gpio5 feeds the center oval section with a resistor inline, and the outer section and back feed in to ADC through a diode, resistor and capacitor.

I think there are probably some variability in the readings as the batteries age. I took the battery holder off and added a voltage regulator which is supposed to deliver 3.3v at 600mAH from 5.5 to 3.5V. I have too look at the specs, but I believe it shuts down if the voltage drops below 3.5v, which would help protect the Lipo.

User avatar
costo
Normal user
Posts: 500
Joined: 21 Nov 2015, 15:03
Location: NL, zw-NB

Re: Back for more advice, but an Easier plugin I think

#4 Post by costo » 03 Sep 2016, 00:07

Thanks for the schematic.
That explains it why the PWM is swiched to 40kHz.
Sensor Track is the part which is put into the soil.
Depending on the soil moisture the capacitance (sensor Track) varies. The signal is more or less attenuated and the resulting voltage is rectified and measured, the average is used to calculate the relative soil moisture . I assume the diode is a germanium (type AA121 or so) or a schottky diode (low drop voltage , meaning more sensitive for small signals)

It is a neat sensor. It is a capacitive sensor, preventing any DC-current in the sensor which would inevitable lead to a degradation/corrosion of the copper. When measuring with DC the sensor needs to be made of bare copper/metal so the ground-resistance can be measured. Now the measurement is done with a 40kHz AC and the sensor can be isolated, preventing a degradation of the copper/metal parts when put in the moisty ground.


edit:
Someone who likes experimenting and soldering could try to modufy these cheap sensors http://www.aliexpress.com/item/1pcs-lot ... 12818cc4b0
to work with the ESP, using this software and schematic, and painting the sensor with an isolating spray so they will not corrode.

Drum
Normal user
Posts: 300
Joined: 07 Feb 2016, 11:56

Re: Back for more advice, but an Easier plugin I think

#5 Post by Drum » 07 Sep 2016, 18:53

I managed to get it working, but there is some variability in the readings, dry is 850 +- 10, and wet is about 750 +- 10. This is probably why the original code takes an average, but I haven't been able to get that to work yet. Until I figure that out I can always have Node-Red average a few values. It isn't pretty, but it works if anyone is interested in these things.... Now I have to figure out how to put some in the garden and see how well they work. It is based on the dust sensor as it already had an input and an output.

Code: Select all

//#######################################################################################################
//#################################### Plugin 116: ESP Soil Sensor V1.1##################################
//#######################################################################################################

#define PLUGIN_116
#define PLUGIN_ID_116 116
#define PLUGIN_NAME_116 "ESP Capacitive Soil Moisture Sensor"
#define PLUGIN_VALUENAME1_116 "Moisture"

boolean Plugin_116_init = false;
byte pin_soil = 0;

boolean Plugin_116(byte function, struct EventStruct *event, String& string)
{
  boolean success = false;

  switch (function)
  {
    case PLUGIN_DEVICE_ADD:
      {
        Device[++deviceCount].Number = PLUGIN_ID_116;
        Device[deviceCount].Type = DEVICE_TYPE_SINGLE;
        Device[deviceCount].VType = SENSOR_TYPE_SINGLE;
        Device[deviceCount].Ports = 0;
        Device[deviceCount].PullUpOption = false;
        Device[deviceCount].InverseLogicOption = false;
        Device[deviceCount].FormulaOption = true;
        Device[deviceCount].ValueCount = 1;
        Device[deviceCount].SendDataOption = true;
        Device[deviceCount].TimerOption = true;
        Device[deviceCount].GlobalSyncOption = true;
        break;
      }
    case PLUGIN_GET_DEVICENAME:
      {
        string = F(PLUGIN_NAME_116);
        break;
      }
    case PLUGIN_GET_DEVICEVALUENAMES:
      {
        strcpy_P(ExtraTaskSettings.TaskDeviceValueNames[0], PSTR(PLUGIN_VALUENAME1_116));
        break;
      }
    case PLUGIN_INIT:
      {
        Plugin_116_init = true;
		pin_soil = 5;  
        pinMode(pin_soil, OUTPUT); 
        success = true;
        break;
      }

    case PLUGIN_READ:
      {
        pin_soil = 5; 
      
        int value;
        value = 0;
       {
		  analogWrite(pin_soil, HIGH);
		  analogWriteFreq(40000);
		  analogWrite(pin_soil, 400); 
          delayMicroseconds(500);
          value = analogRead(A0);
        }
               UserVar[event->BaseVarIndex] = (float)value;
        String log = F("Soil Moisture value: ");
        log += value;
        addLog(LOG_LEVEL_INFO, log);
        success = true;
	        break;
      }
  }
  return success;
}

Drum
Normal user
Posts: 300
Joined: 07 Feb 2016, 11:56

Re: Back for more advice, but an Easier plugin I think

#6 Post by Drum » 19 Sep 2016, 13:30

I am having some odd issues with this one. I am still trying different things, but if I set pin 5 to default the first reading for soil moisture is always "2" and if I set pin 5 to Output High, it is always 859 or close. Doesn't matter if wet or dry. And the dht-11 doesn't seem to like to run when the soil moisture sensor plugin is active.
So far most of the testing has been with the delay, and multiple readings. I can set a loop to take 10 readings and the first cycle is always really low, the second is always as expected. The difference the delay makes is how long it take it to top out when dry. With pin 5 set to output high and 2500ms delay, the 3rd through 10th readings are 903. 50ms delay it takes longer to get to 903, 7 or 8 readings. First is close to 890.

My first thought it I have it sending the signal on pin 5 out after the first cycle, which also might explain why the dht-11 always works on the first cycle and then almost always drops out.

Not being a programmer I have to ask, am I making some simple mistake with this?

Post Reply

Who is online

Users browsing this forum: No registered users and 49 guests