WiFi Temperature/Humidity meter

Based on below two links I have combined internal temperature senzor with humidity and external temp meter.

Combined code below

https://www.instructables.com/id/Arduino-IOT-Temperature-and-Humidity-With-ESP8266-/

http://navody.arduino-shop.cz/navody-k-produktum/teplotni-senzor-ds18b20.html

Public view at thingspeak.com

https://thingspeak.com/channels/303956

/* Arduino IOT - Temperature (oC) and Humidity (%) on the web
*Use the DHT-22 sensor to read temperature and humidity values
*Send these values to http://www.thingSpeak.com with the ESP8266 serial Wifi module
Dev: Michalis Vasilakis // Date:23/2/2016 // Update: 25/2/2015 // Ver. 1.3
More info: http://www.ardumotive.com/iot-wifi-temp-and-humidity.html
Tip: open the serial monitor for debugging */

//Libraires
#include
#include

// Teplotní čidlo DS18B20
// připojení knihoven
#include
#include

// nastavení čísla vstupního pinu
const int pinCidlaDS = 4;
// vytvoření instance oneWireDS z knihovny OneWire
OneWire oneWireDS(pinCidlaDS);
// vytvoření instance senzoryDS z knihovny DallasTemperature
DallasTemperature senzoryDS(&oneWireDS);

/*————————DHT SENSOR————————*/
#define DHTPIN 2 // DHT data pin connected to Arduino pin 2
#define DHTTYPE DHT22 // DHT 22 (or AM2302)
DHT dht(DHTPIN, DHTTYPE); // Initialize the DHT sensor
/*———————————————————-*/

/*—————–ESP8266 Serial WiFi Module—————*/
#define SSID “PRAHA” // “SSID-WiFiname”
#define PASS “jandra76” // “password”
#define IP “184.106.153.149”// thingspeak.com ip
String msg = “GET /update?key=BP0RDZWQ5N7AYIDD”; //change it with your key…
/*———————————————————–*/

//Variables
float temp;
int hum;
String tempC;
int error;
float tempoutside;
String tempoutsideC;
void setup()
{
Serial.begin(115200); //or use default 115200.
// zapnutí komunikace knihovny s teplotním čidlem
senzoryDS.begin();

Serial.println(“AT”);
delay(10000);
if(Serial.find(“OK”)){
connectWiFi();
}
}

void loop(){
// načtení informací ze všech připojených čidel na daném pinu
senzoryDS.requestTemperatures();
// výpis teploty na sériovou linku, při připojení více čidel
// na jeden pin můžeme postupně načíst všechny teploty
// pomocí změny čísla v závorce (0) – pořadí dle unikátní adresy čidel
Serial.print(“Teplota cidla DS18B20: “);
Serial.print(senzoryDS.getTempCByIndex(0));
Serial.println(” stupnu Celsia”);
tempoutside= senzoryDS.getTempCByIndex(0);
// pauza pro přehlednější výpis
delay(500);

//Read temperature and humidity values from DHT sensor:
start: //label
error=0;
temp = dht.readTemperature();
hum = dht.readHumidity();
char buffer[10];
// there is a useful c function called dtostrf() which will convert a float to a char array
//so it can then be printed easily. The format is: dtostrf(floatvar, StringLengthIncDecimalPoint, numVarsAfterDecimal, charbuf);
tempC = dtostrf(temp, 4, 1, buffer);
tempoutsideC = dtostrf(tempoutside, 4, 1, buffer);

updateTemp();
//Resend if transmission is not completed
if (error==1){
goto start; //go to label “start”
}

delay(60000); //Update every 1 hour
}

void updateTemp(){
String cmd = “AT+CIPSTART=\”TCP\”,\””;
cmd += IP;
cmd += “\”,80″;
Serial.println(cmd);
delay(2000);
if(Serial.find(“Error”)){
return;
}
cmd = msg ;
cmd += “&field1=”; //field 1 for temperature
cmd += tempC;
cmd += “&field2=”; //field 2 for humidity
cmd += String(hum);
cmd += “&field3=”; //field 3 for temperature outside
cmd += tempoutsideC;
cmd += “\r\n”;
Serial.print(“AT+CIPSEND=”);
Serial.println(cmd.length());
if(Serial.find(“>”)){
Serial.print(cmd);
}
else{
Serial.println(“AT+CIPCLOSE”);
//Resend…
error=1;
}
}

boolean connectWiFi(){
Serial.println(“AT+CWMODE=1″);
delay(2000);
String cmd=”AT+CWJAP=\””;
cmd+=SSID;
cmd+=”\”,\””;
cmd+=PASS;
cmd+=”\””;
Serial.println(cmd);
delay(5000);
if(Serial.find(“OK”)){
return true;
}else{
return false;
}

}

Advertisements

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s