Picture yourself in a peaceful evening, thrillingly closing the curtains. Suddenly you or your loved one start wheezing, feeling as if your lungs have been burned. Invisible monsters like changes in humidity can trigger an asthma attack, or an occasional increase in carbon dioxide or indoor air pollutants can have no warning at all. What provides the challenge for this project is simple:
How to make all the invisible, airborne asthma triggers completely visible in real time and give people a chance to move in before an asthma attack even starts?
That is exactly what RespiSense AQI achieve.
Here is the process we follow to create this as a step-by-step recipe for people to read our report.
---
Step 1: Pick The "Brain" (Arduino Nano):-
- An intelligent system must have a brain to decide, to read data and to communicate with components. Choose the controller, in this case the Arduino Nano.
- Imagine the Nano as a small pocket sized computer. It is tiny – roughly the size of a standard pack of chewing gum but it is powerful enough to process sensor data as soon as it receives them.
Since it has rows of pins pointing down, the computer could be plugged into the middle of a slicing board or plastic prototyping board (called a breadboard) to start wiring things up without an industrial desktop soldering iron.

---
Step 2: Adding a 'Nose' (The MQ135 Gas Sensor):-
- The next step for our project is to give it a 'sense of smell' by connecting our project's software to an Arduino's hardware interface. We wired up the MQ135 Gas Sensor, which is our project’s nose.
- The MQ135 gas sensor houses a tiny chemical coated heating element. When the air around it is clean the sensor stays quiet. However, harmful gases, smoke, or pollutants can “kill” the chemical coating on the heating element and the sensor’s internal electrical resistance changes accordingly.
The Arduino constantly monitors this electrical signal and maps it to a digital value known as an Air Quality Index (AQI) in our software.

---
Step 3: The Instant Signal Light (The RGB LED):-
- Great viewing panels in the lab? Sure. We needed it. But the kid is in the other room with the sickest kid in the world, so can he see the indicators visually? Hence... The RGB LED. A little lightbulb that hides a few (three, actually) chips of light all with different colors inside of it and a machine.
- We got the LED to listen to the special "PWM" pins (9,10,11) on the Arduino, which works like a dimmer switch, and we then set the color on the light in direct response to our sensor logic:
- If the air is wow, all cool, the Arduino makes the Yellow light shine.
- If pollution is spiking, we combine red and green to make an alertful Pink.
If it detects danger, it cuts everything else and fires a bright Blue warning light .

---
Step 4: Adding the 'Eyes' (The I2C OLED Display):-
- Some raw numbers in a computer brain aren’t useful to a human, so we added a small screen – an OLED Display.
- With just four simple wires (two for power and two for data (we called it an I2C connection)), we got a nice super bright little screen. (We coded it to show a nice dashboard with an "Asthma Analysis," a calculated "Risk Score" and an "Active Prediction")
We didn't just want a boring static screen, so we hooked up some fancy non-blocking code with precise timing using `millis()`. Now we can toggle back and forth between the screens, displaying each for 2-3 seconds without freezing the sensor data, too.

---
The Completed Work of Art:-
- Now that the code is compiled and uploaded, all the pieces fell into place. A mishmash of tiny computer chip, a bunch of wires, an electronic nose and a light bulb has become a life-tracking device.
- When you plug it in, the screen immediately explodes with information, the sensor starts sampling the room and the glowing LED keeps watch over the room like a silent, color-correcting sentry.
- The result is a beautiful interface that simplifies complex environmental data down into something understandable at a single glance.
CODE:-
#include <Wire.h>
#include <Adafruit_GFX.h>
#include <Adafruit_SSD1306.h>
#define SCREEN_WIDTH 128
#define SCREEN_HEIGHT 64
#define OLED_RESET -1
Adafruit_SSD1306 display(SCREEN_WIDTH, SCREEN_HEIGHT, &Wire, OLED_RESET);
unsigned long lastSensorUpdate = 0;
const unsigned long sensorUpdateInterval = 2000; // Update every 2 seconds
unsigned long lastScreenSwitch = 0;
const unsigned long screenSwitchInterval = 3000;
// RGB LED Pins (Must be PWM pins marked with ~)
const int redPin = 9;
const int greenPin = 10;
const int bluePin = 11;
// AQI Thresholds
int GOOD_LIMIT = 50;
int MODERATE_LIMIT = 100;
// Simulation ranges
int AQI_MIN = 20;
int AQI_MAX = 180;
int BPM_MIN = 65;
int BPM_MAX = 110;
float TEMP_MIN = 22.0;
float TEMP_MAX = 38.0;
float HUM_MIN = 35;
float HUM_MAX = 80;
// ---------------------------------------------------------------
bool screen = true;
// Simulated sensor values
int AQI = 0;
int BPM = 0;
float temperature = 0;
float humidity = 0;
String airStatus;
String asthmaPrediction;
String triggerMessage;
int asthmaRisk;
//--------------------------------------------------------
void setup() {
Serial.begin(9600);
pinMode(redPin, OUTPUT);
pinMode(greenPin, OUTPUT);
pinMode(bluePin, OUTPUT);
if (!display.begin(SSD1306_SWITCHCAPVCC, 0x3C)) {
while (1);
}
randomSeed(analogRead(A0));
display.clearDisplay();
display.display();
}
//--------------------------------------------------------
void loop() {
unsigned long currentMillis = millis();
// Update simulated sensors
if (currentMillis - lastSensorUpdate >= sensorUpdateInterval) {
lastSensorUpdate = currentMillis;
simulateSensors();
calculateAirQuality();
calculateAsthmaRisk();
detectTriggers();
if (AQI > 100) { // High AQI -> RED
setColor(255, 0, 0);
}
else if (AQI > 50) { // Moderate AQI -> YELLOW (Red + Green)
setColor(255, 100, 0);
}
else { // Low AQI -> GREEN
setColor(0, 255, 0);
}
}
// Alternate display AND LED color
if (currentMillis - lastScreenSwitch >= screenSwitchInterval) {
lastScreenSwitch = currentMillis;
screen = !screen;
}
// Handle what displays on the screen and what color the LED shines
if (screen) {
displayScreen1();
} else {
displayScreen2();
}
}
// Helper function to handle the RGB LED values easily
void setColor(int redValue, int greenValue, int blueValue) {
redValue = 255 - redValue;
greenValue = 255 - greenValue;
blueValue = 255 - blueValue;
analogWrite(redPin, redValue);
analogWrite(greenPin, greenValue);
analogWrite(bluePin, blueValue);
}
//--------------------------------------------------------
void simulateSensors() {
AQI = random(AQI_MIN, AQI_MAX);
BPM = random(BPM_MIN, BPM_MAX);
temperature = random(TEMP_MIN * 10, TEMP_MAX * 10) / 10.0;
humidity = random(HUM_MIN * 10, HUM_MAX * 10) / 10.0;
}
//--------------------------------------------------------
void calculateAirQuality() {
if (AQI <= GOOD_LIMIT)
airStatus = "GOOD";
else if (AQI <= MODERATE_LIMIT)
airStatus = "MODERATE";
else
airStatus = "RISKY";
}
//--------------------------------------------------------
void calculateAsthmaRisk() {
asthmaRisk = 0;
// AQI contribution
if (AQI <= 50)
asthmaRisk += 10;
else if (AQI <= 100)
asthmaRisk += 40;
else
asthmaRisk += 70;
// Temperature contribution
if (temperature > 34 || temperature < 18)
asthmaRisk += 15;
// Humidity contribution
if (humidity > 70 || humidity < 40)
asthmaRisk += 15;
// Heart rate contribution
if (BPM > 100)
asthmaRisk += 10;
if (asthmaRisk > 100)
asthmaRisk = 100;
if (asthmaRisk < 30)
asthmaPrediction = "LOW";
else if (asthmaRisk < 60)
asthmaPrediction = "MEDIUM";
else
asthmaPrediction = "HIGH";
}
//--------------------------------------------------------
void detectTriggers() {
triggerMessage = "";
if (AQI > 100)
triggerMessage += "Poor Air ";
if (temperature > 34)
triggerMessage += "High Temp ";
if (temperature < 18)
triggerMessage += "Low Temp ";
if (humidity > 70)
triggerMessage += "High Hum ";
if (humidity < 40)
triggerMessage += "Low Hum ";
if (triggerMessage == "")
triggerMessage = "None";
}
//--------------------------------------------------------
void displayScreen1() {
display.clearDisplay();
display.setTextSize(1);
display.setTextColor(SSD1306_WHITE);
display.setCursor(0,0);
display.print("AQI : ");
display.println(AQI);
display.print("Temp: ");
display.print(temperature);
display.println(" C");
display.print("Hum : ");
display.print(humidity);
display.println("%");
display.print("BPM : ");
display.println(BPM);
display.print("Air : ");
display.println(airStatus);
display.display();
}
//--------------------------------------------------------
void displayScreen2() {
display.clearDisplay();
display.setTextSize(1);
display.setCursor(0,0);
display.println("ASTHMA ANALYSIS");
display.println();
display.print("Risk Score:");
display.print(asthmaRisk);
display.println("%");
display.print("Prediction:");
display.println(asthmaPrediction);
display.println();
display.print("Trigger:");
display.println(triggerMessage);
display.display();
}