Lamp on off — Arduino Uno simulation

An interactive Arduino Uno circuit simulation you can run free in your browser on Velxio, by zeyctr.

Components

Sketch code

// Arduino Blink Example
const int TOUCHSENS = 3;
const int MIC = A1;
const int RELAY = 2;






void setup() {
  analogRead(A1);
  digitalWrite(2, LOW);
  pinMode(RELAY, OUTPUT);
  pinMode(TOUCHSENS, INPUT);
  pinMode(MIC, INPUT);
}

void loop() {
  int touchState = digitalRead(TOUCHSENS);

  int relayval = 0;

  bool led = false;
  
  if(led == true){
    digitalWrite(2, HIGH);
  };
  


  if (touchState == HIGH){
    relayval += 1;
    delay(20);
  }else{
    touchState = LOW;
  }
  if (relayval == 1){
      led = true;
  }else if (relayval > 2){
      led = false;
      relayval = 0;
  }


  delay(50);

}