Community project

Smart Classroom Air Monitor

Photo of Smart Classroom Air Monitor
Generated with AI

AR-JAY MORETE

Published November 22, 2026

This smart classroom air monitor combines sound and air quality sensing to track environmental conditions in real time. Built around an Arduino Uno, the system reads noise levels from a KY-038 sound sensor and air quality data from an MQ135 sensor, displaying results on a 16x2 LCD screen with visual and audible alerts via LEDs and a piezo buzzer. A precision RTC module timestamps all readings for logging and analysis.

The guide provides a complete wiring diagram, full parts list, calibrated firmware, and step-by-step assembly instructions. Builders will learn how to integrate multiple I2C sensors, handle sensor warmup periods, manage display updates efficiently, and implement threshold-based alerting. The modular design makes it easy to customize thresholds and add additional sensors for expanded monitoring capabilities.

Wiring diagram

Wiring diagram for Smart Classroom Air Monitor
Loading diagram…

Gather all the parts

QtyComponent
1

Ky 038 Sound Sensor

KY-038 sound-detection module: electret microphone + LM393 comparator. Analog raw + digital threshold output (potentiometer-tuned). Common ringer / clap detector; not suitable for audio capture.

1

MQ135

Air quality and gas sensor (analog)

1

LCD 16x2 I2C

16x2 character LCD display with I2C backpack

1

Adafruit DS3231 Precision RTC Breakout

DS3231 precision real-time clock breakout with integrated TCXO and crystal for accurate timekeeping over I2C.

1

LED

green

Standard 3mm/5mm through-hole LED. A current-limiting series resistor is added automatically.

1

LED

red

Standard 3mm/5mm through-hole LED. A current-limiting series resistor is added automatically.

1

Resistor

220 Ω

Through-hole resistor (current-limiting in series with an LED)

1

Resistor

220 Ω

Through-hole resistor (current-limiting in series with an LED)

1

Rocker Switch

Classic compact panel-mount rocker switch for on/off power control in enclosures.

1

5 V low-current active piezo buzzer

Two-terminal self-oscillating piezo; require a datasheet rating of 10 mA maximum at 5 V for direct GPIO drive.

1

Regulated 5 V DC supply with screw-terminal output

Isolated regulated 5.0 V DC wall supply, at least 1 A, with insulated low-voltage output leads.

Assemble it in 5 steps

1. Arrange the board and modules

Use one full-size 830-point breadboard. Put the Uno to its left, microphone and MQ-135 along the top edge, LCD above the board and RTC at upper right. Use male-to-male and female-to-male jumpers as needed (about 25 leads). Keep the hot MQ-135 can exposed and away from fingers and plastic.

2. Wire power and signal junctions

The switched red rail feeds the Uno 5V header and GND to the blue rail. Use one continuous section or bridge split rails with matching jumpers. Feed sound, MQ-135 and LCD VCC and RTC VIN from red; tie their grounds to blue. Use yellow for sound AO to A0 and orange for MQ-135 AO (marked A0 on some modules) to A1. Leave both digital outputs open. Join Uno A4 and both SDA pins in strip A10–E10 (green wires); join A5 and both SCL pins in A12–E12 (purple wires). Read module labels; header order varies.

3. Place the LEDs diagonally

With numbered rows increasing left to right and A–E above the center gap, put green long leg in D24 and short leg in D25 (along the board). Put red long leg in E40 and short leg in F40 (across the center gap; gently spread leads). Connect D6 to A20; put green resistor between B20 and B24. Connect D7 to A36; put red resistor between B36 and B40. Ground green via A25 and red via J40. Each resistor is 220 ohms; each LED has legs in separate strips.

4. Connect the active buzzer

Put buzzer leads into two unused, separate strips (for example H48 and H51 if the lead spacing fits; otherwise use jumpers). Connect plus to D8 and minus to the ground rail.

  • Use a self-oscillating 5 V piezo buzzer rated at 10 mA maximum. Do not connect an unknown-current or magnetic buzzer directly to D8.

5. Wire the rocker on the breadboard

With all power unplugged, bring the regulated supply positive to rocker T1 on a spare breadboard strip (for example A56). Bring T2 to a different strip (A58), then jumper that strip to the red rail. Connect supply negative to the blue rail. Use insulated terminal-to-jumper leads if the rocker tabs do not fit; secure the rocker next to the breadboard rather than forcing its tabs in. Verify polarity and 5.0 V at the switched rails before attaching the Uno and modules. The RTC backup cell may retain time when off.

  • Only regulated 5.0 V DC may feed the Uno 5V header. Do not use VIN or wire mains to the breadboard.
  • Before plugging in computer USB for Deploy, physically disconnect the external supply and disconnect the jumper between the Uno 5V header and red rail. Unplug USB before reconnecting them.

Review all connections

1. Connections between "sound" and "Arduino"

FunctionsoundArduino
powerVCC5V
groundGNDGND
analogAOGPIO 14

2. Connections between "air" and "Arduino"

FunctionairArduino
powerVCC5V
groundGNDGND
analogA0GPIO 15

3. Connections between "lcd" and "Arduino"

FunctionlcdArduino
powerVCC5V
groundGNDGND
i2cSDAGPIO 18
i2cSCLGPIO 19

4. Connections between "rtc" and "Arduino"

FunctionrtcArduino
powerVIN5V
groundGNDGND
i2cSDAGPIO 18
i2cSCLGPIO 19

5. Connections between "rg" and "Arduino"

FunctionrgArduino
digitalP1GPIO 6

6. Connections between "rr" and "Arduino"

FunctionrrArduino
digitalP1GPIO 7

7. Connections between "green" and "Arduino"

