Arduino Sketches

Hi all

Got some pressure sensors on the way from Aliexpress.

1 x 10Bar - Water pressure after booster pump.
2 x .5 Bar - Water pressure at the bottom of tank in pipe to booster pump, got 2 tanks.
1 x drop in 5M transducer/sensor - Will be configured for a friend, he has a cement tank that has a drop in pump, so will add a drop in sensor lying at the bottom.

All are 5v output based.

I’m looking for a sketch’s that can measure the voltage, convert to water level after having been zero’d, but then send the data to MQTT broker.

I have some Nodemcu’s and D1 Mini’s available.

G

If you would like to go Wifi , you will need to setup a voltage divider to get your volts down to maximum 3v (Personally if would say 2.5v just to be safe).
The ESP chip analog only reads to up 3.3v there after you get magic smoke…
Here is a very good tutorial on ADC read for ESP32 - ESP32 Analog Input with Arduino IDE | Random Nerd Tutorials.

Once you managed to read the ADC value you can map it to your pressure that corresponds to the pressure at that voltage.
After that part sorted you can then move over in publishing the data to MQTT
Here is a very good tutorial on how to read and publish sensor data via MQTT
ESP32 MQTT Publish Subscribe with Arduino IDE | Random Nerd Tutorials
The example should get you going fairly quickly.

Few things to consider

  • ESP board only have one ADC , it you want to read all the sensors on one board you will need to get a ADS1115 that can read up to 4 analog values.
  • How are you going to power the board (Things get messy very quickly with all the wires going all over the place).
    Hope it helps :slight_smile:

starting to think i will just do this with a rpi zero… and python.
but then need a ADC… fckd. hmm R 70/each… might be easiest…

question, why you say if i go wifi… the nodemcu and d1mini is both wifi…

I can do 1 board per sensor, to keep things simple.

G

just spoke to supplier… they can ship 5v input and a 3.3v output model, requested they change my order as such.
allows me to power it from the 5v power pin, but 3.3v for the ADC.
no magic smoke :wink:
G

I use a few esp and nodemcu boards and send data to HA, flash them with ESPhome, have 3 running voltage dividers(on the nodemcu’s their adc pins is a lot more stable than the ESP(older ones))
Mind sharing the links for the pressure sensors you ordered?

ESPhome have a lot of examples so its fairly easy to get things running, they also have things to filter out your readings, especially if you measure from above in a tank and have water coming ect.

  • platform: ultrasonic
    trigger_pin: D5
    echo_pin: D6
    unit_of_measurement: “%”
    icon: “mdi:water-percent”
    accuracy_decimals: 0
    update_interval: 0.5s
    name: “2kl Watertank”
    filters:
    • median:
      window_size: 10
      send_every: 10
      send_first_at: 1
    • lambda: return (1-((x-.22)/2))*100;
    • filter_out: nan

# tank height: 223cm, width 75
# height from full to sensor: 22cm (essentially sensors minimum distance)
# full tank: 180cm
# current reading: x
# ergo: used = (x - 22)
# ergo: remaining = (180 - used)
# ergo: percent = (remaining / 180) * 100

Sorry ,lost my train of though a bit. Was considering that could use a Uno with Ethernet shield but going Wifi should be easier.

happy to share, can i convince you to assist… I know the Rasp Pi platform and Python better.
Have done very little on the Arduino platform…

Here are the links to the 2 types of sensors ordered.
order:
1 x 10bar for measuring pressure in line after my booster pump.
2 x 0.5bar for measuring water level in 3m (4750L) water tanks.
the order has been changed to be 5v input and 0-3.3v output.
[4-20mA Pressure Transmitter Sensor 0.1bar/10bar/145psi 0-60Mpa 0-10V Pressure Transducer Sensor M20*1.5 Pressure Transmitter - AliExpress 1420](https://Type 1)

1 x 5M+10m cable
the order has been changed to be 5v input and 0-3.3v output.
[Submersible 0-10V 4-20mA Output Hydrostatic Level Sensor Transmitter DC12-36V Water Tank Liquids Transducer Meter 5m 10m 1-5V - AliExpress 1420](https://Type 2)

I want to send all output measured from these to a MQTT broker. this broken runs on a Home Assistant platform where I dashboard etc.

G

Getting the code going should not be to difficult and quite happy to help but I suspect getting the hardware setup for the programming is going to be the fun part.
I had a look at the sensor on Ally and it seems like the input PSU is 24V DC.
So just thinking about it you will need

  • 24v PSU
  • Buck converter to power the ESP chip
  • ADC converter for the sensor inputs (ADS1115 ADC)
  • PCB to put them all together
  • I would say a test rig to run your tests, water don’t mix well with electronics

The programming itself is fairly easy, you could even program the D1 with Tasmota and ADS1115 I2C Devices - Tasmota
It will then transmit the Analog values via MQTT and you can convert them post process in Node Red , Phyton extra.

spoke to them…

they had different models and shipping me 5v input units, with a 3.3v output.

how would this look like if done on arduino… looking above it looks like a BOM for the pi considering you got a ADC.

Looks like i got 1 x ESP32 based NodeMCU, believe they have 4 analog ports which will work for me and multiple 8266’s, and for them i only need 1 analog port for 1 sensor.

options is as you said to use / abuse tasmota… and might do the 1 D1Mini with the 1 sensor using tasmota… as thats going to a friend and it’s more hands off… for the NodeMCU with the ESP32 that will go here with me… might be keen to try a custom Arduino sketch for that, where we measure the 3 levels (might be a 4th down the line) and then send data to a MQTT… if there is problems with these can always then redo as Tasmota… now to jsut wait for the sensors… can then check confirm things…
need to put a water tube together that i can mark out to be able to zero/calibrate the setup…
G

As far a as I remember the 8266 have a ADC input range of 0-1V just make sure to divide the voltage enough. Have a look at RandomNerd’s site if you haven’t already. There is a ton of valuable info. He’s site is usually my first stop when I do anything with ESPs.

thanks, will do.

G

Went searching a bit.
ESP8266

ESP32:

I have not used the ESP32 yet. For the 8266 D1 Mini type boards the 0-1v applies. You might need to add a multiplier somewhere in your calculations. I use a multiplier of 3.3 to get my measurement correct. I have not tried a Dev board. I would treat the board as 0-1v and see what voltage is measured before decreasing the divider resistance to increase the resolution.

Decided to go RPI Zero paired with a MCP3008. used 10k pots during dev.

quick and easy Python program, all working, now just waiting for actual sensors.

G

hi hi.

Need someone to check my understanding… please see attached picture.
My units are 5V input, 0-3.3V output.

1 → 5v
2 → N - common
3 → Analog # (3.3v) MPC3008

The MCP3008 happily can be powered by 5v. so plan is to run that as a common positive in, to the chip and the sensor.
Then common negative
and then just the sensor output onto analog 0 in for the first sensor, and 1 for 2nd and so on.

M

bump.

G

hi hi all

please check this one…

Red is 5v in.
Do I have it correct, green is negative and yellow is 3.3v sensor output.

G