Skip to content

11. Input devices

in this week I used my Final project Atmega 328p board to program the BME 680 MultiSensor. and take the serial readings from it for these parameters:

  1. VOCs gases.
  2. Air humidity.
  3. Air pressure.
  4. altitude.
  5. temperature

Atmega 328p.

first i check my atmega pins and I need 4 pins for the sensor: GND, VCC, SDA and SCL.

and I connected my sensor to them.

programing.

I wrote the testing code for the sensor and its: BME680 Breakout

#include <Wire.h>
#include <SPI.h>
#include <Adafruit_Sensor.h>
#include "Adafruit_BME680.h"

#define BME_SCK 13
#define BME_MISO 12
#define BME_MOSI 11
#define BME_CS 10

#define SEALEVELPRESSURE_HPA (1013.25)

Adafruit_BME680 bme; // I2C
//Adafruit_BME680 bme(BME_CS); // hardware SPI
//Adafruit_BME680 bme(BME_CS, BME_MOSI, BME_MISO,  BME_SCK);

void setup() {
  Serial.begin(9600);
  while (!Serial);
  Serial.println(F("BME680 test"));

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

  // Set up oversampling and filter initialization
  bme.setTemperatureOversampling(BME680_OS_8X);
  bme.setHumidityOversampling(BME680_OS_2X);
  bme.setPressureOversampling(BME680_OS_4X);
  bme.setIIRFilterSize(BME680_FILTER_SIZE_3);
  bme.setGasHeater(320, 150); // 320*C for 150 ms
}

void loop() {
  if (! bme.performReading()) {
    Serial.println("Failed to perform reading :(");
    return;
  }
  Serial.print("Temperature = ");
  Serial.print(bme.temperature);
  Serial.println(" *C");

  Serial.print("Pressure = ");
  Serial.print(bme.pressure / 100.0);
  Serial.println(" hPa");

  Serial.print("Humidity = ");
  Serial.print(bme.humidity);
  Serial.println(" %");

  Serial.print("Gas = ");
  Serial.print(bme.gas_resistance / 1000.0);
  Serial.println(" KOhms");

  Serial.print("Approx. Altitude = ");
  Serial.print(bme.readAltitude(SEALEVELPRESSURE_HPA));
  Serial.println(" m");

  Serial.println();
  delay(2000);
}

then I connected the FTDI Cable and uploaded the sketch with the upload button and I opened the serial monitor to check the reading and the result like this:

References:

BME680 Breakout

Group Assignment.

LINK

I measured the changing voltage from an analog input ( potentiameter) and the videos below show how:

I used three methods: Multimeter, oscilloscope and serial monitor to read the voltage.

multimeter reading was not fixed and changing between 0.0 and 0.2 V difference.

the code I used to show reading on serial monitor:

void setup() {

  Serial.begin(9600);
}


void loop() {

  int sensorValue = analogRead(A0);

  float voltage = sensorValue * (5.0 / 1023.0);

  Serial.println(voltage);
}

and the oscilloscope reading showed me how when I turn the potentiometer knob to increase resistance how the voltage line drop below the 5V line. the line is difficult to read.

so i prefer the serial monitor