FunctiongreenArduino
digitalANODE → Resistor P2EXT
groundGNDGND

8. Connections between "red" and "Arduino"

FunctionredArduino
digitalANODE → Resistor P2EXT
groundGNDGND

9. Connections between "alarm" and "Arduino"

FunctionalarmArduino
digitalPOSGPIO 8
groundNEGGND

10. Connections between "supply" and "Arduino"

FunctionsupplyArduino
powerVOUT → Rocker Switch T1EXT
groundGNDGND

11. Connections between "rocker" and "Arduino"

FunctionrockerArduino
powerT2 → Switched red breadboard rail to Uno 5V header and module power5V

Deploy the firmware

#include <Arduino.h>
#include <Wire.h>
#include <LiquidCrystal_I2C.h>
#include <RTClib.h>
#include <stdio.h>
#include <string.h>

// Starter values only. Calibrate on your own hardware (raw ADC counts).
constexpr uint16_t NOISE_THRESHOLD = 40, AIR_THRESHOLD = 500;
constexpr uint32_t AIR_WARMUP_MS = 180000, PAGE_MS = 3000;
constexpr uint8_t GREEN = 6, RED = 7, BUZZER = 8;
LiquidCrystal_I2C lcd(0x27,16,2), alternate(0x3F,16,2);
LiquidCrystal_I2C *screen = nullptr;
RTC_DS3231 rtc;
bool clockOk, noiseHigh, airHigh, airReady;
uint16_t lo=1023, hi=0, noise=0, air=0;
uint32_t started, windowAt, airAt, pageAt, refreshAt, logAt;
uint8_t page;
char previous[2][17] = {};

bool responds(uint8_t address) {
  Wire.beginTransmission(address);
  return Wire.endTransmission()==0;
}

// Overwrite only changed rows, padding old text away without flicker.
void line(uint8_t row, const char *text) {
  if (!screen) return;
  char padded[17];
  snprintf(padded,sizeof padded,"%-16.16s",text);
  if (strcmp(previous[row],padded)==0) return;
  strcpy(previous[row],padded);
  screen->setCursor(0,row);
  screen->print(padded);
}

void setup() {
  pinMode(GREEN,OUTPUT); pinMode(RED,OUTPUT); pinMode(BUZZER,OUTPUT);
  Serial.begin(115200);
  Wire.begin();
  clockOk=rtc.begin();
  // Set once on lost backup power; compile time is an approximate local time.
  if (clockOk) rtc.adjust(DateTime(2026, 11, 22, 04, 45, 0));
  if (responds(0x27)) screen=&lcd;
  else if (responds(0x3F)) screen=&alternate;
  if (screen) { screen->init(); screen->backlight(); }
  else Serial.println(F("LCD not found at 0x27 or 0x3F"));
  started=windowAt=airAt=pageAt=millis();
  air=analogRead(A1);
}

void loop() {
  uint32_t t=millis();
  // Peak-to-peak removes the microphone's DC offset. No delay between reads.
  analogRead(A0); // Allow the ADC input to settle after switching channels.
  uint16_t sample=analogRead(A0);
  if (sample<lo) lo=sample;
  if (sample>hi) hi=sample;
  if (t-windowAt>=50) {
    noise=hi-lo;
    noiseHigh=noise>NOISE_THRESHOLD;
    lo=1023; hi=0; windowAt=t;
  }
  if (t-airAt>=100) {
    analogRead(A1);
    air=(7UL*air+analogRead(A1)+4)/8;
    airAt=t;
  }
  if (t-started>=AIR_WARMUP_MS) airReady=true;
  airHigh=airReady && air>AIR_THRESHOLD;
  bool warning=noiseHigh || airHigh;
  digitalWrite(GREEN,airReady && !warning);
  digitalWrite(RED,warning);
  digitalWrite(BUZZER,warning);
  if (t-logAt>=500) {
    logAt=t;
    Serial.print(F("Noise p-p: ")); Serial.print(noise);
    Serial.print(F("  MQ-135: ")); Serial.print(air);
    if (!airReady) Serial.print(F(" (warming)"));
    Serial.println();
  }
  if (t-pageAt>=PAGE_MS) { page=(page+1)%4; pageAt=t; }
  if (t-refreshAt<150) return;
  refreshAt=t;
  char buf[24];
  switch (page) {
    case 0:
      snprintf(buf,sizeof buf,"Noise p-p: %u",noise); line(0,buf);
      line(1,noiseHigh?"HIGH NOISE":"Noise normal"); break;
    case 1:
      snprintf(buf,sizeof buf,"MQ-135 raw: %u",air); line(0,buf);
      line(1,!airReady?"Sensor warming":airHigh?"Air warning":"Air below limit"); break;
    case 2:
      if (clockOk) {
        DateTime d=rtc.now();
        snprintf(buf,sizeof buf,"Date %04u-%02u-%02u",d.year(),d.month(),d.day()); line(0,buf);
        snprintf(buf,sizeof buf,"Time %02u:%02u:%02u",d.hour(),d.minute(),d.second()); line(1,buf);
      } else { line(0,"RTC not found"); line(1,"Check SDA/SCL"); }
      break;
    default:
      line(0,noiseHigh && airHigh?"NOISE + AIR":noiseHigh?"HIGH NOISE":airHigh?"AIR QUALITY":"Classroom");
      line(1,warning?"WARNING":airReady?"Normal":"Air warming up");
  }
}

Remix this project

Make it yours in one click

Open a full copy of this project in your own Schematik workspace, diagram, code, parts, and assembly steps included. Swap the sensor, add features, or redesign the whole thing with AI. The author's original stays untouched.

Open in Schematik