Temperature and humidity logger

Our mobile home is during the winter in his/her wintersleep.
To controll temp and hum inside the car I placed a NodeMCU and a SHT1x sensor. With the help of the great Blynk libraries and the witgets I now can monitor temp and hum at any time and place!

This is my first attemp, later I will clean the code and put some better commands in it!

For now enjoy!

/**************************************************************
 * Blynk is a platform with iOS and Android apps to control
 * Arduino, Raspberry Pi and the likes over the Internet.
 * You can easily build graphic interfaces for all your
 * projects by simply dragging and dropping widgets.
 *
 *   Downloads, docs, tutorials: http://www.blynk.cc
 *   Blynk community:            http://community.blynk.cc
 *   Social networks:            http://www.fb.com/blynkapp
 *                               http://twitter.com/blynk_app
 *



* Blynk library is licensed under MIT license
 * This example code is in public domain.
 *
 **************************************************************
 * This example runs directly on ESP8266 chip.
 *
 * You need to install this for ESP8266 development:
 *   https://github.com/esp8266/Arduino
 * 
 * Please be sure to select hte right ESP8266 module
 * in the Tools -> Board menu!
 *

 * Change WiFi ssid, pass, and Blynk auth token to run :)
 *
 **************************************************************/
#define BLYNK_PRINT Serial    // Comment this out to disable prints and save space
#include <ESP8266WiFi.h>
#include <BlynkSimpleEsp8266.h>
#include <SimpleTimer.h>
#include <SHT1x.h>

// Specify data and clock connections and instantiate SHT1x object
#define dataPin  D1
#define clockPin D2

float temp_c;
float temp_f;
float humidity;
  
SHT1x sht1x(dataPin, clockPin);



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

void schrijven()
{
  // This function sends Arduino up time every 1 minute
  // In the app, Widget's reading frequency should be set to PUSH
  // You can send anything with any interval using this construction
  // Don't send more that 10 values per second

  Blynk.virtualWrite(V5, temp_c);
  Blynk.virtualWrite(V6,humidity);

  if (temp_c >15) 
  {
    Blynk.virtualWrite(V2,255);
    Blynk.virtualWrite(V3,0);
  }
  else
  {
    Blynk.virtualWrite(V2,0);
    Blynk.virtualWrite(V3,255);
  }
  if (humidity >75) 
  {
    Blynk.virtualWrite(V0,255);
    Blynk.virtualWrite(V1,0);
  }
  else
  {
    Blynk.virtualWrite(V0,0);
    Blynk.virtualWrite(V1,255);
  }
}

void setup()
{
  Serial.begin(9600);
  Blynk.begin(auth, "xxxx", "xxxxxxxx");
  Serial.println("Starting up");
  tijd.setInterval(60000, schrijven); //  Here you set interval (1 min) and which function to call 
} 

void loop()
{
   // Read values from the sensor
  temp_c = sht1x.readTemperatureC();
  temp_f = sht1x.readTemperatureF();
  humidity = sht1x.readHumidity();

  // Print the values to the serial port
  Serial.print("Temperature: ");
  Serial.print(temp_c, DEC);
  Serial.print("C / ");
  Serial.print(temp_f, DEC);
  Serial.print("F. Humidity: ");
  Serial.print(humidity);
  Serial.println("%");

  
  Blynk.run();
  tijd.run();
 }

AndrΓ©

3 Likes