Soil Moisture Sensor/HC-SR04 to Arduino Uno

Hello community,

We’re planning to implement IoT to our Gardening System for our school project using the following:
–Soil Moisture Sensor
–Ultrasonic Sensor (HC-SR04) as our water level sensor
–Arduino Uno (as microcontroller)
–ESP8266-01 (as our Wi-Fi Module)

The problem is that, we’re only seeing reference to the mentioned sensors above (soil moisture and ultrasonic) to nodeMCU… Is it not possible to integrate in Arduino Uno and Blynk?

We tried implementing the Soil Moisture with Blynk Application
Here’s our code with ESP8266-01 as our Wi-Fi Module

#define BLYNK_PRINT Serial

#include <ESP8266WiFi.h>
#include <BlynkSimpleEsp8266.h>
//BlynkTimer timer;
// You should get Auth Token in the Blynk App.
// Go to the Project Settings (nut icon).
char auth[] = "xxxxxx";

// Your WiFi credentials.
// Set password to "" for open networks.
char ssid[] = "xxxxxx";
char pass[] = "xxxxxx";
BlynkTimer timer;
int sensorData;

void myTimerEvent()
  sensorData = analogRead(A0);
  Serial.print("Value: ");
  int map_value = map(sensorData,1023,335,0,100);
  Serial.print("Moisture: ");
  Blynk.virtualWrite(V5, sensorData);
  Blynk.virtualWrite(V6, map_value);
void setup()
  // Debug console
  Serial.println("Reading From the Sensor ...");
  Blynk.begin(auth, ssid, pass);
  timer.setInterval(1000L, myTimerEvent);

void loop()

Note: We’re getting correct values using the mentioned sensors without the Blynk, but implementing it to the app itself gives us incorrect/fluctuating values :frowning:

We used this reference for the code:

Any help or recommendation will be good. Thank you.


please do not use a delay on blynk that’s not gonna have you emailed a code like I did

#define BLYNK_PRINT Serial
#include <OneWire.h>
#include <DallasTemperature.h>
#include <SPI.h>
#include <Fishino.h>
#include <BlynkSimpleFishino.h>
#include <TimeLib.h>
#include <WidgetRTC.h>
char auth[] = "80a7af7c4258";
#define ONE_WIRE_BUS 2
OneWire oneWire(ONE_WIRE_BUS);
float tempout = 0;
DallasTemperature sensors(&oneWire);
BlynkTimer timer;
WidgetLED led6(V3);
WidgetLED led4(V8);
char Date[16];
char Time[16];
int sensorValue = 0;
int sensorPin = A0;
int sensorValuePercent = 0;
float current = 0.0;
WidgetRTC rtc;

  int state = param.asInt();
  if (state) {
   Blynk.setProperty(V8, "color", "#FF00FF");
  } else {
   Blynk.setProperty(V8, "color", "#3ADF00");
void clockdata()
  sprintf(Time, "%02d:%02d:%02d", hour(), minute(), second());
  sprintf(Date, "%02d/%02d/%04d", day(), month(), year());
  Serial.print("Uhrzeit und Datum ");
  Serial.print(" ");
  Blynk.virtualWrite(V1, Time);
  Blynk.virtualWrite(V2, Date);
void Twitter(){
  Blynk.tweet (String ("Temperatur ist : ") + sensors.getTempCByIndex(0) + "°C / Bodenfeuchte ist : " + sensorValue + "% um " + (Time) + " am " + (Date));
void Bodenfeucht(){
  sensorValue = analogRead(sensorPin);
  sensorValue = map(sensorValue, 0, 1023, 1023, 0);
  sensorValuePercent = (sensorValue / 1023) * 100;
  Serial.print (String ("Bodenfeuchte ist : ") + sensorValue = analogRead(sensorPin));
  Blynk.virtualWrite(V7, sensorValue,current);
void Temperaturmessung(){

  tempout = (sensors.getTempCByIndex(0));
  Serial.print (String ("Temperatur ist : ") + sensors.getTempCByIndex(0));
  Blynk.virtualWrite(V4, tempout);
  if (tempout < 9.99) {
   Blynk.setProperty(V3, "color", "#FF00FF");
    Blynk.setProperty(V3, "label", "schön warm 🌡 °C"); 
    Blynk.setProperty(V4, "label", "arsch kalt °C");
  if (tempout > 10 && tempout < 19) {
    Blynk.setProperty(V4, "label", "Temperatur normal °C");
  if (tempout > 20 && tempout < 69.99) {
    Blynk.setProperty(V4, "label", "schön warm °C");
void setup()
  // Debug console
timer.setInterval(1000, clockdata);
timer.setInterval(1000, Bodenfeucht);
timer.setInterval(1000, Temperaturmessung);
timer.setInterval(15000, Twitter);
Blynk.begin(auth, " ", " ");


void loop()

Yes it’s possible but for basic projects ESP’s in standalone mode are easier and cheaper. Swap the Uno and ESP8266-01 for a ‘WeMos’ style board.

Someone on hackster did something similar, have a look maybe it will help.

Hello sir, thank you for responding but the project itself is focused only on Water Level Monitoring (which means it doesn’t have any integration or additional modules). We’re in need of reference in terms of integrated modules for plant monitoring and watering system.

Well, compare the size of an UNO and the required ESP-01 (Left) and a fully functional, standalone, Wemos D1 Mini (Right)

PS, aside from libraries, pin numbering format and a few other peculities like analog bit depth, etc., they will both easily connect to multiple sensors and use pretty much the identical coding. And the Wemos itself is less then $5 online.