Advertisement
rabirajkhadka

Thermistor, Node MCU and Blynk App

Apr 25th, 2020
1,383
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. #define BLYNK_PRINT Serial    // Comment this out to disable prints and save space
  2. #include <SPI.h>
  3. #include <ESP8266WiFi.h>
  4. #include <BlynkSimpleEsp8266.h>
  5. #include <SimpleTimer.h>
  6.  
  7. // You should get Auth Token in the Blynk App.
  8. // Go to the Project Settings (nut icon).
  9. char auth[] = "YOUR AUTH CODE";
  10.  
  11. // Your WiFi credentials.
  12. // Set password to "" for open networks.
  13. char ssid[] = "YOUR_SSID";  //Enter your WIFI Name
  14. char pass[] = "YOUR_PASSWORD";  //Enter your WIFI Password
  15.  
  16. int ThermistorPin = 0; //USE Analog Pin A0 for the input of thermistor value [0 or A0 both works]
  17. int Vo;
  18. float R1 = 10000;
  19. float logR2, R2, T, Tc, Tf;
  20. float c1 = 1.009249522e-03, c2 = 2.378405444e-04, c3 = 2.019202697e-07;
  21.  
  22. SimpleTimer timer;
  23. void sendSensor()
  24. {
  25.  
  26.   Vo = analogRead(ThermistorPin); // Analog Value read from thermistor pin A0
  27.  
  28.   R2 = R1 * (1023.0 / (float)Vo - 1.0); //Mapping of the Data
  29.   logR2 = log(R2); // Log of Mapped Data
  30.   T = (1.0 / (c1 + c2*logR2 + c3*logR2*logR2*logR2)); // Convert data to temperature relevant data
  31.   Tc = T - 273.15; //Temperature in Celcius
  32.   Tf = (Tc * 9.0)/ 5.0 + 32.0; //Temperature in Fareinheit
  33.  
  34.   Serial.print("Temperature: ");
  35.   Serial.print(Tc);
  36.   Serial.println(" C");  
  37.   Blynk.virtualWrite(V4, Tc); //Virtual Pin for the data display in the APP
  38. }
  39.  
  40. void setup()
  41. {
  42.   Serial.begin(115200); // See the connection status in Serial Monitor
  43.   Blynk.begin(auth, ssid, pass);
  44.   // Setup a function to be called every second
  45.   timer.setInterval(1000L, sendSensor);
  46. }
  47.  
  48. void loop()
  49. {
  50.   Blynk.run(); // Initiates Blynk
  51.   timer.run(); // Initiates SimpleTimer
  52. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement