ELECTRONICS
FLAME DETECTOR SENSOR
/*AUTO_ON_STREET_LIGHT
CREATED BY AMEYA ANGADI
LAST EDITED ON - 19/08/2021
THIS CODE IS AN EXAMPLE OF AN AUTO ON-OFF STREET LIGHT WHICH AUTOMATICALLY SWITCHES ON WHEN IT GETS DARK AND REMAINS ON UNTILL IT DETECTS ENOUGH LIGHT.
*/
#include <Servo.h>
Servo myservo;
const int greenpin = 12; // ledpin and lightpin are not changed throughout the process
const int ledpin = 13; // ledpin and lightpin are not changed throughout the process
const int lightpin = A2;
const int LIGHT = 10; // sets LIGHT value for light sensor
int pos = 0;
int ctr = 0;
void setup() {
Serial.begin(9600);
myservo.attach(8);
pinMode(ledpin, OUTPUT);
pinMode(greenpin, OUTPUT);
pinMode(lightpin, INPUT);
}
void loop() {
int lightsens = analogRead(lightpin); // reads analog data from light sensor
if (lightsens < LIGHT) {
digitalWrite(ledpin, LOW); //turns led on
digitalWrite(greenpin, HIGH); //turns led on
delay(150);
}
else {
digitalWrite(ledpin, HIGH);
digitalWrite(greenpin, LOW);
for (pos = 0; pos <= 180; pos += 1) { // goes from 0 degrees to 180 degrees
// in steps of 1 degree
myservo.write(pos); // tell servo to go to position in variable 'pos'
delay(15); // waits 15ms for the servo to reach the position
}
for (pos = 180; pos >= 0; pos -= 1) { // goes from 180 degrees to 0 degrees
myservo.write(pos); // tell servo to go to position in variable 'pos'
delay(15); // waits 15ms for the servo to reach the position
}
}
}