Gathering, saving and serving environment data using arduino

Gathering, saving and serving environment data using arduino

The result can be found on http://weather.gravila.me

I created a solution that enables me to interface an Arduino to my server, the Raspberry Pi 3. I wished to be able to persist the data in a database and fetch it using RESTful services afterwards.

The current sensors in use are a DHT11 for humidity, a BMP180 for pressure and temperature, and a photodiode to indicate light intensity, enabling a better visualisation of the diurnal cycle. If I were to reorder the sensors I would replace the DHT and BMP with a BME280 which contains all three sensors. Additionally, avoid the DHT11 as it only has a 1°C resolution. I’m also currently thinking about a solution for the light diode which, while effective in its purpose, only really indicates ‘night’ and ‘day’, not so much variations in light intensity. I’m also planning to add an MQ-135 gas detector soon.

For the Arduino I used an Arduino nano. Bigger would have been counterproductive and smaller would have risked incompatibility later down the line if the sensors end up piling up. I’m expecting this to be my testing rig so I want it to be flexible, but am definitely entertaining the idea of implementing multiple of them in different parts of the apartment. A mini, without the FTDI built in would have been unnecessarily complicated to connect. For those the main challenge will be energy efficiency as I’d prefer to run them off batteries, and the amount of sensors would probably be reduced: temperature and humidity most likely.

Finally I’d like to address the question of why I decided to use the Arduino if I could have easily just interfaced the sensors to the raspberry. The reason is modularity. In case I decide to upgrade to an x86 server this will still work.

Arduino filePython fileSQL

Database info obviously redacted, replace with your own. I am using MySQL as I am already familiar with PostgreSQL and wanted to learn something new.

I’m manually creating the data the Arduino sends as a JSON. While it is more difficult to create initially and update with extra data, the alternative would be comma separated values which would increase the risk of mixups at no real advantage. JSON is better since I do not care about the transferred data size or latency and it makes it easy to read on the Python side.

Running all of these together fills the database up with weather data. The rest is serving it which I have done using a Java web server in spring, which I will be getting into in a future post.

If you have any questions, please post them below. Thanks for reading!

Leave a Reply

Your email address will not be published. Required fields are marked *