Projects

Check out my code at my GitHub

______________________________________________

Arduino Weather Station

Watch out, The Weather Channel; there's a new meteorologist in town. This is an Arduino based weather station that measures the temperature and relative humidity of its environment and then sends this data to my website to be displayed live. The weather station communicates with my website through an ESP8266 wireless module that connects to my apartment WiFi network. See my weather report here.

weather station weather station

For such a skilled electrical engineer as myself, building the actual weather station was simple; the Arduino supplies power to a SparkFun Si7021 breakout board which then sends the temperature and humidity data via I2C back to the Arduino. The challenging part was getting this data to my website so that I could display it.

Arduino code Arduino Code

Shown above are excerpts from the Arduino code that controls the weather station. The Arduino connects to my apartment WiFi network, reads the weather data, and sends an HTTP GET request containing the temperature and humidity data to my website. Because I only have two data points to send, an HTTP GET request works fine; however, if I were to need to send more data, such as an entire data structure, it would be better to use an HTTP POST request. Unfortunately, even though I wanted to try to make HTTP POST requests, I could not get the ESP8266 to reliably send HTTP POST requests; HTTP GET requests will work for now. (Side note - because my web server uses HTTPS and not HTTP, I needed to jump through some extra hoops to send a GET request. This includes using the SHA1 fingerprint for the HTTPS certificate on my server.)

SITE

Next, after the Arduino sent the data via an HTTP GET request, I needed to save that data somewhere. So, I set up a MYSQL database and wrote a PHP script to transfer the Arduino data into a table within the database. Shown above is an excerpt from the PHP script that writes to the MYSQL database.

SITE

Then, I needed to retrieve that data in my MYSQL database and display it on my website. Shown above is part of the second PHP script that I used; unlike the other PHP script, this script reads data from the database and 'echoes' it into an HTML table.

HTML

And then the project was done! This was my first time ever learning about HTTP, HTTPS, PHP, MYSQL, and ESP8266, so I spent 4-5 hours learning about client-server communication, how to use a database, etc. In addition, I never would have gotten this project to work if it wasn't for the amazing PHP and Arduino examples that I found online to guide me; thank you to Rishi Tiwari at tricksumo.com and to circuits4you.com.

Check out the Arduino code for this project here.

NOTE: Shown below is the weather station with an LCD display that I added after the project was finished.

finished station