Skip to content

Instantly share code, notes, and snippets.

@vjandrei
Created February 25, 2020 13:34
Show Gist options
  • Save vjandrei/8da4279225dbf6308a2fafc0accf073b to your computer and use it in GitHub Desktop.
Save vjandrei/8da4279225dbf6308a2fafc0accf073b to your computer and use it in GitHub Desktop.
/**
* ReadSHT1xValues
*
* Read temperature and humidity values from an SHT1x-series (SHT10,
* SHT11, SHT15) sensor.
*
* Copyright 2009 Jonathan Oxer <jon@oxer.com.au>
* www.practicalarduino.com
*/
#include <SHT1x.h>
#include <ESP8266WiFi.h>
#include <FirebaseArduino.h>
// Specify data and clock connections and instantiate SHT1x object
#define dataPin 4 //D1
#define clockPin 5 //D2
SHT1x sht1x(dataPin, clockPin);
void setup()
{
Serial.begin(38400); // Open serial connection to report values to host
Serial.println("Starting up");
wifiConnect();
Firebase.begin(FIREBASE_HOST, FIREBASE_AUTH);
delay(10);
}
void loop()
{
float temp_c;
float temp_f;
float humidity;
// 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("%");
Firebase.setInt("temp", temp_c);
Firebase.pushFloat("temp", temp_c);
Firebase.setFloat("temp", 42.0);
// handle error
if (Firebase.failed()) {
Serial.print("setting /number failed:");
Serial.println(Firebase.error());
return;
}
if(WiFi.status() != WL_CONNECTED)
{
wifiConnect();
}
delay(2000);
}
void wifiConnect()
{
WiFi.begin(WIFI_SSID, WIFI_PASSWORD); // Connect to the network
Serial.print("Connecting to ");
Serial.print(WIFI_SSID); Serial.println(" ...");
int teller = 0;
while (WiFi.status() != WL_CONNECTED)
{ // Wait for the Wi-Fi to connect
delay(1000);
Serial.print(++teller); Serial.print(' ');
}
Serial.println('\n');
Serial.println("Connection established!");
Serial.print("IP address:\t");
Serial.println(WiFi.localIP()); // Send the IP address of the ESP8266 to the computer
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment