System that control brightness when motion detected , automatic switching when dark and automatic cut off battery charging when full charged for solar street light.
When is a day and no! or! motion detected |
When is dark but no motion detected |
When is dark and motion detected |
CODES
#define LED_PIN 11
#define LDR_PIN A1
const int MOTION_SENSOR_PIN = 7; // Arduino pin connected to the OUTPUT pin of motion sensor
int motionStateCurrent = LOW; // current state of motion sensor's pin
int motionStatePrevious = LOW; // previous state of motion sensor's pin
void setup()
{
pinMode(LED_PIN, OUTPUT);
Serial.begin(9600); // initialize serial
pinMode(MOTION_SENSOR_PIN, INPUT); // set arduino pin to input mode
}
void loop()
{
int LDRValue = analogRead(LDR_PIN);
int brightness = LDRValue / 4;
//int brightness = map(LDRValue, 0, 1023, 0, 255);
analogWrite(LED_PIN, brightness);
motionStatePrevious = motionStateCurrent; // store old state
motionStateCurrent = digitalRead(MOTION_SENSOR_PIN); // read new state
if (motionStatePrevious == LOW && motionStateCurrent == HIGH) { // pin state change: LOW -> HIGH
Serial.println("Motion detected!");
if (int brightness = map(LDRValue, 0, 1023, 0, 255)) {
digitalWrite(LED_PIN,HIGH);
delay(5000);
digitalWrite(LED_PIN,LOW);
}
}
}
0 Comments