{"id":23485,"date":"2024-07-25T11:06:46","date_gmt":"2024-07-25T09:06:46","guid":{"rendered":"https:\/\/monraspberry.com\/?p=23485"},"modified":"2024-07-17T11:45:56","modified_gmt":"2024-07-17T09:45:56","slug":"creating-a-weather-station-with-a-raspberry-pi","status":"publish","type":"post","link":"https:\/\/monraspberry.com\/en\/creer-une-station-meteo-avec-un-raspberry-pi\/","title":{"rendered":"Creating a weather station with a Raspberry Pi"},"content":{"rendered":"<p>Building a weather station with a Raspberry Pi is an exciting and educational project. You can measure temperature, humidity, atmospheric pressure and much more. Here's a detailed guide to help you get started.<\/p>\n\n\n\n<h4 class=\"wp-block-heading\">Contents<\/h4>\n\n\n\n<ol class=\"wp-block-list\">\n<li>Introduction<\/li>\n\n\n\n<li>Equipment required<\/li>\n\n\n\n<li>Raspberry Pi configuration<\/li>\n\n\n\n<li>Sensor installation<\/li>\n\n\n\n<li>Programming the Raspberry Pi<\/li>\n\n\n\n<li>Creating the Web Interface<\/li>\n\n\n\n<li>Data storage<\/li>\n\n\n\n<li>Testing and adjustment<\/li>\n\n\n\n<li>Conclusion<\/li>\n<\/ol>\n\n\n\n<h3 class=\"wp-block-heading\">1. Introduction<\/h3>\n\n\n\n<p>A personal weather station lets you monitor local weather conditions in real time. Using a Raspberry Pi and various sensors, you can collect and display weather data accurately and reliably.<\/p>\n\n\n\n<h3 class=\"wp-block-heading\">2. Materials required<\/h3>\n\n\n\n<ul class=\"wp-block-list\">\n<li>Raspberry Pi (model 3 or higher)<\/li>\n\n\n\n<li>microSD card (minimum 16 GB) with Raspbian installed<\/li>\n\n\n\n<li>Temperature and humidity sensor (DHT11 or DHT22)<\/li>\n\n\n\n<li>Atmospheric pressure sensor (BMP180 or BMP280)<\/li>\n\n\n\n<li>Connecting wires<\/li>\n\n\n\n<li>Breadboard<\/li>\n\n\n\n<li>Internet access (Wi-Fi or Ethernet)<\/li>\n<\/ul>\n\n\n\n<h3 class=\"wp-block-heading\">3. Raspberry Pi configuration<\/h3>\n\n\n\n<ol class=\"wp-block-list\">\n<li><strong>Install Raspbian :<\/strong>\n<ul class=\"wp-block-list\">\n<li>Download the Raspbian image from the official website.<\/li>\n\n\n\n<li>Use a tool like balenaEtcher to burn the image onto the microSD card.<\/li>\n\n\n\n<li>Insert the microSD card into the Raspberry Pi and start it up.<\/li>\n<\/ul>\n<\/li>\n\n\n\n<li><strong>Configuring the Raspberry Pi :<\/strong>\n<ul class=\"wp-block-list\">\n<li>Log in with the default credentials (user : <code>pi<\/code>password : <code>raspberry<\/code>).<\/li>\n\n\n\n<li>Update the system with the following commands:\n<ul class=\"wp-block-list\">\n<li><code>sudo apt update <\/code><\/li>\n\n\n\n<li><code>sudo apt upgrade<\/code><\/li>\n<\/ul>\n<\/li>\n<\/ul>\n<\/li>\n\n\n\n<li><strong>Install the necessary libraries :<\/strong>\n<ul class=\"wp-block-list\">\n<li>Install the libraries for :\n<ul class=\"wp-block-list\">\n<li><code>sudo apt install python3-pip <\/code><\/li>\n\n\n\n<li><code>pip3 install Adafruit_DHT Adafruit_BMP<\/code><\/li>\n<\/ul>\n<\/li>\n<\/ul>\n<\/li>\n<\/ol>\n\n\n\n<h3 class=\"wp-block-heading\">4. Sensor installation<\/h3>\n\n\n\n<ol class=\"wp-block-list\">\n<li><strong>Connect temperature and humidity sensor (DHT11\/DHT22) :<\/strong>\n<ul class=\"wp-block-list\">\n<li>Connect the sensor to the breadboard.<\/li>\n\n\n\n<li>Connect the wires: VCC to 3.3V, GND to GND, and the signal output to a GPIO (e.g. GPIO4).<\/li>\n<\/ul>\n<\/li>\n\n\n\n<li><strong>Connect atmospheric pressure sensor (BMP180\/BMP280) :<\/strong>\n<ul class=\"wp-block-list\">\n<li>Connect the sensor wires: VCC to 3.3V, GND to GND, SDA to GPIO2 (SDA) and SCL to GPIO3 (SCL).<\/li>\n<\/ul>\n<\/li>\n<\/ol>\n\n\n\n<h3 class=\"wp-block-heading\">5. Programming the Raspberry Pi<\/h3>\n\n\n\n<ol class=\"wp-block-list\">\n<li><strong>Read sensor data :<\/strong>\n<ul class=\"wp-block-list\">\n<li>Create a Python script to read sensor data. Here's a sample code:<\/li>\n<\/ul>\n<\/li>\n<\/ol>\n\n\n<div class=\"wp-block-syntaxhighlighter-code\"><pre class=\"brush: plain; title: ; notranslate\" title=\"\">\nimport Adafruit_DHT\nimport Adafruit_BMP.BMP085 as BMP085\nimport time\n\n# Sensor configuration\nDHT_SENSOR = Adafruit_DHT.DHT22\nDHT_PIN = 4\nbmp = BMP085.BMP085()\n\ndef read_sensors():\n    humidity, temperature = Adafruit_DHT.read_retry(DHT_SENSOR, DHT_PIN)\n    pressure = bmp.read_pressure()\n    return humidity, temperature, pressure\n\nwhile True:\n    humidity, temperature, pressure = read_sensors()\n    print(f \"Temp: {temperature}\u00b0C Humidity: {humidity}% Pressure: {pressure} Pa\")\n    time.sleep(2)\n<\/pre><\/div>\n\n\n<h3 class=\"wp-block-heading\">6. Web interface creation<\/h3>\n\n\n\n<ol class=\"wp-block-list\">\n<li><strong>Install Flask :<\/strong>\n<ul class=\"wp-block-list\">\n<li>Use Flask to create a simple web interface:\n<ul class=\"wp-block-list\">\n<li><code>pip3 install flask<\/code><\/li>\n<\/ul>\n<\/li>\n<\/ul>\n<\/li>\n\n\n\n<li><strong>Creating a Flask script :<\/strong><\/li>\n<\/ol>\n\n\n<div class=\"wp-block-syntaxhighlighter-code\"><pre class=\"brush: plain; title: ; notranslate\" title=\"\">\nfrom flask import Flask, render_template\nimport Adafruit_DHT\nimport Adafruit_BMP.BMP085 as BMP085\n\napp = Flask(__name__)\n\nDHT_SENSOR = Adafruit_DHT.DHT22\nDHT_PIN = 4\nbmp = BMP085.BMP085()\n\ndef read_sensors():\n    humidity, temperature = Adafruit_DHT.read_retry(DHT_SENSOR, DHT_PIN)\n    pressure = bmp.read_pressure()\n    return humidity, temperature, pressure\n\n@app.route('\/')\ndef index():\n    humidity, temperature, pressure = read_sensors()\n    return render_template('index.html', temperature=temperature, humidity=humidity, pressure=pressure)\n\nif __name__ == '__main__':\n    app.run(host='0.0.0.0', port=5000)\n<\/pre><\/div>\n\n\n<p>3. <strong>Create HTML template :<\/strong><\/p>\n\n\n\n<ul class=\"wp-block-list\">\n<li>Create a file <code>templates\/index.html<\/code> :<\/li>\n<\/ul>\n\n\n<div class=\"wp-block-syntaxhighlighter-code\"><pre class=\"brush: plain; title: ; notranslate\" title=\"\">\n<title>Weather Station<\/title>\n\n\n    <h1>Current Weather Conditions<\/h1>\n    <p>Temperature : {{ temperature }}\u00b0C<\/p>\n    <p>Humidity: {{ humidity }}%<\/p>\n    <p>Atmospheric pressure : {{ pressure }} Pa<\/p>\n<\/pre><\/div>\n\n\n<h3 class=\"wp-block-heading\">7. Data storage<\/h3>\n\n\n\n<ol class=\"wp-block-list\">\n<li><strong>Using a SQLite database (optional) :<\/strong>\n<ul class=\"wp-block-list\">\n<li>To save weather data, you can use SQLite :\n<ul class=\"wp-block-list\">\n<li>s<code>udo apt install sqlite3 <\/code><\/li>\n\n\n\n<li><code>pip3 install flask-sqlalchemy<\/code><\/li>\n<\/ul>\n<\/li>\n<\/ul>\n<\/li>\n\n\n\n<li><strong>Modify the Flask script to save the data:<\/strong><\/li>\n<\/ol>\n\n\n<div class=\"wp-block-syntaxhighlighter-code\"><pre class=\"brush: plain; title: ; notranslate\" title=\"\">\nfrom flask import Flask, render_template\nfrom flask_sqlalchemy import SQLAlchemy\nimport Adafruit_DHT\nimport Adafruit_BMP.BMP085 as BMP085\nimport datetime\n\napp = Flask(__name__)\napp.config['SQLALCHEMY_DATABASE_URI'] = 'sqlite:\/\/\/weather.db'\ndb = SQLAlchemy(app)\n\nclass WeatherData(db.Model):\n    id = db.Column(db.Integer, primary_key=True)\n    timestamp = db.Column(db.DateTime, default=datetime.datetime.utcnow)\n    temperature = db.Column(db.Float)\n    humidity = db.Column(db.Float)\n    pressure = db.Column(db.Float)\n\nDHT_SENSOR = Adafruit_DHT.DHT22\nDHT_PIN = 4\nbmp = BMP085.BMP085()\n\ndef read_sensors():\n    humidity, temperature = Adafruit_DHT.read_retry(DHT_SENSOR, DHT_PIN)\n    pressure = bmp.read_pressure()\n    return humidity, temperature, pressure\n\n@app.route('\/')\ndef index():\n    humidity, temperature, pressure = read_sensors()\n    weather_data = WeatherData(temperature=temperature, humidity=humidity, pressure=pressure)\n    db.session.add(weather_data)\n    db.session.commit()\n    return render_template('index.html', temperature=temperature, humidity=humidity, pressure=pressure)\n\nif __name__ == '__main__':\n    db.create_all()\n    app.run(host='0.0.0.0', port=5000)\n<\/pre><\/div>\n\n\n<h3 class=\"wp-block-heading\">8. Tests and adjustments<\/h3>\n\n\n\n<ol class=\"wp-block-list\">\n<li><strong>Test the system :<\/strong>\n<ul class=\"wp-block-list\">\n<li>Make sure all sensors are working properly.<\/li>\n\n\n\n<li>Test the web interface and check that the data is displayed correctly.<\/li>\n<\/ul>\n<\/li>\n\n\n\n<li><strong>Adjust parameters :<\/strong>\n<ul class=\"wp-block-list\">\n<li>Adjust sensor reading intervals and web interface updates to suit your needs.<\/li>\n<\/ul>\n<\/li>\n<\/ol>\n\n\n\n<h3 class=\"wp-block-heading\">9. Conclusion<\/h3>\n\n\n\n<p>By following this guide, you now have a working weather station with a Raspberry Pi. You can monitor local weather conditions in real time and store data for later analysis. Enjoy your weather station and don't hesitate to add extra features to make it even more powerful!<\/p>","protected":false},"excerpt":{"rendered":"<p>Construire une station m\u00e9t\u00e9o avec un Raspberry Pi est un projet passionnant et \u00e9ducatif. Vous pouvez mesurer la temp\u00e9rature, l&#8217;humidit\u00e9, la pression atmosph\u00e9rique et plus encore. Voici un guide d\u00e9taill\u00e9 pour vous aider \u00e0 r\u00e9aliser ce projet. Sommaire 1. Introduction Une station m\u00e9t\u00e9o personnelle vous permet de suivre les conditions m\u00e9t\u00e9orologiques locales en temps r\u00e9el. [&hellip;]<\/p>\n","protected":false},"author":1,"featured_media":23486,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"_jetpack_memberships_contains_paid_content":false,"footnotes":""},"categories":[308],"tags":[],"class_list":["post-23485","post","type-post","status-publish","format-standard","has-post-thumbnail","hentry","category-tutos"],"featured_image_src":{"landsacpe":["https:\/\/monraspberry.com\/wp-content\/uploads\/2024\/07\/Station-meteo-Raspberry-Pi.png",791,445,false],"list":["https:\/\/monraspberry.com\/wp-content\/uploads\/2024\/07\/Station-meteo-Raspberry-Pi.png",463,260,false],"medium":["https:\/\/monraspberry.com\/wp-content\/uploads\/2024\/07\/Station-meteo-Raspberry-Pi-300x169.png",300,169,true],"full":["https:\/\/monraspberry.com\/wp-content\/uploads\/2024\/07\/Station-meteo-Raspberry-Pi.png",1920,1080,false]},"jetpack_featured_media_url":"https:\/\/monraspberry.com\/wp-content\/uploads\/2024\/07\/Station-meteo-Raspberry-Pi.png","jetpack_sharing_enabled":true,"_links":{"self":[{"href":"https:\/\/monraspberry.com\/en\/wp-json\/wp\/v2\/posts\/23485","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/monraspberry.com\/en\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/monraspberry.com\/en\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/monraspberry.com\/en\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/monraspberry.com\/en\/wp-json\/wp\/v2\/comments?post=23485"}],"version-history":[{"count":0,"href":"https:\/\/monraspberry.com\/en\/wp-json\/wp\/v2\/posts\/23485\/revisions"}],"wp:featuredmedia":[{"embeddable":true,"href":"https:\/\/monraspberry.com\/en\/wp-json\/wp\/v2\/media\/23486"}],"wp:attachment":[{"href":"https:\/\/monraspberry.com\/en\/wp-json\/wp\/v2\/media?parent=23485"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/monraspberry.com\/en\/wp-json\/wp\/v2\/categories?post=23485"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/monraspberry.com\/en\/wp-json\/wp\/v2\/tags?post=23485"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}