Create a gist now

Instantly share code, notes, and snippets.

What would you like to do?
Laser Sensor
// Arduino Based Laser Sensor
// By Nillakash34
// nillakash34@gmail.com
// fb.com/nillakash34
int ledPin = 13; // choose the pin for the LED
int lasinput = A0; // Analog pin 0 will be called 'lasersensor'
int lasValue = 0;
void setup() {
pinMode(ledPin, OUTPUT); // declare LED as output
pinMode(lasinput, INPUT); // declare sensor as input
Serial.begin(9600); // Initialize serial communication at 9600 bits per second
}
void loop() {
lasValue = analogRead(lasinput); // Read the input on analog pin 0 (named 'lasersensor')
if(lasValue <= 500) {
digitalWrite(ledPin, HIGH); // Activate digital output pin 13-turn LED ON
delay(100);
digitalWrite(ledPin, LOW);
delay(100);
Serial.println("Laser Detected"); //Show in the Display"Laser Detected"
} else {
digitalWrite(ledPin, LOW); // turn LED OFF
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment