Ampnics
Published © CERN-OHL2

Hardware Design with KiCAD+Grok3 AI

Air Quality Monitoring System—designed in KiCAD and powered by Grok AI! This hands-on project teaches you end-to-end hardware design.

IntermediateFull instructions provided5 hours422
Hardware Design with KiCAD+Grok3 AI

Things used in this project

Hardware components

ESP8266 ESP-12E
Espressif ESP8266 ESP-12E
×1

Software apps and online services

KiCad
KiCad
Twitter
Twitter

Story

Read more

Schematics

Hardware Design With KiCAD+Grok3

Download Schematic & Layout now!

Code

Firmware

C/C++
It is also generated by Grok 3
#include <ESP8266WiFi.h>
#include <WiFiClient.h>
#include <HTTPClient.h>
#include <Wire.h>
#include <Adafruit_GFX.h>
#include <Adafruit_SSD1306.h>

// OLED setup
#define SCREEN_WIDTH 128
#define SCREEN_HEIGHT 64
#define OLED_SDA 4  // GPIO4 (D2 on NodeMCU)
#define OLED_SCL 5  // GPIO5 (D1 on NodeMCU)
Adafruit_SSD1306 display(SCREEN_WIDTH, SCREEN_HEIGHT, &Wire, -1);

// Wi-Fi credentials
const char* ssid = "YOUR_WIFI_SSID";
const char* password = "YOUR_WIFI_PASSWORD";

// ThingSpeak setup
const char* thingSpeakHost = "api.thingspeak.com";
const String thingSpeakApiKey = "YOUR_THINGSPEAK_API_KEY";

// MQ135 setup
const int mq135Pin = A0; // Analog input pin for MQ135
float ppm = 0.0;

// Calibration constants for MQ135 (adjust based on datasheet and environment)
const float RLOAD = 10.0;  // Load resistor in kΩ (on MQ135 module)
const float RZERO = 76.63; // Sensor resistance in clean air (calibrate this)
const float PARA = 116.6020682; // From MQ135 datasheet
const float PARB = 2.769034857; // From MQ135 datasheet

void setup() {
  // Initialize Serial for debugging
  Serial.begin(115200);

  // Initialize OLED
  Wire.begin(OLED_SDA, OLED_SCL);
  if (!display.begin(SSD1306_SWITCHCAPVCC, 0x3C)) {
    Serial.println("OLED initialization failed!");
    for (;;);
  }
  display.clearDisplay();
  display.setTextSize(1);
  display.setTextColor(SSD1306_WHITE);
  display.setCursor(0, 0);
  display.println("Air Quality Monitor");
  display.display();

  // Connect to Wi-Fi
  WiFi.begin(ssid, password);
  display.setCursor(0, 20);
  display.println("Connecting to WiFi...");
  display.display();
  while (WiFi.status() != WL_CONNECTED) {
    delay(500);
    Serial.print(".");
  }
  Serial.println("\nWiFi connected");
  display.clearDisplay();
  display.setCursor(0, 0);
  display.println("WiFi Connected!");
  display.display();
  delay(1000);
}

void loop() {
  // Read MQ135 sensor value
  int sensorValue = analogRead(mq135Pin);
  float voltage = sensorValue * (3.3 / 1023.0); // Convert to voltage (ESP8266 ADC range)

  // Calculate resistance of MQ135
  float rSensor = ((3.3 * RLOAD) / voltage) - RLOAD;

  // Calculate PPM (based on MQ135 datasheet formula)
  ppm = PARA * pow((rSensor / RZERO), -PARB);

  // Display on OLED
  display.clearDisplay();
  display.setCursor(0, 0);
  display.println("Air Quality Monitor");
  display.setCursor(0, 20);
  display.print("PPM: ");
  display.print(ppm, 1);
  display.println(" ppm");
  if (ppm < 400) {
    display.println("Air: Good");
  } else if (ppm < 1000) {
    display.println("Air: Moderate");
  } else {
    display.println("Air: Poor");
  }
  display.display();

  // Send to ThingSpeak
  if (WiFi.status() == WL_CONNECTED) {
    HTTPClient http;
    String url = "http://api.thingspeak.com/update?api_key=";
    url += thingSpeakApiKey;
    url += "&field1=";
    url += String(ppm);
    http.begin(url);
    int httpCode = http.GET();
    if (httpCode > 0) {
      Serial.println("Data sent to ThingSpeak");
    } else {
      Serial.println("Failed to send data");
    }
    http.end();
  }

  // Debug output to Serial
  Serial.print("MQ135 Voltage: ");
  Serial.print(voltage);
  Serial.print("V, PPM: ");
  Serial.println(ppm);

  delay(30000); // Update every 30 seconds
}

Credits

Ampnics
1 project • 1 follower
We are shaping India’s #1 innovation hub, empowering students, hobbyists, engineers, and entrepreneurs!
Contact

Comments

Please log in or sign up to comment.