0% found this document useful (0 votes)
9 views2 pages

Code For 8.1: Setup Pinmode Serial Begin

This code configures an Arduino to read light intensity from an LDR sensor and control an LED based on the readings. The LED turns on when the light level is below 400, indicating darkness, and turns off in bright conditions. The readings are printed to the Serial Monitor with a 500 ms delay for stability.

Uploaded by

Rhob Legolâs
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
9 views2 pages

Code For 8.1: Setup Pinmode Serial Begin

This code configures an Arduino to read light intensity from an LDR sensor and control an LED based on the readings. The LED turns on when the light level is below 400, indicating darkness, and turns off in bright conditions. The readings are printed to the Serial Monitor with a 500 ms delay for stability.

Uploaded by

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

Code for 8.

1
int ldrPin = A0; // LDR analog input
int ledPin = 7; // LED output
int lightValue = 0;

void setup() {
pinMode(ledPin, OUTPUT);
Serial.begin(9600);
}

void loop() {
lightValue = analogRead(ldrPin); // read light level
Serial.println(lightValue);

if (lightValue < 400) { // dark


digitalWrite(ledPin, HIGH);
} else { // bright
digitalWrite(ledPin, LOW);
}

delay(500);
}
This code sets up an LDR sensor to measure light intensity and control an LED based on
the readings. The LDR is connected to analog pin A0, while the LED is connected to digital
pin 7. In the loop(), the Arduino reads the analog value from the LDR and prints it to the
Serial Monitor. If the light level is below 400 (meaning it’s dark), the LED is turned on;
otherwise, it’s turned off. The delay(500) adds a short pause between each reading to make
the output more stable and readable.

You might also like