top of page

My Wi-Fi Arduino weather station

I didn't know what to do, and I didn't have a thermometer at home. I watered two plants with one hose.


In my previous flat, I had thermostats for each room and could keep the temperature under control. Well, in my new flat I had to become just a little creative. As I bought several sensors for my Arduino microcontroller, I decided to put them to the test and put together some wire and a few lines of code to check the temperature.


Initially, I had the temperature and humidity sensor (DHT11) connected to an ultrasonic sensor and a buzzer, displaying on a LED the current temperature and humidity when you were waving something at it at 20 cm distance. Wasn't sure why I decided to do that, so I later upgraded the sensor to a DHT22 and decided to connect it to a Wi-Fi module to control the temperature at distance with my phone. For simplicity, I exploited the RemoteXY app.


THE PIECES

  • Arduino Uno (note: sometimes the 3.3v output of the Uno will not be enough to power the ESP8266, I was lucky apparently)

  • DHT22 (or DHT11) temperature and humidity sensor (if using a DHT11 there is the code for that too on my repo)

  • ESP8266 Wi-Fi module



THE WIRING




THE CODE


You can find the code below on my GitHub, here👀. Let's see the few lines of code to make everything work. I used the RemoteXY app to manage all the Wi-Fi communication and to easily create a GUI for my phone app.


////////////////////////////////////////////////        
RemoteXY include library          ////////////////////////////////////////////////

//RemoteXY select connection mode and include library 
#defineREMOTEXY_MODE__ESP8266_HARDSERIAL_POINT
#include<RemoteXY.h>

// RemoteXY connection settings 
#defineREMOTEXY_SERIAL Serial
#defineREMOTEXY_SERIAL_SPEED115200
#defineREMOTEXY_WIFI_SSID"Weather_Station"
#defineREMOTEXY_WIFI_PASSWORD"solopernoi"
#defineREMOTEXY_SERVER_PORT6377

// RemoteXY configuration depending on the GUI designed on their website
#pragma pack(push, 1)uint8_t RemoteXY_CONF[] = { 255,0,0,32,0,104,0,10,24,0,66,130,64,6,23,18,20,26,66,132,69,11,13,10,20,24,68,50,3,31,94,30,8,2,166,84,101,109,112,101,114,97,116,117,114,101,0,72,117,109,105,100,105,116,121,0,129,0,9,9,24,4,17,84,101,109,112,101,114,97,116,117,114,101,58,0,129,0,10,17,17,4,21,72,117,109,105,100,105,116,121,58,0,67,5,36,9,16,4,2,24,11,67,5,36,17,16,4,2,24,11 
};

// this structure defines all the variables and events of your control interface 
struct {
// output variables
int8_t arch; // =0..100 level position 
int8_t lancetta; // =0..100 level position
float graph_var1; // first variable in the graph
float graph_var2; // second variable in the graph
char temp[11]; // string UTF8 end zero 
char hum[11]; // string UTF8 end zero 

// other variables
uint8_t connect_flag; // =1 if wire connected, else =0 

} RemoteXY;
#pragma pack(pop)

///////////////////////////////////////////////           
END RemoteXY include          ///////////////////////////////////////////////

// libraries for DHT sensor
#include<DHT.h>
#include<Adafruit_Sensor.h>

// define DHT sensor type and assigned pin
#defineDHTPIN7
#defineDHTTYPE DHT22DHT 
dht = DHT(DHTPIN, DHTTYPE);

voidsetup() 
{
 RemoteXY_Init (); 
 // initialise DHT22 sensor  
 dht.begin();
}

voidloop() { 
 RemoteXY_Handler ();
 
 // start reading temp and humidity
 double t = dht.readTemperature();
 double h = dht.readHumidity();  
 Serial.println(t); // debug purposes
 
 // cast to int
 int t_int = static_cast<int>(t);
 int h_int = static_cast<int>(h);
 
 // print them on the GUI
 dtostrf(t, 0, 2, RemoteXY.temp);
 dtostrf(h, 0, 2, RemoteXY.hum);
 delay(5000);
 
 // populate the elements of the GUI  
 RemoteXY.arch = t_int;  
 RemoteXY.lancetta = h_int; 
 RemoteXY.graph_var1 = t_int;  
 RemoteXY.graph_var2 = h_int;
}

I believe everything is self-explanatory. Just so you know you have to register to the RemoteXY app and make the design of your app on their website. After that, you will be able to create the specific code to hook up your interface with your variables create inside the Arduino IDE. Then, you will need to insert a key to link your application to your device (for example your smartphone). Now you will be able to your Wi-Fi weather station :)


Ah, yes, you will need to register to fully exploit the app features!



Commentaires


bottom of page