In this lesson students learn how to give their Arduino the ability to make decisions. Using a photoresistor as an input and two LEDs as outputs, students write an if/else statement that chooses which LED turns on based on how much light is hitting the sensor.

This is a milestone lesson:
• Students use a real sensor
• Convert its data into a number
• Compare that number to a threshold
• And trigger different actions based on a condition

By the end, the Arduino becomes responsive and interactive — it reacts to the environment, just like real smart devices.


Student Learning Goals

By the end of this lesson students will be able to
• Build a photoresistor + resistor input circuit
• Build two LED output circuits
• Use analogRead(A0) to read light levels
• Understand the purpose of if/else statements
• Write a complete decision-making sketch
• Change the threshold value to fit their classroom lighting
• Upload and test a working “light detector” program


Materials Needed

Arduino Uno boards
USB cables
Breadboards
Photoresistors
3 × 10k resistors
3 × LEDs
Jumper wires
Computers with Arduino IDE
Student notebooks


Teacher Preparation Notes

Before class
Build the complete circuit so you can model it step by step.
Test the photoresistor in your lighting to estimate the threshold range.

Students may be nervous adding multiple components.
Move slowly, pause often, and reassure them that wiring mistakes are normal and fixable.


Safety Notes

Unplug the Arduino when wiring.
LEDs must be placed in the correct direction (long leg to positive).
Photoresistor has no polarity — either direction is fine.
Keep liquids away from electronics.


Warm Up Activity

Ask students
Have you ever seen something that turns on automatically when it gets dark

Let them mention nightlights, street lights, garden lights, or phones adjusting brightness.

Explain
Today we are going to build a sensor-based decision system just like that.


Lesson Flow


**Step One

Review the Photoresistor**
Show the PPT slides describing photoresistors.

Explain warmly
More light → lower resistance
Less light → higher resistance
This is how the Arduino can “sense” light.


**Step Two

Review the Basic Sensor Circuit**
Show the wiring from the previous lesson.

Tell students they will extend this circuit today.


**Step Three

Build Today’s Full Circuit**
Show the PPT’s “Today we are going to build this” slide.

Guide students step by step:

1. Place the photoresistor


Either orientation is fine — that reduces anxiety.

2. Add the 10k resistor

Creates the voltage divider

3. Build the two LED circuits

LED 1 → resistor → ground
LED 2 → resistor → ground

Teacher reassurance
Students may mix up LED polarity — remind them long leg = positive.

4. Create a shared ground buss


Connect LED grounds + photoresistor ground here.

5. Connect the outputs

LED1 → pin 13
LED2 → pin 12

6. Complete the sensor connections

Photoresistor → 5V
Center of the photoresistor/resistor pair → A0

Pause often and check wiring calmly.


**Step Four

Start From Last Lesson’s Code**
Students begin with this (from PPT):

void setup(){
    Serial.begin(9600);
}
void loop(){
    Serial.println( analogRead(A0) );
    delay(250);
}

Have them upload and open Serial Monitor to confirm the sensor is reading correctly.


**Step Five

Introduce the IF / ELSE Structure**
Show the if/else slide.

Explain in gentle language
An if statement lets the Arduino make a choice.
• If the light is below a certain value → do action A
• If the light is above that value → do action B


**Step Six

Add LED Variables & Pin Modes**
Have students add:

int led01 = 13;
int led02 = 12;

Then update setup():

pinMode(led01, OUTPUT);
pinMode(led02, OUTPUT);

This prepares each LED to be controlled.


**Step Seven

Add the IF / ELSE Logic**
Use the PPT’s full example:

if ( analogRead(A0) < 500 ) {
    digitalWrite(led01, HIGH);
    digitalWrite(led02, LOW);
}
else {
    digitalWrite(led01, LOW);
    digitalWrite(led02, HIGH);
}

Explain
500 is our decision point.
Below 500 = darker → LED01 turns on
Above 500 = brighter → LED02 turns on

Teacher reassurance
Their room may require a different number — that’s okay.


**Step Eight

Upload and Test**
Have students upload the code.

Ask them to
• Cover the sensor
• Shine a light on it
• Block the light with their hand
• Slowly move their hand up and down

They should see one LED or the other turn on.

Celebrate this moment — the Arduino is now responding to the world.


**Step Nine

Adjust the Threshold**
Show the final PPT note:
“Change your number to match your room lights on and off.”

Encourage students to experiment with values
300
600
750
Let them discover what works best in your lighting conditions.

This helps them feel ownership over their code.


Teacher Notes for Each Slide

Photoresistor & resistor slides
Keep the vocabulary simple and calm.

Circuit build slides
Move slowly — pause after major wiring steps.

Serial monitor starter code
Make sure capitalization is exact (Serial.begin).

If/else explanation
Use real examples (nightlight, automatic headlights).

Decision logic slides
Explain the threshold in friendly, human terms.


Independent or Group Activity

Option A: Light-Level Calibrator
Students slowly adjust the threshold number until the LEDs switch at a moment they choose.

Option B: Two-Zone Light Detector
Students label LED01 “Dark Zone” and LED02 “Bright Zone.”

Option C: Build a Paper Shade
Students create a little paper hood that changes sensor readings and test the effect.


Vocabulary and Concepts

If Statement
A tool that lets the Arduino make a decision.

Else
What happens when the “if” is not true.

Threshold
The value used to compare sensor readings.

Analog Input
A smooth range of values (0–1023).

digitalWrite
Turns an output pin HIGH or LOW.


Wrap Up

Ask
Which LED turned on when you covered the sensor
How did changing the threshold change the behavior
What real devices use this kind of decision system

Affirm how impressive it is that students created an interactive smart circuit.


Exit Ticket

One
What does an if statement allow the Arduino to do

Two
What happened to your LEDs when the room got darker or brighter


Quiz

1. Multiple Choice
If analogRead(A0) is 200, which condition is true
A. A0 < 500
B. A0 > 900
C. Neither

2. Short Answer
What does else mean

3. Multiple Choice
Which pin numbers did we use for LEDs
A. 2 and 3
B. 12 and 13
C. A0 and A1

4. Short Answer
Why do we print analogRead(A0) to Serial Monitor

5. Short Answer
How did you find the right threshold for your classroom


Teacher Reflection

Were students comfortable wiring multiple components
Did they understand the if/else comparison
Was adjusting the threshold easy or confusing
Would a future lesson benefit from adding more sensor conditions