Thermistor NTC10k with ESP8266 and Blynk

Hello, I need help.

I need to connect the NTC10k sensor to a high seal refrigerator, which is why the ds18b20 would not work, as they have thicker cables and neither does the DHT11.

As the NTC10k has only two wires, I can place it in the fridge without disturbing its seal.

I need help because NTC is not connecting to blynk and I don’t know how to solve it, I’m using the following code:

#include <BlynkSimpleEsp8266.h>

#include <Wire.h>

#include <ESP8266WiFi.h>

#include <WiFiClient.h>

#include <ESP8266WebServer.h>

#include <ESP8266mDNS.h>

#include <WiFiManager.h>

#define BLYNK_TEMPLATE_ID "TMPLhS6Pw9a8"

#define BLYNK_TEMPLATE_NAME "NTC10k"

#define BLYNK_AUTH_TOKEN "EXZgQkXDwUtS7wagilF34jXBnslTwavk"

#define BLYNK_PRINT Serial

#define THERMISTORPIN A0        

#define THERMISTORNOMINAL 10000      

#define TEMPERATURENOMINAL 25  

#define NUMSAMPLES 5

#define BCOEFFICIENT 3950

#define SERIESRESISTOR 10000    

const char* ssid = "nit";

const char* pass = "nit@univas";

char auth[] = "EXZgQkXDwUtS7wagilF34jXBnslTwavk";

BlynkTimer timer;

int samples[NUMSAMPLES];

void myTimerEvent()

{

  Blynk.virtualWrite(V1, millis() / 1000);

}

void sensorDataSend()

{

  int ThermistorPin = 32;

  int Vo;

  float A = 10000;

  float logC, C, T ;

  float c1 = 1.009249522e-03, c2 = 2.378405444e-04, c3 = 2.019202697e-07;

  float c4 = 1.009249522e-03, c5 = 2.378405444e-04, c6 = 2.019202697e-07;

  Vo = analogRead(ThermistorPin);

  C = A * (1023.0 / (float)Vo - 1.0);

  logC = log(C);

  T = (1.0 / (c1 + c2*logC + c3*logC*logC*logC));

  T = T - 273.15;

  Blynk.virtualWrite(V1, T);

}

void setup(void) {

    Blynk.begin(auth, ssid, pass);

  Serial.begin(9600);

  analogReference(EXTERNAL);

   timer.setInterval(5000L, sensorDataSend);

}

void loop(void) {

  uint8_t i;

  float average;

  // take N samples in a row, with a slight delay

  for (i=0; i< NUMSAMPLES; i++) {

   samples[i] = analogRead(THERMISTORPIN);

   delay(10);

    Blynk.run();

    timer.run();

  }

 

  // average all the samples out

  average = 0;

  for (i=0; i< NUMSAMPLES; i++) {

     average += samples[i];

  }

  average /= NUMSAMPLES;

  Serial.print("Average analog reading ");

  Serial.println(average);

 

  // convert the value to resistance

  average = 1023 / average - 1;

  average = SERIESRESISTOR / average;

  Serial.print("Thermistor resistance ");

  Serial.println(average);

 

  float steinhart;

  steinhart = average / THERMISTORNOMINAL;     // (R/Ro)

  steinhart = log(steinhart);                  // ln(R/Ro)

  steinhart /= BCOEFFICIENT;                   // 1/B * ln(R/Ro)

  steinhart += 1.0 / (TEMPERATURENOMINAL + 273.15); // + (1/To)

  steinhart = 1.0 / steinhart;                 // Invert

  steinhart -= 273.15;                         // convert absolute temp to C

 

  Serial.print("Temperature ");

  Serial.print(steinhart);

  Serial.println(" *C");

 

  delay(1000);

}

@Matheus_73 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:
```

Copy and paste these if you can’t find the correct symbol on your keyboard.

Pete.

1 Like

You’ve defined THERMISTORPIN (all capitals) as pin A0, which is correct for tge ESP8266, as it only has one analog pin…

And you’ve used that when taking readings in your void loop (more on that later)…

quote=“Matheus_73, post:1, topic:66942”]
samples[i] = analogRead(THERMISTORPIN);
[/quote]

In your sensorDataSend() function you declare ThermistorPin (mixed case) as pin 32, and attempt to take analog readings from that pin…

The ESP8266 doesn’t have a GPIO32 (but the ESP32 does, and it can be used as an analog pin, but you aren’t using an ESP32)

This means that you aren’t getting any readings from your sensor in the sensorDataSend() function, because you are attempting to read a non-existent pin, which obviously doesn’t have a sensor attached to it.

I’d suggest that you remove all of the stuff relating to taking sensor readings, and move it to your sensorDataSend() function (and probably give it a better name too).

You need to remove all of your delays, and allow the BlynkTimer to handle the timing.

You should also move this…

to the very beginning of your void setup, and stop doing this…

and this…

and instead do this…

Blynk.begin(BLYNK_AUTH_TOKEN, ssid, pass);

Pete.

1 Like

After all the code cleaning suggested by @PeteKnight, you can change the timesetinterval for the routine sensorDataSend to 1000L instead of 5000L.
For every run of that function you can serial print the temperature reading, and you can add a counter as a condition to send the data to BLYNK each time the counter reach 5, in that way, using just one function you will accomplish both tasks:
Serial print temperature every 1 second and send temperature to blynk every 5 seconds.
By the way, think if it’s worth to send every 5 seconds the temperature reading to Blynk. Your system changes the temperature so fast that a 5 seconds sampling is needed?

1 Like