Arduino Laser Security System with Buzzer and LED | Example Code | English Subtitle
ฝัง
- เผยแพร่เมื่อ 20 ก.ย. 2024
- Arduino Laser Security System with Buzzer and LED | Example Code | English Subtitle
Code : code is on the comment below.
Facebook : / doit20-104218935882053
Please Subscribe my Channel. ThankYou!
// Pin configurations
const int transmitterPin = 10; // Pin connected to the laser transmitter
const int receiverPin = 11; // Pin connected to the receiver
const int ledPin = LED_BUILTIN; // Pin connected to the LED
void setup() {
// Initialize serial communication
Serial.begin(9600);
// Set transmitter pin as output
pinMode(transmitterPin, OUTPUT);
// Set receiver pin as input
pinMode(receiverPin, INPUT);
// Set LED pin as output
pinMode(ledPin, OUTPUT);
}
void loop() {
// Transmit laser signal
digitalWrite(transmitterPin, HIGH);
delay(10); // Adjust delay as needed
// Check receiver
int receiverState = digitalRead(receiverPin);
// If receiver receives the laser, turn on LED, otherwise turn it off
if (receiverState == HIGH) {
Serial.println("Laser detected!");
digitalWrite(ledPin, HIGH); // Turn on LED
} else {
Serial.println("No laser detected.");
digitalWrite(ledPin, LOW); // Turn off LED
}
// Delay before next loop iteration
delay(1000); // Adjust delay as needed
}