IoT Hydroponics - Measure EC

About: Add the ability to measure pH, ORP, EC or salinity to your Arduino or Raspberry Pi project.

Intro: IoT Hydroponics - Measure EC

This instructable will show how to make a Bluetooth Low Energy Internet of Things device to monitor the Electrical Conductivity of a hydroponic nutrient solution.

The hardware will be any ESP32 development board and a uFire EC_Salinity probe interface.

We will display our data on a simple webpage that connects to our device through Web Bluetooth.

Step 1: Things You'll Need

  1. Any ESP32 development board. This one seems reasonable, but any will work.
  2. An EC_Salinity Probe Interface board and a K1 conductivity probe. You can get them both at ufire.co
  3. Some odds and ends like wires and USB cables.

Step 2: Connections

The ESP32 we are using has WiFi and BLE interfaces, so that just needs a power supply. You'll probably want a USB cable supplying mains power, but a battery is another option. Many ESP32s can be bought with battery charging circuitry already on the board.

The uFire device that we will be measuring EC and temperature connect to the ESP32 by the I2C bus. With the ESP32, you can choose any two pins for I2C. Both devices will be on the same bus, so the SCL and SDA pins will be the same. If you look at the code, you will see this line.

uFire_EC_BLE ec_ble(19, 23);

I decided to use pin 19 for SDA and pin 23 for SCL. So Connect the ESP32's 3.3v (or whatever the pin may be called on your particular board) to the EC uFire device's 3.3/5v pin, GND to GND, 19 to SDA, and 23 to SCL. Now connect the uFire pH board to the EC board, pin for pin. Your ESP32 board may have a different pin-out than the picture.

Step 3: The Software

  1. I will assume you are familiar with Arduino, the Arduino IDE, and have it installed already. If not, follow the links.
  2. Next thing is getting the ESP32 platform installed. For some reason, this hasn't been simplified by the available platform management features the IDE has to offer, so you'll need to go to the github page and follow the appropriate installation instructions.
  3. Now for the libraries:
    1. From in the Arduino IDE, goto Sketch / Include Library / Manage Libraries... and search for and install 'EC_Salinity'.
    2. Search for and install 'ESP32 BLE Arduino'

Step 4: The Sketch

The sketch for this project is quick and easy.

You can find it on the github page. It will also be in the BLE example under File / Examples / EC_Salinity. And for good measure, it's attached to this instructable as well.

#include "uFire_EC_BLE.h"<br>
// On the ESP32, the I2C pins can be chosen. In this case, sda=19 and scl=23 
uFire_EC_BLE ec_ble(19, 23);

void setup() {
  // minimal setup of the EC_Salinity interface
  ec_ble.setK(1.0);
  // start the BLE server
  ec_ble.startBLE();
}
void loop() {
  // loop through and take continous measurements
  ec_ble.measureEC();
  ec_ble.measureTemp(); 
}

Step 5: Displaying Our Data

Now that the hardware is setup, we need a convenient way to display our data. For that, we will make a simple webpage that uses Web Bluetooth. If you aren't familiar with it, it's a Javascript API that is currently only available on Chrome. It allows you to connect to a BLE device from a webpage.

Have a look at the github repo.

As a quick overview:

  • it uses bulma.io for styling
  • knockout.js for front-end framework
  • app.js contains all the javascript code
  • index.html contains all the html

How exactly it all works would require quite a bit of typing, but some main points:

  • the data-bind html elements are what bind our data to our display. When that declared variable is updated, the webpage is also updated.
  • the javascript is fairly self-explanatory. It looks for devices with the prefix of 'uFire' in the name, connects to it and then registers to be notified whenever a value is changed.

Some things to keep in mind, if you want to develop your own webpage:

  1. it needs to be served from an https server, you can't access it from a local file (file://). Here is a good python https webserver to get started.
  2. Only Chrome version 55+ works for this particular implementation. You could write an app or program using the more traditional BLE APIs.
  3. Make sure Experimental Web Platform features is Enabled by going to chrome://flags/#enable-experimental-web-platform-features and restarting the browser. On newer versions of Chrome, this is enabled by default.

Step 6: Using the Webpage

Now that everything is put together, programmed, and the website is being served, we can look at the end result.


Open the website, in our case, it lives at https://ufire.co/uFire_BLE/, click the Bluetooth icon in the upper right and choose the uFire EC device. Now you should be seeing the EC reading in mS and the temperature in C.

You can also set some calibration options.

Share

    Recommendations

    • Tiny Home Contest

      Tiny Home Contest
    • Metalworking Contest

      Metalworking Contest
    • Audio Contest 2018

      Audio Contest 2018

    Discussions

    0
    None
    seamster

    3 months ago

    Good info, thank you.