What am I doing wrong here? ESP8266 + ADS1115

Okay, so I’ve got an ESP8266-based Plant Monitoring system. I have a large 26"x9" indoor herb garden that I’ve decided to fully automate.

It’s set up as follows:

Control: ESP8266MOD (NodeMCU v3)

Lights: 78x SK6812 Strip LEDs (attached to D4).

Relays: 1x 3.3v Relays (built to be expandable to 2x 3.3v relays if needed). The in-use one is attached to a 5v submersible water pump sitting in an 8L reserve tank. (Relays are assigned to D5 & D6)

Switch: Reed-switch style float, mounted in the side of the 8L reserve to detect when the water is low, attached to D7.

1x ADS1115 (assigned to SDA/D1 & SCL/D2)

Attached to A0 and A1 of the ADS1115 are:
2x Capacitive Moisture Sensors (v2.0), set to detect moisture levels in the soil.
(A2 and A3 are unused at the moment)

Sloppy Schematic:

The lights are on a circadian lighting plan (The Adaptive Lighting HACS add-on, controlled by HASS), and the watering is automated within ESPHome, but accessible within HASS as well. When toggled, the relay switches on for 15 seconds and stops. The relays, the switch, the LEDs all work fine.

What doesn’t work, is the detection on the ADS1115. I’m getting inconsistent results on A0 and zero results on A1, or rather A1 is always telling me 100% when the sensor is connected. Cables have been swapped out, moisture sensors have been swapped out, it doesn’t make a difference.

The only anomaly I can find is that when the lights are on (6:00am-7:00pm), the A0 moisture sensor has weird fluctuations in it’s values, but is rock-solid when the lights are off, as seen in my HASS history:

I’ve checked with my multimeter and everything that requires 3v3 is getting the required 3v3 (±0.01v). Everything that needs 5v is getting the required 5v (±0.01v). The LEDs are powered off the input voltage directly, and not through the ESP8266, so I don’t know why the lights themselves would affect anything. Everything is powered off a 5v 3a supply.

ESP Home code:

esphome:
  name: plantkit
  platform: ESP8266
  board: nodemcuv2
  on_boot:
    priority: -100
    then:
      - light.turn_on: plantlamp
      
wifi:
  ssid: !secret wifi_ssid
  password: !secret wifi_password
  use_address: 192.168.0.5
  manual_ip:
    static_ip: 192.168.0.5
    gateway: 192.168.0.1
    subnet: 255.255.255.0

  # enable fallback hotspot
  ap:
    ssid: "Plant Kit"
    password: !secret ap_password 
    
captive_portal:

i2c:
  sda: 4
  scl: 5
ads1115:
  - address: 0x48
    id: ads1115_X1
# Enable logging
logger:

# Enable Home Assistant API
api:
ota:

light:
  - platform: neopixelbus
    variant: SK6812
    type: GRBW
    pin: D4
    num_leds: 78
    name: "Plant Lighting"
    id: plantlamp
    default_transition_length: 1s

sensor:
  - name: "Soil Saturation Sensor 1 (Blue)"
    ads1115_id: ads1115_X1
    id: soil_sensor_1
    update_interval: 60s
    unit_of_measurement: "%"
    icon: "mdi:water-percent"
    gain: 4.096
    accuracy_decimals: 0
    multiplexer: 'A0_GND' # Don't Change
    filters:
      - calibrate_linear:
        - 0.7 -> 100.00
        - 2.625 -> 0.00
      - lambda:  |
          if (x < 0) return 0; 
          else if (x > 100) return 100;
          else return (x);
    platform: ads1115
  - name: "Soil Saturation Sensor 2 (Red)"
    ads1115_id: ads1115_X1
    id: soil_sensor_2
    update_interval: 60s
    unit_of_measurement: "%"
    icon: "mdi:water-percent"
    gain: 4.096
    accuracy_decimals: 0
    multiplexer: 'A1_GND'
    filters:
      - calibrate_linear:
        - 0.7 -> 100.00
        - 2.625 -> 0.00
      - lambda:  |
          if (x < 0) return 0; 
          else if (x > 100) return 100;
          else return (x);
    platform: ads1115

binary_sensor:
  # Water Level (Tells if level is low)
  - platform: gpio
    pin: 
      number: D6
      mode: INPUT_PULLUP
    name: "Water low"
    id: water_low
    device_class: moisture
# SPARE RELAY
#  - platform: gpio
#    pin: 
#      number: D7
#      inverted: true
#      mode: INPUT_PULLUP
#    name: "Water low"
#    id: water_low
#    device_class: moisture

