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 learn 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.

Learn More In Our Free Instructional Guidebook

This comprehensive guidebook for the 1st Maker Space Microcontroller Trainer provides a comprehensive introduction to the world of Arduino programming for beginners. It guides users through the foundational concepts of microcontrollers, 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 learning, 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 learn how to blink an LED!

Project 1.01 Blink x2

In this project, you’ll learn how to blink more than one LED!

Bri Wagner

Education Solution Specialist

Bri Wagner brings a bachelor’s degree in Elementary Education and nine years of classroom teaching experience to her role at 1st Maker Space. A former Teacher of the Year Award recipient, Bri is passionate about creating engaging, hands-on learning experiences that inspire student success. She understands the impact that innovative instruction and meaningful classroom resources can have on student achievement and is dedicated to partnering with educators to bring high-quality STEM solutions into classrooms. Bri is committed to empowering teachers and helping students develop the creativity, confidence, and problem-solving skills they need to thrive.