Last active
July 20, 2022 17:36
-
-
Save biscuitrainbow/56ec79c2f8d7d0d62cc39b8cb48af67f to your computer and use it in GitHub Desktop.
Water temp NTC & DHT11
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#include "DHT.h" | |
DHT dht; | |
const int dhtPin = D0; | |
struct DhtValue { | |
float humidity; | |
float celcius; | |
float fahrenheit; | |
float kelvin; | |
}; | |
void setup() | |
{ | |
Serial.begin(9600); | |
dht.setup(dhtPin); | |
} | |
void loop() | |
{ | |
delay(dht.getMinimumSamplingPeriod()); | |
DhtValue dhtValue = readDht(); | |
printDht(dhtValue); | |
} | |
DhtValue readDht() { | |
DhtValue dhtValue; | |
dhtValue.humidity = dht.getHumidity(); | |
dhtValue.celcius = dht.getTemperature(); | |
dhtValue.fahrenheit = (dhtValue.celcius * 1.8) + 32; | |
dhtValue.kelvin = dhtValue.celcius + 293.15; | |
return dhtValue; | |
} | |
void printDht(DhtValue dhtValue) { | |
Serial.print("Temperature:"); | |
Serial.print("\t"); | |
Serial.print(dhtValue.celcius); | |
Serial.print("C\t\t"); | |
Serial.print(dhtValue.kelvin); | |
Serial.print("K\t\t"); | |
Serial.print(dhtValue.fahrenheit); | |
Serial.print("F\t\t"); | |
Serial.print(dhtValue.humidity); | |
Serial.println("%"); | |
} | |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#define BLYNK_TEMPLATE_ID "YOUR_TEMPLATE_ID" | |
#define BLYNK_DEVICE_NAME "YOUR_DEVICE_NAME" | |
#define BLYNK_AUTH_TOKEN "YOUR_DEVICE_TOKEN" | |
#define BLYNK_FIRMWARE_VERSION "0.1.0" | |
#define BLYNK_PRINT Serial | |
#define APP_DEBUG | |
#define WIFI_SSID "YOUR_WIFI_SSID" | |
#define WIFI_PASSWORD "YOUR_WIFI_PASSWORD" | |
#include "DHT.h" | |
#include <ESP8266WiFi.h> | |
#include <BlynkSimpleEsp8266.h> | |
DHT dht; | |
const int dhtPin = D0; | |
struct DhtValue { | |
float humidity; | |
float celcius; | |
float fahrenheit; | |
float kelvin; | |
}; | |
void setup() | |
{ | |
Serial.begin(9600); | |
dht.setup(dhtPin); | |
Blynk.begin(BLYNK_AUTH_TOKEN, WIFI_SSID, WIFI_PASSWORD); | |
} | |
void loop() | |
{ | |
delay(dht.getMinimumSamplingPeriod()); | |
DhtValue dhtValue = readDht(); | |
printDht(dhtValue); | |
Blynk.virtualWrite(V0,dhtValue.celcius); | |
Blynk.virtualWrite(V1,dhtValue.fahrenheit); | |
} | |
DhtValue readDht() { | |
DhtValue dhtValue; | |
dhtValue.humidity = dht.getHumidity(); | |
dhtValue.celcius = dht.getTemperature(); | |
dhtValue.fahrenheit = (dhtValue.celcius * 1.8) + 32; | |
dhtValue.kelvin = dhtValue.celcius + 293.15; | |
return dhtValue; | |
} | |
void printDht(DhtValue dhtValue) { | |
Serial.print("Temperature:"); | |
Serial.print("\t"); | |
Serial.print(dhtValue.celcius); | |
Serial.print("C\t\t"); | |
Serial.print(dhtValue.kelvin); | |
Serial.print("K\t\t"); | |
Serial.print(dhtValue.fahrenheit); | |
Serial.print("F\t\t"); | |
Serial.print(dhtValue.humidity); | |
Serial.println("%"); | |
} | |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
const int tempPin = A0; | |
struct Temperature { | |
float kelvin; | |
float celcius; | |
float fahrenheit; | |
} ; | |
void setup() { | |
Serial.begin(9600); | |
pinMode(tempPin,INPUT); | |
} | |
void loop() { | |
Temperature temp = readTemp(); | |
printTemp(temp); | |
delay(1000); | |
} | |
Temperature readTemp() { | |
const int rt0 = 10000; // Ω | |
const int B = 3977; // K | |
const int vcc = 5; //Supply voltage | |
const int r = 10000; //R=10KΩ | |
float rt, vr, ln, tempValue, t0, sensorValue; | |
float a = A0; | |
t0 = 25 + 273.15; | |
sensorValue = analogRead(tempPin); | |
sensorValue = (5.00 / 1023.00) * sensorValue; | |
vr = vcc - sensorValue; | |
rt = sensorValue / (vr / r); | |
ln = log(rt / rt0); | |
tempValue = (1 / ((ln / B) + (1 / t0))); | |
Temperature temp; | |
temp.kelvin = tempValue; | |
temp.celcius = tempValue - 273.15; | |
temp.fahrenheit = (temp.celcius * 1.8) + 32; | |
return temp; | |
} | |
void printTemp(Temperature temp) { | |
Serial.print("Temperature:"); | |
Serial.print("\t"); | |
Serial.print(temp.celcius); | |
Serial.print("C\t\t"); | |
Serial.print(temp.kelvin); | |
Serial.print("K\t\t"); | |
Serial.print(temp.fahrenheit); | |
Serial.println("F"); | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#include <ESP8266WiFi.h> | |
#define AP_SSID "AP_SSID" | |
#define AP_PASSWORD "AP_PASSWORD" | |
void setup() { | |
Serial.begin(9600); | |
Serial.println(); | |
Serial.print("Setting AP ... "); | |
boolean result = WiFi.softAP(AP_SSID, AP_PASSWORD); | |
if (result == true) { | |
Serial.println("Ready"); | |
} else { | |
Serial.println("Failed!"); | |
} | |
} | |
void loop(){ | |
Serial.printf("Stations connected = %d\n", WiFi.softAPgetStationNum()); | |
delay(3000); | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#include <ESP8266WiFi.h> | |
#include <ESP8266HTTPClient.h> | |
#define WIFI_SSID "YOUR_WIFI_SSID" | |
#define WIFI_PASSWORD "YOUR_WIFI_PASSWORD" | |
void setup() { | |
Serial.begin(9600); | |
connectWifi(); | |
} | |
void loop() { | |
} | |
void connectWifi() { | |
Serial.println("Communication Started \n\n"); | |
delay(1000); | |
WiFi.mode(WIFI_STA); | |
WiFi.begin(WIFI_SSID, WIFI_PASSWORD); //try to connect with wifi | |
Serial.print("Connecting to "); | |
Serial.print(WIFI_SSID); | |
while (WiFi.status() != WL_CONNECTED) { | |
Serial.print("."); | |
delay(500); | |
} | |
Serial.println(); | |
Serial.print("Connected to "); | |
Serial.println(WIFI_SSID); | |
Serial.print("IP Address is : "); | |
Serial.println(WiFi.localIP()); //print local IP address | |
delay(30); | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#include <ESP8266WiFi.h> | |
#define WIFI_SSID "YOUR_WIFI_SSID" | |
#define WIFI_PASSWORD "YOUR_WIFI_PASSWORD" | |
void setup() { | |
Serial.println("Communication Started \n\n"); | |
delay(1000); | |
WiFi.mode(WIFI_STA); | |
WiFi.begin(WIFI_SSID, WIFI_PASSWORD); //try to connect with wifi | |
Serial.print("Connecting to "); | |
Serial.print(WIFI_SSID); | |
while (WiFi.status() != WL_CONNECTED) { | |
Serial.print("."); | |
delay(500); | |
} | |
Serial.println(); | |
Serial.print("Connected to "); | |
Serial.println(WIFI_SSID); | |
Serial.print("IP Address is : "); | |
Serial.println(WiFi.localIP()); //print local IP address | |
delay(30); | |
} | |
void loop(){ | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment