Elijah Scheele
Published © GPL3+

Connected Soil Moisture Sensor

Simple Arduino/Genuino 101 BLE connected soil moisture sensor. Pair with IoT service to monitor and record measurements.

EasyWork in progress30 minutes4,483
Connected Soil Moisture Sensor

Things used in this project

Hardware components

Arduino 101 & Genuino 101
Arduino 101 & Genuino 101
×1
Soil Moisture Sensor
Can also use Sparkfun's moisture sensor
×1
Resistor 10k ohm
Resistor 10k ohm
Pullup for analog input.
×1

Story

Read more

Schematics

Soil Moisture Sensor Layout

Fritzing layout of basic soil moisture sensor.

Code

Soil Moisure Sensor Arduino/Genuino 101 Code

Arduino
Upload the code to your Arduino/Genuino 101. Use an app like nRF Connect or write your own BLE code to read/receive updated values for the soil moisture sensor.
#include <BLEAttribute.h>
#include <BLECentral.h>
#include <BLECharacteristic.h>
#include <BLECommon.h>
#include <BLEDescriptor.h>
#include <BLEPeripheral.h>
#include <BLEService.h>
#include <BLETypedCharacteristic.h>
#include <BLETypedCharacteristics.h>
#include <BLEUuid.h>
#include <CurieBLE.h>

//Soil sensor analog input pin
const int soilPin = A0;

BLEPeripheral blePeripheral;

//Soil Service and Characteristic - Custom UUID
BLEService soilService("19B10030-E8F2-537E-4F6C-D104768A1214");
BLEIntCharacteristic soilCharacteristic("19B10031-E8F2-537E-4F6C-D104768A1214", BLERead | BLENotify);





void setup() {
  //Set peripheral name and advertised services.
  blePeripheral.setLocalName("SoilSense");
  blePeripheral.setAdvertisedServiceUuid(soilService.uuid());
  blePeripheral.addAttribute(soilService);
  blePeripheral.addAttribute(soilCharacteristic);
  //set initial soil value to 0
  soilCharacteristic.setValue(0);
  //start peripheral
  blePeripheral.begin();
}

void loop() {
  //poll peripheral and read/set value
  blePeripheral.poll();
  int soilValue = analogRead(soilPin);
  Serial.println(soilValue);
  boolean soilChanged = (soilCharacteristic.value() != soilValue);

  if (soilChanged) {
    soilCharacteristic.setValue(soilValue);
  }
  //delay
  delay(500);
 }

Credits

Elijah Scheele

Elijah Scheele

8 projects • 49 followers
Developer interested in all sorts of cool projects.

Comments