0% found this document useful (0 votes)
7 views1 page

LDR Senser Code

Uploaded by

rfid035
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as TXT, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
7 views1 page

LDR Senser Code

Uploaded by

rfid035
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as TXT, PDF, TXT or read online on Scribd
You are on page 1/ 1

int lightDigitalPin = 8;

int lightAnalogPin = A0;

bool lastLightState = HIGH;


int lastLightIntensity = 0;

void setup() {
Serial.begin(9600);

pinMode(lightDigitalPin, INPUT);
pinMode(LED_BUILTIN, OUTPUT);

int initialLightState = digitalRead(lightDigitalPin);


int initialLightIntensity = analogRead(lightAnalogPin);

if (initialLightState == LOW) {
Serial.println("Bright light detected!");
digitalWrite(LED_BUILTIN, HIGH);
} else {
Serial.println("Dim light or darkness detected.");
digitalWrite(LED_BUILTIN, LOW);
}

Serial.print("Initial Light Intensity: ");


Serial.println(initialLightIntensity);
}

void loop() {

int lightDetected = digitalRead(lightDigitalPin);


int lightIntensity = analogRead(lightAnalogPin);

if (lightDetected != lastLightState) {
lastLightState = lightDetected;

if (lightDetected == LOW) {
Serial.println("Bright light detected!");
digitalWrite(LED_BUILTIN, HIGH);
} else {
Serial.println("Dim light or darkness detected.");
digitalWrite(LED_BUILTIN, LOW);
}
}

if (lightIntensity != lastLightIntensity) {
if (lightIntensity > lastLightIntensity) {
Serial.print("Light intensity increasing: ");
} else {
Serial.print("Light intensity decreasing: ");
}

Serial.println(lightIntensity);
lastLightIntensity = lightIntensity;
}

delay(100);
}

You might also like

pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy