In this final project I attempted to make an interactive weather station that would be able to get the day’s weather and then give you a suggestion on what to wear based on the weather data that it gets. When I came up with the idea I thought it might be something for younger kids to teach them about the weather and let them know what to wear instead of their parents just telling them what clothes to wear. My original idea was to have an LCD that would put up all minds of weather data like temperature, humidity, wind, etc but I eventually had to scale it down to something more manageable and I figured younger kids would want to just look at a bunch of numbers.
Progress Photos:
I attempted to do this by using the Arduino Uno along with the Sparkfun ESP8266 “Thing” to grab the weather data from the internet, a 16×2 LCD to display the data, and some magnetic switches to choose whether to show the what to wear or the weather. Additionally I added a potentiometer to choose what time of day to show the weather for; morning, afternoon, evening, and nighttime. Ultimately I only got small bit of it to function properly due to some problems I ran into. Firstly I had some trouble getting the WiFi card to send data to the Arduino that could be translated to the LCD as all of the data was being communicated through the Serial monitor which had only one way to send data. Additionally I had to get a new ESP8266 because I accidentally broke the first one while soldering the pins to put it on a protoboard. I also ran into trouble when my magnetic switches stopped recognizing the magnets until they didn’t pick up anything at all therefore the interaction part was not functioning correctly. Finding the hourly weather data was also a problem since almost all the sites that provide weather data require a monthly fee to retrieve that kind of data. For the enclosure I modeled a box in the shape of a cloud using Rhinoceros and then used the laser cutter to cut the layers of the box out of a sheet of plywood. After gluing the pieces of the box together I put the circuit inside. I would like to eventually get this working correctly and maybe even take it further to make an even more sophisticated weather station with real time data.
Circuit:
Final Photos:
Video:
Arduino Code:
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 <LiquidCrystal.h> | |
// initialize the library with the numbers of the interface pins | |
LiquidCrystal lcd(12, 11, 5, 4, 3, 2); | |
int blueLED = 6; | |
int redLED = 7; | |
int greenLED = 8; | |
int yellowLED = 9; | |
int potPin = A5; | |
int sensorValue; | |
int magnet1 = 10; | |
int magnet2 = 13; | |
int weatherProfile; | |
void setup() | |
{ | |
lcd.begin (16,2); | |
Serial.begin(9600); | |
lcd.setCursor(2,0); | |
lcd.print("Please Choose"); | |
lcd.setCursor(0,1); | |
lcd.print("<— or —>"); | |
pinMode(blueLED, OUTPUT); | |
pinMode(redLED, OUTPUT); | |
pinMode(greenLED, OUTPUT); | |
pinMode(yellowLED, OUTPUT); | |
pinMode(potPin, INPUT); | |
} | |
void loop() | |
{ | |
sensorValue = analogRead(potPin); | |
Serial.println(sensorValue); | |
if(sensorValue < 50) { | |
digitalWrite(redLED, LOW); | |
digitalWrite(yellowLED, LOW); | |
digitalWrite(greenLED, LOW); | |
digitalWrite(blueLED, LOW); | |
lcd.setCursor(0,0); | |
lcd.print(" Please Choose"); | |
} | |
else if(sensorValue >= 50 && sensorValue <= 255) { | |
digitalWrite(redLED, HIGH); | |
digitalWrite(yellowLED, LOW); | |
digitalWrite(greenLED, LOW); | |
digitalWrite(blueLED, LOW); | |
lcd.setCursor(0,0); | |
lcd.print("Good Morning! "); | |
if(digitalRead(magnet1) == HIGH) { | |
//getWeather("morning"); | |
} | |
else if(digitalRead(magnet2) == HIGH) { | |
//whatToWear(weatherProfile); | |
} | |
} | |
else if(sensorValue >= 256 && sensorValue <= 511) { | |
digitalWrite(yellowLED, HIGH); | |
digitalWrite(blueLED, LOW); | |
digitalWrite(greenLED, LOW); | |
digitalWrite(redLED, LOW); | |
lcd.setCursor(0,0); | |
lcd.print("Good Afternoon! "); | |
if(digitalRead(magnet1) == HIGH) { | |
//getWeather("afternoon"); | |
} | |
else if(digitalRead(magnet2) == HIGH) { | |
//whatToWear(weatherProfile); | |
} | |
} | |
else if(sensorValue >= 512 && sensorValue <= 767) { | |
digitalWrite(greenLED, HIGH); | |
digitalWrite(redLED, LOW); | |
digitalWrite(blueLED, LOW); | |
digitalWrite(yellowLED, LOW); | |
lcd.setCursor(0,0); | |
lcd.print("Good Evening! "); | |
if(digitalRead(magnet1) == HIGH) { | |
//getWeather("evening"); | |
} | |
else if(digitalRead(magnet2) == HIGH) { | |
//whatToWear(weatherProfile); | |
} | |
} | |
else if(sensorValue >= 768) { | |
digitalWrite(blueLED, HIGH); | |
digitalWrite(yellowLED, LOW); | |
digitalWrite(greenLED, LOW); | |
digitalWrite(redLED, LOW); | |
lcd.setCursor(0,0); | |
lcd.print("Go to sleep! "); | |
if(digitalRead(magnet1) == HIGH) { | |
//getWeather("nighttime"); | |
} | |
else if(digitalRead(magnet2) == HIGH) { | |
//whatToWear(weatherProfile); | |
} | |
} | |
} | |
void getWeather(string timeOfDay) { | |
int temp; | |
if(timeOfDay == "morning") { | |
temp = Serial.read(); //read in temperature from the Serial monitor | |
if(temp > 80) { | |
lcd.setCursor(0,0); | |
lcd.print("It will be hot. ") | |
} | |
else if(temp <= 80 && temp > 45) { | |
lcd.setCursor(0,0); | |
lcd.print("It will be mild. ") | |
} | |
else if(temp <= 45 && temp > 40) { | |
lcd.setCursor(0,0); | |
lcd.print("It will be cold. ") | |
} | |
else { | |
lcd.setCursor(0,0); | |
lcd.print("It will be frigid. ") | |
} | |
} | |
else if(timeOfDay == "afternoon") { | |
temp = Serial.read(); | |
if(temp > 80) { | |
lcd.setCursor(0,0); | |
lcd.print("It will be hot. ") | |
} | |
else if(temp <= 80 && temp > 45) { | |
lcd.setCursor(0,0); | |
lcd.print("It will be mild. ") | |
} | |
else if(temp <= 45 && temp > 40) { | |
lcd.setCursor(0,0); | |
lcd.print("It will be cold. ") | |
} | |
else { | |
lcd.setCursor(0,0); | |
lcd.print("It will be frigid. ") | |
} | |
} | |
else if(timeOfDay == "evening") { | |
temp = Serial.read(); | |
if(temp > 80) { | |
lcd.setCursor(0,0); | |
lcd.print("It will be hot. ") | |
} | |
else if(temp <= 80 && temp > 45) { | |
lcd.setCursor(0,0); | |
lcd.print("It will be mild. ") | |
} | |
else if(temp <= 45 && temp > 40) { | |
lcd.setCursor(0,0); | |
lcd.print("It will be cold. ") | |
} | |
else { | |
lcd.setCursor(0,0); | |
lcd.print("It will be frigid. ") | |
} | |
} | |
else if(timeOfDay == "nighttime") { | |
temp = Serial.read(); | |
if(temp > 80) { | |
lcd.setCursor(0,0); | |
lcd.print("It will be hot. ") | |
} | |
else if(temp <= 80 && temp > 45) { | |
lcd.setCursor(0,0); | |
lcd.print("It will be mild. ") | |
} | |
else if(temp <= 45 && temp > 40) { | |
lcd.setCursor(0,0); | |
lcd.print("It will be cold. ") | |
} | |
else { | |
lcd.setCursor(0,0); | |
lcd.print("It will be frigid. ") | |
} | |
} | |
} | |
void whatToWear(int weatherProfile) { | |
if(weatherProfile == 1) { | |
lcd.setCursor(0,1); | |
lcd.print("T-shirt+Shorts "); | |
} | |
else if(weatherProfile == 2) { | |
lcd.setCursor(0,1); | |
lcd.print("T-shirt+Pants "); | |
} | |
else if(weatherProfile == 3) { | |
lcd.setCursor(0,1); | |
lcd.print("Jacket+Pants "); | |
} | |
else { | |
lcd.setCursor(0,1); | |
lcd.print("Wintercoat+Pants "); | |
} | |
} |
ESP8266 Code:
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> | |
#ifndef min | |
#define min(x,y) (((x)<(y))?(x):(y)) | |
#endif | |
#ifndef max | |
#define max(x,y) (((x)>(y))?(x):(y)) | |
#endif | |
#include <ArduinoJson.h> | |
const char SSID[] = "******"; //Wifi name | |
const char PASSWORD[] = "*********"; //Wifi password | |
// Use your own API key by signing up for a free developer account. | |
// http://www.wunderground.com/weather/api/ | |
#define WU_API_KEY "faa6a04ec4a845f2b7ce096c9a80ace5" | |
// Specify your favorite location one of these ways. | |
//#define WU_LOCATION "CO/BOULDER" | |
// US ZIP code | |
//#define WU_LOCATION "" | |
#define WU_LOCATION "80303" | |
// Country and city | |
//#define WU_LOCATION "United States/Boulder" | |
// 5 minutes between update checks. The free developer account has a limit | |
// on the number of calls so don't go wild. | |
#define DELAY_NORMAL (5*60*1000) | |
// 20 minute delay between updates after an error | |
#define DELAY_ERROR (20*60*1000) | |
#define WUNDERGROUND "api.wunderground.com" | |
// HTTP request | |
const char WUNDERGROUND_REQ[] = | |
"GET /api/" WU_API_KEY "/conditions/q/" WU_LOCATION ".json HTTP/1.1\r\n" | |
"User-Agent: ESP8266/0.1\r\n" | |
"Accept: */*\r\n" | |
"Host: " WUNDERGROUND "\r\n" | |
"Connection: close\r\n" | |
"\r\n"; | |
void setup() | |
{ | |
Serial.begin(115200); | |
// We start by connecting to a WiFi network | |
Serial.println(); | |
Serial.println(); | |
Serial.print(F("Connecting to ")); | |
Serial.println(SSID); | |
WiFi.begin(SSID, PASSWORD); | |
while (WiFi.status() != WL_CONNECTED) { | |
delay(500); | |
Serial.print(F(".")); | |
} | |
Serial.println(); | |
Serial.println(F("WiFi connected")); | |
Serial.println(F("IP address: ")); | |
Serial.println(WiFi.localIP()); | |
} | |
static char respBuf[4096]; | |
void loop() | |
{ | |
// TODO check for disconnect from AP | |
// Open socket to WU server port 80 | |
Serial.print(F("Connecting to ")); | |
Serial.println(WUNDERGROUND); | |
// Use WiFiClient class to create TCP connections | |
WiFiClient httpclient; | |
const int httpPort = 80; | |
if (!httpclient.connect(WUNDERGROUND, httpPort)) { | |
Serial.println(F("connection failed")); | |
delay(DELAY_ERROR); | |
return; | |
} | |
// This will send the http request to the server | |
Serial.print(WUNDERGROUND_REQ); | |
httpclient.print(WUNDERGROUND_REQ); | |
httpclient.flush(); | |
// Collect http response headers and content from Weather Underground | |
// HTTP headers are discarded. | |
// The content is formatted in JSON and is left in respBuf. | |
int respLen = 0; | |
bool skip_headers = true; | |
while (httpclient.connected() || httpclient.available()) { | |
if (skip_headers) { | |
String aLine = httpclient.readStringUntil('\n'); | |
//Serial.println(aLine); | |
// Blank line denotes end of headers | |
if (aLine.length() <= 1) { | |
skip_headers = false; | |
} | |
} | |
else { | |
int bytesIn; | |
bytesIn = httpclient.read((uint8_t *)&respBuf[respLen], sizeof(respBuf) – respLen); | |
Serial.print(F("bytesIn ")); Serial.println(bytesIn); | |
if (bytesIn > 0) { | |
respLen += bytesIn; | |
if (respLen > sizeof(respBuf)) respLen = sizeof(respBuf); | |
} | |
else if (bytesIn < 0) { | |
Serial.print(F("read error ")); | |
Serial.println(bytesIn); | |
} | |
} | |
delay(1); | |
} | |
httpclient.stop(); | |
if (respLen >= sizeof(respBuf)) { | |
Serial.print(F("respBuf overflow ")); | |
Serial.println(respLen); | |
delay(DELAY_ERROR); | |
return; | |
} | |
// Terminate the C string | |
respBuf[respLen++] = '\0'; | |
Serial.print(F("respLen ")); | |
Serial.println(respLen); | |
//Serial.println(respBuf); | |
if (showWeather(respBuf)) { | |
delay(DELAY_NORMAL); | |
} | |
else { | |
delay(DELAY_ERROR); | |
} | |
} | |
bool showWeather(char *json) | |
{ | |
StaticJsonBuffer<3*1024> jsonBuffer; | |
// Skip characters until first '{' found | |
// Ignore chunked length, if present | |
char *jsonstart = strchr(json, '{'); | |
//Serial.print(F("jsonstart ")); Serial.println(jsonstart); | |
if (jsonstart == NULL) { | |
Serial.println(F("JSON data missing")); | |
return false; | |
} | |
json = jsonstart; | |
// Parse JSON | |
JsonObject& root = jsonBuffer.parseObject(json); | |
if (!root.success()) { | |
Serial.println(F("jsonBuffer.parseObject() failed")); | |
return false; | |
} | |
// Extract weather info from parsed JSON | |
JsonObject& current = root["current_observation"]; | |
const float temp_f = current["temp_f"]; | |
Serial.print(temp_f, 1); Serial.print(F(" F, ")); | |
const float temp_c = current["temp_c"]; | |
const char *humi = current[F("relative_humidity")]; | |
const char *weather = current["weather"]; | |
const char *pressure_mb = current["pressure_mb"]; | |
const char *observation_time = current["observation_time_rfc822"]; | |
// Extract local timezone fields | |
const char *local_tz_short = current["local_tz_short"]; | |
const char *local_tz_long = current["local_tz_long"]; | |
const char *local_tz_offset = current["local_tz_offset"]; | |
return true; | |
} |
ESP8266 Code reference:Â https://gist.github.com/bbx10/149bba466b1e2cd887bf