Skip to content

Commit

Permalink
changes
Browse files Browse the repository at this point in the history
  • Loading branch information
vs4vijay committed Mar 19, 2024
1 parent 994e1b6 commit a59857a
Show file tree
Hide file tree
Showing 2 changed files with 26 additions and 34 deletions.
48 changes: 23 additions & 25 deletions airsense_firmware/src/main.cpp
Original file line number Diff line number Diff line change
@@ -1,16 +1,15 @@
#include <Arduino.h>
#include <Wire.h>
// #include <Adafruit_Sensor.h>
#include <Adafruit_BME688.h>
#include <Adafruit_Sensor.h>
#include <Adafruit_BME680.h>

#define LED_PIN 2
#define BME688_I2C_ADDR 0x77

Adafruit_BME688 bme;
Adafruit_BME680 bme;

void blink_led();
float calculate_aqi(float temperature, float humidity, float pressure, float gasResistance);

float calculate_aqi(Adafruit_BME680 bme);

void blink_led()
{
Expand All @@ -21,7 +20,6 @@ void blink_led()
digitalWrite(LED_PIN, LOW);
}


void setup()
{
Serial.begin(115200);
Expand All @@ -30,18 +28,31 @@ void setup()
if (!bme.begin(BME688_I2C_ADDR))
{
Serial.println("Could not find a valid BME688 sensor, check wiring!");
while (1);
while (1)
;
}

Serial.println("[+] AirSense is running...");
}

void loop()
{

// Calculate Air Quality Index (AQI) using a formula
float aqi = calculate_aqi(bme);
Serial.print("Air Quality Index (AQI): ");
Serial.println(aqi);

delay(2000);
}

float calculate_aqi(Adafruit_BME680 bme)
{

float temperature = bme.readTemperature();
float humidity = bme.readHumidity();
float pressure = bme.readPressure() / 100.0;
float gasResistance = bme.readGasResistance() / 1000.0;
// float gasResistance = bme.readGasResistance() / 1000.0;

Serial.print("Temperature: ");
Serial.print(temperature);
Expand All @@ -55,29 +66,16 @@ void loop()
Serial.print(pressure);
Serial.println(" hPa");

Serial.print("Gas Resistance: ");
Serial.print(gasResistance);
Serial.println(" KOhms");

// Calculate Air Quality Index (AQI) using a formula
float aqi = calculate_aqi(temperature, humidity, pressure, gasResistance);
Serial.print("Air Quality Index (AQI): ");
Serial.println(aqi);

delay(2000);
}

float calculate_aqi(float temperature, float humidity, float pressure, float gasResistance)
{


// Serial.print("Gas Resistance: ");
// Serial.print(gasResistance);
// Serial.println(" KOhms");

// TODO: Implement AQI calculation based on sensor readings
// You can use the provided sensor data to calculate the AQI
// and return the calculated value

// Example calculation:
float aqi = temperature + humidity + pressure + gasResistance;
float aqi = temperature + humidity + pressure;

return aqi;
}
12 changes: 3 additions & 9 deletions platformio.ini
Original file line number Diff line number Diff line change
Expand Up @@ -11,19 +11,13 @@
[platformio]
default_envs = esp32dev
src_dir = airsense_firmware/src
; include_dir = airsense_firmware/include
; lib_dir = airsense_firmware/lib
; test_dir = airsense_firmware/test

[env:esp32dev]
platform = espressif32
board = esp32dev
framework = arduino
monitor_speed = 115200
upload_speed = 115200


; [env:native]
; # Used to run unit test; g++ must be in PATH.
; platform = native
; build_flags = "-std=c++11"
lib_deps =
adafruit/Adafruit BME680 Library@^2.0.4
adafruit/Adafruit Unified Sensor@^1.1.14

0 comments on commit a59857a

Please sign in to comment.