Inaccurate ADC readings due to fluctuating mains voltage

Hey!

I work on an indoor Hemp grow and have been having issues with my water tank level sensor getting inaccurate readings. After debugging the issue for a while I finally found the issue but I don’t know how to fix it yet. I am hoping someone here will be able to help me out.

The tank level sensor I am using is the AquaPlumb from Vegetronix. This device gets calibrated for the “no water” and “full water” levels and outputs a voltage from 0v (empty) to 3v (full). I already found the ADC on the esp8266 to be rather inaccurate so I order the ADS1115 to try and fix this issue and it actually did make things far more stable. The problem is that we are pulling hundreds of amps with our grow lights and when they turn on/off it causes my voltage readings to fluctuate quite a ridiculous amount (the tank will read empty because it is and the lights will all turn off causing the voltage to spike on the mains which then makes the sensor read “full tank” and vice versa when the power goes off).

So how can I combat this? It seems my transformer output moves with the input voltage (which totally makes sense) but I need a stable 5v reference for my ADC. I thought that possibly using a 120vac to 12vdc transformer then using a buck-converter or linear voltage regulator to take that 12v down to 5v but I am just curious if this will actually work. I did try moving the sensor to an independent power supply and tied the grounds together for reference and still had issues.

Esphome code:

i2c:
  sda: D2
  scl: D1
  scan: True
  id: bus_a

sensor:
  - platform: ads1115
    multiplexer: 'A0_GND'
    gain: 6.144 
    name: "Water Tank One Voltage"
    id: water_tank_one_voltage
    update_interval: 1s
    accuracy_decimals: 5
    filters:
      - sliding_window_moving_average:
          window_size: 60
          send_every: 60
  - platform: template
    name: "Water Tank One Level"
    lambda: !lambda return id(water_tank_one_voltage).state;
    update_interval: 60s
    accuracy_decimals: 0
    unit_of_measurement: "gallon"
    filters:
      - calibrate_linear:
          - 0.0 -> 0.0
          - 3.0 -> 2600.0
  - platform: template
    name: "Water Tank One Percent"
    lambda: !lambda return id(water_tank_one_voltage).state;
    update_interval: 60s
    accuracy_decimals: 2
    unit_of_measurement: "%"
    filters:
      - calibrate_linear:
          - 0.0 -> 0.0
          - 3.0 -> 100.0
  - platform: adc
    pin: VCC
    name: "Water Tank One VCC Voltage"

Any help is greatly appreciated :slight_smile:

If turning your lights on and off affects your mains that much, you don’t have a big enough mains.

Perhaps you should turn them on/off in smaller groups.

@nickrout The lights are already turning on in phases a few minutes apart because the power company will hit you with a huge fine if you spike their power that much. The problem is the mains voltage stays steady when the lights turn on/off so that doesn’t help at all (That’s why my graph above doesn’t spike when the lights turn on and then go back to normal levels).

Ok looks like you have that covered.

Try a capacitor over the input voltage terminals.

I had thought about that but wont a capacitor only smooth out constant fluctuations? Will it work for voltage that only go up and down once a day?

It may depend how big the cap is? As usual, try it and see.

Get a higher quality power supply for the ESP that doesn’t have voltage fluctuations with mains changes (no good supply should).
Connect a big filter capacitor (anything bigger than 100uF to about 1000uF) between your ESP power pin and ground.
Use shielded cable from the sensor to the ESP. Ground shield only at ESP end.
Increase the supply voltage of the sensor to 12V or higher (I see it supports up to 20) and use an external A/D converter that the ESP can read via I2C.
Or just ditch the A/D on the ESP (it kind of sucks) and use an external.
Change the code on the ESP so that it takes more than one sample then averages them together (20 - 100 samples, then average).

Exact same problem. Exact same project. Besides the ADS1115 what else did you try so far ?

So far capacitors and different power supplies didn’t fix the problem for me. I am now waiting for these to arrive to see if they will help with this problem:

My hope is the battery and boost converter inside the circuit will be able to keep things steady with the added bonus of keeping things working when the power goes out. For only $2 a piece I figured it was worth trying. Only downside is the shipping being about 30 days out.

I’m still curious if a simple voltage step up or step down converter would be able to keep it steady despite the VAC fluctuations. I haven’t had a chance to try this out but if someone else does and it works please do let me know.

Another fix I could do is just run a extension cord off one of our transformers that isn’t being heavily loaded (such as the one that provides power to our office). The downside of that is now I have to run hundreds of feet of extension cord for just a few sensors. This is why I am opting for another fix if possible.

I recently got some VH400 soil moisture sensors and they work great with a steady VAC source but once I moved them out onto our growing floor the power fluctuations from the lights turning on/off is clearly affecting the readings:

That graph is with a 470uf capacitor. Doesn’t really help at all.

Yea i figured the same solution (getting an extension cord).
Good to know. A lot of people really like the vh400, its price point still keeps me on the china moisture sensors for the time being but i feel that it will be inevitable and ill prob go with one soon anyway

So far I really like the VH400 especially since it doesn’t get affected by what is in the soil like some of the cheaper capacitive soil sensors I use do. The instant reading is also super handy.

I did have a very strange problem the other day with one of the VH400 sensors though. I tried plugging it into an outlet that is powered 24/7 out on the growing floor (most of our outlets are for lights and will turn on/off on a schedule). For some reason plugging it into this specific outlet was giving me 0% soil moisture readings but moving it to another outlet fixed it. I can’t say specifically what the cause is because testing the VAC and VDC voltages showed them being the same. The microcontroller was connecting to wifi and wasn’t seeing anything strange but the soil moisture sensor refused to work. The only thing I can think that it could be is maybe some sort of noise on the power line that is affecting the soil moisture sensor. I know the moisture sensor pulses on/off so maybe there is some noise and it is interfering with the frequency the sensor is trying to run at. I tried switching out the AC to DC transformer with about 3 different types and also tried various lengths of micro-usb cables for the microcontroller without any solution. I ended up having to run a 6 foot extension cord across the floor to fix it for now. It’s just strange because I have a raspberry pi camera running on that same outlet without any issues.

Are you using grow lights or some other load that is throwing off your readings as well? Or do you just have low quality power coming into your bulding? I’m quite surprised I can’t find anyone else that has posted about running into this same problem.

1 Like

Grow Lights, and just low rated circuits in genera. im justa dude in a house too lol. i was going nuts and it made no sense, when my lights go out it either increased or decreased moisture instantly lol. I have a lot of sensors in a small space so as long as i can get clean power in there i should be solid.
I had a similar idea to smooth out the ADC readings with a constantly charging/depleting battery pack. ive seen a few solar battery projects so i was thinking about doing one of those projects but then suppling with Voltage out and Ground for a microcontroller power supply, and multiple outputs etc.

I’m looking at the VH400s as well. Do you mind sharing your ESP code? Are you using ESPHome?

Also, I’m wondering if an isolated power supply might help with your fluctuations. Kind of like the power supplies that are used for guitar effects pedals to prevent noise bleeding over between pedals. They are pretty much all 9V DC, so you might have to utilize a step-down converter.

1 Like

I just went through single reading drops with an i2c sensor. My problem was pwm fans that I just moved to a separate esp.

I was able to bounce that single drop without having to average my readings. It’s not a solution but a work around for on board automations.

  - platform: ezo
    id: hum_ezo
    address: 111
    unit_of_measurement: "%"
    accuracy_decimals: 2
    update_interval: 1s
    name: "gp-ezo humidity"
    on_value_range:
      below: 74
      then:
        - delay: 1500ms
        - if:
            condition:
              lambda: return id(hum_ezo).state < 74;
            then:
              - switch.turn_on: relay

Hey @Skylord123, I’m doing the exact same thing as you and transitioning my vh400 sensors to ESPhome right now- any chance you’d be willing to share the code you used?