Turn Laser On/Off with a Push-button and Arduino Nano

Description: A KY-008 laser transmitter is turned ON/OFF with a push-button and an Arduino Nano.

 KY-008 Laser with Arduino Nano

Supplies:

1 – Breadboard 830 Points
1 – Arduino Nano
1 – Push-Button
1 – KY-008 Laser Transmitter   >> Link <<

Arduino Code:

int button = 4;
int laserPin = 3;
int status = false;

void setup(){

  pinMode(laserPin, OUTPUT);
  pinMode(button, INPUT_PULLUP);

}

void loop(){

  if (digitalRead(button) == true) {
  status = !status;
  digitalWrite(laserPin, status);

} 

  while(digitalRead(button) == true);
  delay(10);
  
}

Leave a Comment

+ 27 = 30