Doomsday Command Center (Earthquake + Lightning + Weather) — Arduino Mega simulation

An interactive Arduino Mega circuit simulation you can run free in your browser on Velxio, by tareq-neoaz.

Components

Sketch code

#include <SPI.h>
#include <Adafruit_GFX.h>
#include <Adafruit_ILI9341.h>
#include <DHT.h>
#include <Wire.h> 
#include <Servo.h> 

// --- PINS ---
#define TFT_CS   53
#define TFT_DC   48
#define TFT_RST  49
Adafruit_ILI9341 tft = Adafruit_ILI9341(TFT_CS, TFT_DC, TFT_RST);

#define DHT_PIN 33
DHT dht(DHT_PIN, DHT22);

#define SEISMIC_PIN A0 
#define BUTTON_PIN  23 

#define BUZZER_PIN 11
#define SERVO_PIN 10

const uint8_t AS3935 = 0x03;

Servo blastDoor; 

bool isEmergency = false;
bool isMinorAlert = false; 
String emergencyType = "";
unsigned long lastBlink = 0;
bool blinkState = false;

void setup() {
  Serial.begin(115200);
  
  pinMode(SEISMIC_PIN, INPUT); 
  pinMode(BUTTON_PIN, INPUT_PULLUP);
  pinMode(BUZZER_PIN, OUTPUT);
  
  dht.begin();
  Wire.begin(); 
  
  blastDoor.attach(SERVO_PIN);
  blastDoor.write(90); 
  
  tft.begin();
  tft.setRotation(1); 
  tft.fillScreen(ILI9341_BLACK);
  
  drawSecureScreen();
}

uint8_t readReg(uint8_t reg) {
  Wire.beginTransmission(AS3935);
  Wire.write(reg);
  Wire.endTransmission();
  Wire.requestFrom((int)AS3935, 1);
  return Wire.available() ? Wire.read() : 0;
}

void drawSecureScreen() {
  tft.fillScreen(ILI9341_BLACK);
  tft.fillRect(0, 0, 320, 40, ILI9341_DARKGREEN);
  tft.setTextColor(ILI9341_WHITE);
  tft.setTextSize(3);
  tft.setCursor(10, 10);
  tft.print("COMMAND CENTER");
  
  tft.setTextColor(ILI9341_GREEN);
  tft.setTextSize(2);
  tft.setCursor(20, 60);
  tft.print("STATUS: SECURE");
  
  tft.setTextColor(ILI9341_WHITE);
  tft.setCursor(20, 110);
  tft.print("TEMP: -- C");
  
  tft.setCursor(20, 150);
  tft.print("SEISMIC: STABLE");
  
  tft.setCursor(20, 190);
  tft.print("LIGHTNING: -- km");
}

void drawMinorAlertScreen(String type) {
  tft.fillScreen(ILI9341_BLACK);
  tft.fillRect(0, 0, 320, 40, ILI9341_YELLOW);
  tft.setTextColor(ILI9341_BLACK); 
  tft.setTextSize(3);
  tft.setCursor(10, 10);
  tft.print("WARNING LATCHED");
  
  tft.setTextColor(ILI9341_YELLOW);
  tft.setTextSize(2);
  tft.setCursor(20, 70);
  tft.print(type);
  
  tft.setTextColor(ILI9341_WHITE);
  tft.setCursor(20, 120);
  tft.print("PREDICTING MAIN QUAKE...");
}

void triggerEmergency(String type) {
  if (!isEmergency) {
    isEmergency = true;
    isMinorAlert = false; // Overrides the yellow screen
    emergencyType = type;
    Serial.print("!!! EMERGENCY !!! -> ");
    Serial.println(type);
    tone(BUZZER_PIN, 1500); 
    blastDoor.write(0); 
    tft.fillScreen(ILI9341_BLACK); 
  }
}

void drawEmergencyScreen() {
  if (millis() - lastBlink > 250) {
    lastBlink = millis();
    blinkState = !blinkState;
    
    if (blinkState) {
      tft.fillRect(10, 30, 300, 150, ILI9341_RED);
      tft.setTextColor(ILI9341_WHITE);
    } else {
      tft.fillRect(10, 30, 300, 150, ILI9341_BLACK);
      tft.setTextColor(ILI9341_RED);
    }
    
    tft.setTextSize(3);
    tft.setCursor(20, 40);
    tft.print("WARNING!");
    
    tft.setTextSize(2);
    tft.setCursor(20, 90);
    tft.print(emergencyType);
    
    tft.setTextS

More projects by tareq-neoaz