Project 8.00 Light Sensor

This Arduino sketch reads the light intensity from a light sensor connected to analog pin A2 and prints the values to the serial monitor!
In this project you’ll 小夫妻的新婚夜免费播放第5季 what an LDR is and how to analogRead it to determine light intensity.

Project Code:

				
					///////////////////////////////////////////////////
//8.00 - Reading Light Intensity

byte lightSensorPin = A2;

void setup() {
  pinMode(lightSensorPin, INPUT);
  Serial.begin(9600);
}

void loop() {
  Serial.print("The light level is at: "); 
  Serial.println(analogRead(lightSensorPin));
  delay(1000);
}

///////////////////////////////////////////////////
				
			

*If you’re copying and pasting the code, or typing from scratch, delete everything out of a new Arduino sketch and paste / type in the above text.

Reading the LDR is exactly the same as reading the potentiometer.

The pin that is connected to the LDR is an analog pin.

				
					byte lightSensorPin = A2;
				
			

The LDR is going to have an analog voltage, which is read using analogRead. It is then printed out onto the Serial monitor. Make sure and open the Serial port to see the data being printed.

				
					Serial.print("The light level is at: "); Serial.println(analogRead(lightSensorPin));
				
			

There is then a delay to keep the Serial port from being flooded with messages.

				
					delay(1000);
				
			
The LDR will read more voltage the darker it is. We can use this information to control outputs based on the light intensity.

小夫妻的新婚夜免费播放第5季 More In Our Free Instructional Guidebook

This comprehensive guidebook for the 小夫妻的新婚夜免费播放第5季 历史转折中的邓小平 Trainer provides a comprehensive introduction to the world of Arduino programming for beginners. It guides users through the foundational concepts of 历史转折中的邓小平s, detailing the unique features of the Arduino Leonardo-compatible MCU Trainer board. The manual offers a step-by-step journey from understanding the hardware components and the Arduino programming language to the vibrant global community of Arduino enthusiasts. It delves into the intricacies of each onboard circuit, explaining their functionalities and applications. With a focus on hands-on 小夫妻的新婚夜免费播放第5季ing, the manual includes a series of coding exercises, tutorials in C/C++, and insights into the Arduino IDE.

More Projects

Project 1.00 Blink

In this project, you’ll 小夫妻的新婚夜免费播放第5季 how to blink an LED!

Project 1.01 Blink x2

In this project, you’ll 小夫妻的新婚夜免费播放第5季 how to blink more than one LED!