time:
  - platform: homeassistant
    id: homeassistant_time
    on_time:

  # Run water pump check momentarily on a schedule
      - seconds: 0
        minutes: /7
        then:
        - if:
            condition:
              lambda: 'return (id(soil_sensor_1).state < 50 || id(soil_sensor_2).state < 50) && id(automatic_watering).state;'
            then:
              - switch.turn_on: water_pump_relay

           
switch:
  # Water Pump (Switch on watering)
  - platform: gpio
    pin: D7  
    name: "Water Pump Relay"
    id: water_pump_relay
    #internal: true
    on_turn_on:
      - delay: 15sec
      - switch.turn_off: water_pump_relay

  # Dummy switch to turn automatic watering on and off
  - platform: template
    name: "Automatic Watering"
    id: automatic_watering
    optimistic: true

Am I just overtaxing the ESP8266 somehow?

Do you also have an idea what 3.3V LDO your board has at what the maximum current it (theoretically) outputs?

They are 3.3V relays you wrote. I expect you are asking to much from your LDO in the situation the relay are on. As best practice I always try to avoid any sensors and actors on the 3.3V rail from a esp and always try to make use of the (external) 5V I provide as I can guarantee sufficient juice current this way. I think even that 5V relays are cheaper than 3.3V ones :wink:

As of right now, it’s a single 3v3 relay—the second is disconnected and not in use. Its existence in the schematic is merely future proofing additional need. The single relay is only meant to be called upon very rarely. Its active current is 65mA, trigger at 3mA. The problem with using 5v relays is they don’t trigger reliably well on a 3v3 data pin on their own. No need to build extra complexity into the schematic by adding a transistor when using a relay with the correct data voltage works just fine.

Regardless, disconnecting the relay (everything’s plugged in via JST connectors) doesn’t change a lick.

The ADS1115 has an active current of 150uA and the capacitive moisture sensors are each 5mA of active current.

the AMS1117 in the NodeMCU is rated for 1.5A max, but I shouldn’t be going nowhere near that number. On all the pins, I’m using a maximum of 75.15mA + 170mA max draw from the ESP8266 chip itself.

I’ve read a similar problem in the arduino forums. Turned out to be a faulty input.
Try another input or even better another ADS boards.

So the behavior stays the same if there is no “load” (relay) is connected to the gpio? But then if you toggle the gpio (without anything connected?) it still results in this:

Now I see the “lights” are not controlled by the relay but are digital addressable ones :bulb:

Do you have an idea about the power/current draw (from the gpio) for addressing the 78 leds you have connected on D4?

Wasn’t aware of AMS1117 with that (high) output rating - I only came across ones with lower output (like theoretical 0.8A, 1A max)

That’s true but sometimes the “rated” output is not what you get and a esp can also be “spiky” at times… :zap:

That is not the “real life” maximum - it’s not even the maximum from the data sheet actually but labeled “typical”.

Depends at what sources you are looking the maximum (peak) current can be easily the double amount you assumed - some even measure a 1A burst for the esp8266

I use a lot of 5V relays and they all trigger without problems on the 3.3V gpio’s of my esp’s. The (~30) relays I have all trigger around 2.5V - that’s no problem for a esp at all (output high is 3.3V) :muscle:

Using relays on the same power supply as esp is just calling for troubles. Relays are very noisy “bastards” and their power supply should be as far away from esp as possibly. I have “tons” of 5V relays, triggering with 3.3V and not one problem., That stated, even better is to use optocopulers…

AMS1117 has max.nominal current stated 1A, max is 1.5, but don’t rely on that, drawing so much you’ll destroy it in seconds/minutes. It would require way better cooling than it has now on nodeMCU board. Don’t look max values, look for nominal ones. Max are allowed for (milli)seconds.

And, yes, esp boards can spike well over 170mA and if PSU is not capable of delivering reset can occur easily.
In general, i wouldn’t hang all externals on board’s 3.3V psu. Make a separate one. Some low-current sensors, yes, but relays… a big no-no.

1 Like

Easiest fix for you is probably just using 5V directly for the ADS1115 and your Capacitive Moisture Sensors :white_check_mark:

1 Like

I’ll point out yet again, that there’s no change if the relay is disconnected. The relay is a good 45cms from the ESP unit anyway.

It would also stand to reason that not much would be affected re: the load until a relay is triggered. Which in the case of my planter, is not very often.

Yeah, well…
i’d do some preventive tests, like connecting some fixed voltage to A0…A3 inputs and see if it stays constant - this way you’d test ADS chip if it’s ok. Connect, say, two resistors, like in order of 10kohm from plus to A0 and from A0 to GND - that way you’ll get 3.3V/2 voltage on A0. If this will stay constant, try to “load” moisture sensor’s output: connect a resistor in parallel to A0 and GND (10k, or even 4k7 will do). Maybe you get some kind of other nosie. Also make sure that there are 100nF capacitors present in your circuit’s power supply (and, of course, some electrolytic ones).