Wiring Together the Hardware: Integrating the Amospheric Sensor

In the world of garden monitoring, keeping track of environmental conditions is crucial. That's where the BME280 sensor comes into play in your GardenPi project. This sensor is a versatile little device capable of measuring temperature, humidity, and air pressure, making it an invaluable addition to your garden's Raspberry Pi monitoring system.

Why Choose the BME280 Sensor?

  • Accuracy: It provides precise readings of temperature, humidity, and pressure.

  • Compactness: Its small size makes it perfect for Raspberry Pi projects.

  • Versatility: Can be used for various applications, not just garden monitoring.

Applications in Garden Monitoring

  • Temperature Monitoring: Essential for understanding your plants' climate needs.

  • Humidity Tracking: Helps in managing watering schedules and detecting potential moisture issues.

  • Air Pressure Readings: Useful for advanced gardening analytics and correlations with weather patterns.

Connecting the BME280 sensor to your Raspberry Pi involves a few straightforward steps

step 1: Layout your components

For this stage of the process, you'll need:

  • the BME280 sensor

  • wires

  • and your Raspberry Pi we have been working with

step 2: Connect the BME280

BME280 pinout diagram

Referencing the above BME 280 and the below Raspberry Pi pinout diagrams, connect the sensor to your Raspberry Pi using the jumper wires. Typically, you'll need to connect the VCC pin to 3.3V on the Raspberry Pi, GND to GND, SCL to SCL (GPIO 3), and SDA to SDA (GPIO 2).

In our case we are wiring the power to the breadboard and the data to the pi. Steps for wiring the BME280 sensor to the breadboard and raspberry pi:

  1. Connect the BME280 VIN/VCC (3.3v) pin to the right side positive energy on the bread board to power the board

  2. Connect the BME280 Ground pinto the right side negative energy on the bread board

  3. Connect the BME280 SCL pin to the GPIO3 pin (third pin left column) on the Raspberry Pi

  4. Connect the BME280 SDA pin to the GPIO2 pin (second pin left column) on the Raspberry Pi

Following the steps above, your setup should now look similar to the diagram below:

step 3: testing the sensor with the Raspberry Pi

Note: This step assumes you have already Enable I2C on your Raspberry Pi through the raspi-config interface which allows the Raspberry Pi to communicate with the BME280 sensor. It also assumes you have installed the necessary Python packages to perform testing. If you have not done these steps, please reread https://www.seanpj.com/gardenpi/raspberrypisetup

Once everything is wired and set up, but before we can test the sensor, we need to issue the following command in terminal to determine the sensors address:

sudo i2cdetect -y 1

This will display a matrix similar to the following in the terminal window:

The number that is filled out, typically 76 or 77 is the I2C address for the BME280. If there is no number here, something is wrong with the wiring so go back.

With the address in hand, we can now use the below Python script to test if the Raspberry Pi is reading data correctly from the BME280 sensor (making sure to update the address to reflect your device):

import bme280
import smbus2
from time import sleep

port = 1
address = 0x76
bus = smbus2.SMBus(port)

calibration_params = bme280.load_calibration_params(bus, address)
while True:
    try:
        bme280_data = bme280.sample(bus,address)
        humidity = bme280_data.humidity
        pressure = bme280_data.pressure
        temp = bme280_data.temperature
        print(humidity,pressure,temp)
        sleep(5)
    except Exception as e:
        print("error initializing sensor:" , e)
        exit()

Copy the above into a notepad text document or (use an editor like VSCode) and name it something such as ‘bme280Test.py’.

Power on the raspberry pi device and connect to it from the PC using WinSCP. Copy the moistureTest file onto the raspberry pi and then use terminal to run it. Example:

sudo python3 bme280Test.py

This should print 3 numbers (% humidity, pressure, and Celsius temperature) every 5 seconds in terminal and you can use an ice cube or hand heat to test fluctuations. Hit Ctrl-C when you want to stop the script. If you are following along, you now have at least 2 working moisture sensors and a BME280 atmospheric sensor that looks like the following:

Next we will add the light sensor.

Previous
Previous

Wiring Together the Hardware: Integrating the Light Sensor

Next
Next

Wiring Together the Hardware: The Moisture Sensor and ADC