Arduino Web Server Tutorial (Part 2 - hardware)


In this section we connect the Arduino to the BME280 barometric pressure, temperature and humidity sensor. We also install a test sketch that will confirm that the hardware is functioning. The sensor readings will be displayed on the console.

Hardware Requirements

  • Arduino Board with built in ethernet or ethernet shield that supports the Arduino Ethernet library
  • Bosch BME280 Sensor. We used the Adafruit BME280 breakout board
  • Ethernet Cable and Switch
  • 9 to 12V DC Power source
  • SD Card to suite Arduino board

Reference

Hooking Up the Hardware

We are going to wire up the sensor using the I2C bus instead of SPI. This is because the ethernet controller and the SD card both use the SPI bus.

With the I2C bus we only need to connect the following:

  • Analog Pin 5 to SCK
  • Analog Pin 4 to SDI
Connect Arduino to Bosch BME280 Barometric Pressure Sensor I2C Hookup

Once we have connected up the Arduino to the sensor and prior to installing the web server sketch we should test that the sensor is working. We can use the example sketch to read the BME280 and output the barometric pressure, temperature and humidity to the console.

Programming the Arduino Board

We cannot program the Arduino via the Ethernet port, so we need to use the USB port. While we are programming and testing the Arduino board it can be powered via the USB port.

Powering the Arduino Board

We have used the USB port to provide power to the Arduino for this tutorial. Once you have programmed the Arduino you can disconnect the USB and power the board via the 9-12V DC Jack. You could use an inline ethernet power connection to provide power via the network cable.

Testing the Hardware

The basic test sketch is shown below. Before we start on the webserver software we are going to test that the board and BME280 sensor is functioning. To do this we are going to read the sensor and display the temperature on the console.

We are going to use the cactus_io_BME280_I2C library which will take care of communicating with the temperature sensor. We then create a BME280 object which we use to access the sensor data.

We need to call bme.readSensor() to get the data from the sensor. We can then call each of the BME280_I2C methods to retrieve the barometric pressure, humidity and temperature values.


Webserver_Hardware_Test_Sketch
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
#include <Wire.h>
#include "cactus_io_BME280_I2C.h"

// Create BME280 object
BME280_I2C bme; // I2C

void setup() {

Serial.begin(9600);
Serial.println("Webserver Hardware Test Bosch BME280 Pressure - Humidity - Temp Sensor");

if (!bme.begin()) {
Serial.println("Could not find a valid BME280 sensor, check wiring!");
while (1);
}

Serial.println("Pressure\tHumdity\t\tTemp\ttTemp");
}

void loop() {

bme.readSensor();

Serial.print(bme.getPressure_MB()); Serial.print(" mb\t"); // Pressure in millibars
Serial.print(bme.getHumidity()); Serial.print(" %\t\t");
Serial.print(bme.getTemperature_C()); Serial.print(" *C\t");
Serial.print(bme.getTemperature_F()); Serial.println(" *F");

// Add a 2 second delay.
delay(2000); //just here to slow down the output.
}

If the board and sensor is functioning we should see this displayed in the console.

Sample console output for DS18B20 test

If no data is displayed then check that the power and ground are connected. Check that A4 is connected to the SDI pin and that A5 is connect to the SCK pin on the breakout board.

If the hardware working we can now move onto the next step which is to setup the basic webserver. We can then access the Arduino from a browser and it will display a basic html page showing the data from the sensor.



License