Tehtävä 5 — Esp32 Devkit C V4 simulation

An interactive Esp32 Devkit C V4 circuit simulation you can run free in your browser on Velxio, by kaktuspoika8.

Components

Sketch code

const int ledPin    = 32;   
const int sensorPin = 13;  
const int buttonPin = 22;

bool silenced = false;

void setup() {
  Serial.begin(115200);
  Serial.println("Press the button to silence the alarm.");

  pinMode(ledPin, OUTPUT);
  pinMode(sensorPin, INPUT);
  pinMode(buttonPin, INPUT_PULLUP);

  digitalWrite(ledPin, LOW);
}

void loop() {
  bool sensorOn      = digitalRead(sensorPin) == HIGH;
  bool buttonPressed = digitalRead(buttonPin) == LOW; 

  // Napin painaminen aktivoi sammutuksen
  if (buttonPressed) {
    silenced = true;
    digitalWrite(ledPin, LOW);
    Serial.println("Alarm stopped!");
  }

  // Jos sensori ei ole päällä / aktiivinen
  if (!sensorOn) {
    silenced = false;
  }

  // Kun sensori on päällä ja ei hiljennetty, se hälyttää.
  if (sensorOn && !silenced) {
    digitalWrite(ledPin, HIGH);
    Serial.println("ALARM!");
  }

  delay(50);
}

More projects by kaktuspoika8