I need help for my code

I need someone skilled to be able to help me with my code. I have an esp8266 connected to an ads 1115. The code below is just to connect me to a dht11, to a water level sensor. In addition to these sensors, I have a soil moisture sensor and a 6000 theme that I connected to ads1115 via pins A0 and A1. In addition to these sensors, I also have a 3-6 v water pump and a relay connected to pin D7 of the esp.

• Hardware model + communication type. NodeMCU Esp 8266 + ADS 1115 WiFi connection
• Smartphone OS (iOS or Android) + version: Android, version 2.27.30
• Blynk server or local server: I use my own local server. My blynk c++ version is 1.0.0

This is my code but, my soil mosture sensor it’s not going well, the values ​​are bad.

#include <SimpleTimer.h>
#define BLYNK_PRINT Serial    
#include <SPI.h>
#include <ESP8266WiFi.h>
#include <BlynkSimpleEsp8266.h>
#include <DHT.h>
#include <Wire.h>
#include <Adafruit_ADS1015.h>
Adafruit_ADS1115 ads;

 char auth[] = ""; 
 char ssid[] = "Clicknet";  
 char pass[] = "ACASA123";



//senzor apa start
 const int sensorPin= A0;
 float liquid_level;
 int liquid_percentage;
 int top_level = 500;
 int bottom_level = 0;
//senzor apa end

#define DHTPIN 2          
#define DHTTYPE DHT11     

SimpleTimer timer;

void sendSensor()
  float h = dht.readHumidity();
  float t = dht.readTemperature(); 

  if (isnan(h) || isnan(t)) {
    Serial.println("Failed to read from DHT sensor!");
  Blynk.virtualWrite(V5, h);  
  Blynk.virtualWrite(V6, t); 

void setup()
  Serial.println("ADC Range: +/- 6.144V (1 bit = 3mV/ADS1015, 0.1875mV/ADS1115)");  
  pinMode(sensorPin, INPUT);
  Blynk.virtualWrite(V0, liquid_level);
  Blynk.virtualWrite(V1, liquid_percentage);
  Blynk.begin(auth, ssid, pass);

  timer.setInterval(1000L, sendSensor);

void loop()
   int16_t adc0, adc1, adc2, adc3;
   adc0 = ads.readADC_SingleEnded(0);  
   adc0 = adc0 / -180,5; 
   Serial.print("SOIL MOISTURE");

   liquid_level = analogRead(sensorPin);
   liquid_percentage = ((liquid_level-bottom_level)/top_level)*100;

   Blynk.virtualWrite(V2, adc0);
   Blynk.virtualWrite(V0, liquid_level);
   Blynk.virtualWrite(V1, liquid_percentage);



@Petraru_Cosmin please edit your post, using the pencil icon at the bottom, and add triple backticks at the beginning and end of your code.
Triple backticks look like this:

Please state your connection type (WiFi, Bluetooth etc)

Please state the actual version number as shown in the app.

Which are you using, the Blynk cloud servers, or your own local server?

Also, we need to know which version of the Blynk C++ library you are using.

Without these corrections, your topic will be deleted.



1 Like

No its not, the triple backticks are still missing.


1 Like

@Petraru_Cosmin you’ve edited your post, but despite me giving you triple backticks to copy/paste you’ve used different characters, which don’t work.

Please edit your post and add triple backticks at the beginning and end of your code, otherwise the unformatted code will be deleted.


1 Like

Your code has a few problems to start with. Remove all virtualWrites and delays from the loop. There is some good info here Documentation for Blynk, the most popular IoT platform for businesses.

That may fix your problems, depending what “values are bad” means, but if it doesn’t do you have non Blynk code that is working?

Also the DHT doesn’t like being polled more than every 5s. In reality you probably don’t need more than every minute or 5.


Maybe his temperature changes every second :thinking::thinking:


The DHT data is good.I have a problem bcs i don t know to code the soil moisture and the temt 6000 sensor value with the ADS1115.And i don t know to code my water pump with soil moisture and water level sensor variables.

As @daveblynk said, you have first to clean your loop

I’ll clean the loop, but still I would like someone to give me the code for what I asked above if someone knows how. I would be very grateful

This isn’t really a code factory. These aren’t really Blynk issues. If you google how to get these sensors working, get a working sketch printing values to serial (without Blynk) any of us can help you display that data on Blynk.

I think I have heard on here before, “Google is your friend” :slight_smile:

Wemos and ADS1015 example - esp8266 learning should give you a jump on the ADS
TEMT6000 Light/Lux sensor supported? - Let's Control It doesn’t rate the TEMT very high!

Once you got the ADS working with the TEMT print the numbers you are getting and you should be 90% there.