BLYNK
HOME       📲 GETTING STARTED       📗 DOCS       ❓HELP CENTER       👉 SKETCH BUILDER

DS18B20 + relay + node mcu + blynk coding problem

Hello, I am French and I hope my English will be understandable.
I want to check the temperature (ds18b20) with my nodemcu and check it with Blynk.
When the temperature exceeds 82 degrees the relay closes and when the temperature drops to 72 it turns back on.The code works correctly but as soon as I add the blynk code I can’t do it anymore. The error message appears: ‘A1’ was not declared in this scope.
Thanks for your help


#include <ESP8266WiFi.h>
#include <BlynkSimpleEsp8266.h>
#include "OneWire.h"
#include "DallasTemperature.h"

// You should get Auth Token in the Blynk App.
// Go to the Project Settings (nut icon).
char auth[] = "***";

// Your WiFi credentials.
// Set password to "" for open networks.
char ssid[] = "***";
char pass[] = "****";
                     
#define WATER_TEMP_PIN A1 
#define RELAY_PIN A0

OneWire oneWire(WATER_TEMP_PIN); 
DallasTemperature sensors(&oneWire);

BlynkTimer timer;

bool allume = true ; // true pour cuiseurvapeur allumé, false sinon

void sendSensor()
{
  
  float t = Serial.print(dTempWater); // or dht.readTemperature(true) for Fahrenheit

  if (isnan(t)) {
    Serial.println("Failed to read from DHT sensor!");
    return;
  }
  // You can send any value at any time.
  // Please don't send more that 10 values per second.
  Blynk.virtualWrite(V6, t);
}
void setup() 
{
  pinMode (RELAY_PIN, OUTPUT);
  // On initialise la connexion série
  Serial.begin(9600);
  delay(2000);
 Blynk.begin(auth, ssid, pass);
timer.setInterval(1000L, sendSensor);
}

void loop() 
{
  // On récupère la température de la sonde
  sensors.requestTemperatures();
  double dTempWater = sensors.getTempCByIndex(0);

  // On imprime la température
  Serial.print("Température de l'eau: ");
  Serial.print(dTempWater);
  Serial.println("°C");

  // On attends 5 secondes
  delay(5000);

   if (isnan(dTempWater)) {
   Serial.println("Failed to read from DHT sensor!");
 } else {
   if (dTempWater >= 82)  allume = false;}
{   if (dTempWater <= 72)  allume = true;
   }
digitalWrite(RELAY_PIN, allume);

 Blynk.run();
  timer.run();
}>```

@Ronan_Le_Jort please edit your post, using the pencil icon at the bottom, and add triple backticks at the beginning and end of your code so that it displays correctly.
Triple backticks look like this:
```

Pete.

thank you, I made the changes

@Ronan_Le_Jort you’ve made some changes, but you haven’t used the correct characters, even though I provided you with triple backticks that you could copy and paste.

Please try again, and then I’ll explain the cause of your compilation error message.

Pete.

ok, normally it’s good

Okay, the NodeMCU has only one analog pin, referenced as “A0” in code.
You are trying to retrieve data from pin “A1”, which doesn’t physically exist on your NodeMCU.

If you require to analog ports you need to use a different type of board, such as an ESP32, or an analog multiplexer on your NodeMCU.

Pete.

3 Likes

Hello and thank you, the problem came from the connection.

Now, i have taken another example to make the probe information available on blynk but I did not succeed.

I’m trying to send the temperature information (dTempWater) to the blynk application.

Thanks for your help