Introduction: Flask Weather Station
In this instructable we’re going to make a weather station.
The weather station is going to measure temperature, humidity and luminosity with an Arduino. These values will be saved in a Mysql database and displayed on a website running on a Raspberry Pi.
Step 1: The Materials
- Raspberry Pi, adapter and micro SD card
- Wooden planks
- USB cable
- Small breadboard
- DS1307 (RTC)
- AM2302: humidity and temperature sensor
- TSL2561: luminosity sensor
- 16*4 lcd
- I2C adapter for lcd
- 10KOhm resistor
Step 2: Getting Data
Connecting the sensors
We connect the sensors to an Arduino UNO.
The AM2302 is connected to 3.3V (pin1), GND (pin4) and data (pin2). Between VCC and DATA there must be a 10kOhm resistor. Pin 3 is not connected.
The TSL 2561 is connectod to 3.3V (pin1), GND (pin2), SCL (pin3), SDA (pin4). Pin 5 is not connected. If your Arduino doesn't have pins named SCL and SDA, they can be connected to analog pin 5 (SCL) and analog pin 4 (SDA).
Solder the i2c lcd connector to the LCD. The connector is connected to GND, 5V, SDA, SCL.
Reading the sensors
We're going to use libraries for reading the sensors.
Dowload these libraries and extraxt them to document\arduino\libraries.
After restarting the Arduino IDE, the libraries will show up in your examples and can be used.
You can find the code I've used here: https://github.com/Wobbe-Steeland/weather-station/...
The code will send the sensor values and update the LCD if you send a character to the Arduino. You may have to change the addresses of the I2C devices.
Step 3: Setting Up the Pi
To read our RTC we use I2C. I2C can be enabled in raspi-config.
A real time clock must be added if the Pi is not connected to the internet. The clock can be attached directly to the GPIO pins of the Pi.
Now we must configure the Pi to automatically use the RTC, we can do this by following this guide: https://thepihut.com/blogs/raspberry-pi-tutorials/...
Step 4: Database
The data from the sensors will be stored in a Mysql database.
sudo apt-get update && sudo apt-get install mysql mysql-client
Log in to the mysql server.
mysql -uroot -p
Grant acces to root from remote connections. Don't forget to change password for the password you have chosen.
GRANT ALL PRIVILEGES ON *.* TO 'root'@'%' IDENTIFIED BY 'password'; exit
We also have to edit /etc/mysql/my.cnf. Uncomment bind-address and change the address to 0.0.0.0.
Making the database
Now we can log in on the server with MySQL Workbench from a remote computer.
Use: https://github.com/Wobbe-Steeland/weather-station/... to create the database.
Add the values we're measuring to the type table:
insert into weather_station.type values(1,"temperature"); insert into weather_station.type values(2,"humidity"); insert into weather_station.type values(4,"luminosity");
Step 5: Website
The website can be downloaded on: https://github.com/Wobbe-Steeland/weather-station/...
The server uses passlib, simplejson and serial. If these packages are not installed they can be added with pip3.
To start the webserver automatically when the Pi receives power we will add the following lines to /etc/rc.local. Sensor.py asks for data from the Arduino and adds it to the database.
python3 *location of server.py* & python3 *location of sensor.py* &
Step 6: Enclosure
Cut the thin plank in four pieces. Two pieces of 7cm+2*thickness of the plank by 11.7cm. And two pieces of 11.7cm by 22.2cm.
Cut on piece of 7cm * 22.2cm from the thick wood and the plexiglass.
With a dremel we drill a hole trough the thin plank and a little in the thick plank, that way we can easely insert the nail.
After we have attached the first side, we're going to place the electronics. With the dremel we cut a hole in the middle of the side panel, and glue to LCD to it. Next to the LCD we glue the small breadboard.
Now we attach the Raspberry Pi and the Arduino. This can be done with glue, screws or tape.
Place the sensors in the breadboard and connect them and the LCD to the Arduino. Don't forget to test the connections before you glue or tape them in place.
Attach the rest of the side panels and glue the plexiglass on the top
Finally drill a hole in the back for the power adapter of the Raspberry Pi.