What you will learn
  • Distinguish analog, digital and bus-connected sensors.
  • Build a light-dependent resistor divider.
  • Interpret raw ADC counts without inventing physical units.
  • Choose thresholds from measurements.
  • Use hysteresis to reduce output flicker.

Before you begin

Know breadboard rows, the D8 LED circuit and digital input states. This lesson builds a light sensor; other sensor types are explained without assuming interchangeable wiring.

A sensor measures something specific

A sensor converts a physical quantity into information a controller can use. A temperature sensor responds to a thermal condition; a light sensor responds to incoming light. Neither directly knows whether a room is comfortable or a plant is healthy. Those conclusions require context and a decision rule.

Sensors provide different interfaces. An analog device produces a changing voltage. A digital switch reports a state. A bus-connected sensor exchanges encoded measurements using a protocol such as I²C. A library can interpret those messages, but cannot make incorrect wiring safe.

For a first comparison, consider four families. A light-dependent resistor changes resistance with illumination. A temperature sensor may produce analog voltage or digital measurements. An ultrasonic distance module measures sound travel time. A passive infrared, or PIR, motion module responds to changes in infrared energy within its field of view; it is not a reliable person counter.

Every module needs its own voltage and pinout check. A familiar-looking three-pin connector does not guarantee the same order. We build only a passive light-dependent resistor circuit here, avoiding dependence on a particular active sensor library.

Create a voltage that follows light

A light-dependent resistor, or LDR, generally has lower resistance under brighter light. Two resistors in series create a voltage divider. We connect the LDR above a fixed 10 kΩ resistor so the midpoint rises as illumination increases.

Disconnect USB. Connect Uno 5V to one LDR lead. Connect the other LDR lead to A0 and one end of the 10 kΩ resistor. Connect the resistor’s other end to GND. An LDR is not polarized. Retain the output circuit D8 → 330 Ω → red LED anode, with cathode → GND.

The divider is powered from the same 5 V rail used as the normal ADC reference in this example. Its midpoint stays within that supply range. Do not connect an external sensor output above the board’s allowed input voltage. If you move the project to a Pi, this 5 V circuit must not feed Pi GPIO.

These readings will describe relative illumination for your particular LDR and placement. They are not lux, a physical unit of illumination, without appropriate sensor characterization and calibration.

PartRole
Arduino Uno R3, USB cableRead and report voltage
LDR and 10 kΩ resistorCreate changing divider voltage at A0
Red LED and 330 Ω resistorD8 indicator
Breadboard and jumpersMake the listed connections
5V → LDR → junction A0 → 10 kΩ resistor → GND

Read and act with two thresholds

Upload this Arduino C/C++ sketch and set Serial Monitor to 9600 baud. It uses built-in functions only. The initial thresholds demonstrate the mechanism; you must adjust them from your own light and dark observations.

cpp
bool lampOn = false;

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

void loop() {
  int lightReading = analogRead(A0);
  if (lightReading < 350) lampOn = true;
  if (lightReading > 450) lampOn = false;
  digitalWrite(8, lampOn ? HIGH : LOW);
  Serial.println(lightReading);
  delay(100);
}

analogRead(A0) returns a raw Uno R3 ADC count from 0 to 1023. Below 350 the indicator turns on; above 450 it turns off. Between the limits it keeps its previous state. This gap is hysteresis and prevents small variations around one boundary from repeatedly switching the output.

Expected result: Numbers change when you cover and uncover the LDR. With this divider orientation, brighter light usually raises the count. The LED turns on in sufficiently dark conditions after thresholds are calibrated.

Calibration is an experiment

Record at least ten readings with the sensor in its intended bright condition, then ten in its intended dark condition. Keep its position and your hand distance consistent. Notice the range, not only the average. A desk lamp moved closer changes the experiment.

Suppose dark readings cluster from 210 to 260 and bright readings from 700 to 760. Thresholds such as 350 and 450 lie between those observed ranges and leave a margin. Those example numbers are illustrative, not promised results for your components.

Now test an intermediate condition slowly. The LED should remain stable until one of the two limits is crossed. If bright and dark readings overlap, no threshold can perfectly distinguish them using that measurement alone. Improve sensor placement, change the lighting definition or choose another sensor instead of hiding the overlap.

Averaging several readings can reduce random variation, but it also delays a response and cannot repair a badly chosen measurement. Keep raw readings in your notebook so a smoothed graph does not conceal the original uncertainty.

Know what the measurement cannot prove

This is automatic control using explicit rules, not machine learning. A model trained from examples would be a different decision mechanism, and it would still need reliable input data. An inaccurate or poorly positioned sensor does not become accurate because its output passes through AI.

Temperature sensors need thermal contact and enough time to settle. Ultrasonic sensors can miss angled or absorbent surfaces. PIR modules need their documented startup time and may miss a stationary person. These limitations should appear beside a project’s success conditions, not after a surprising failure.

Our staged test is to check the unpowered divider, observe raw readings without judging the LED, choose thresholds and then verify the output. If A0 is always near an endpoint, inspect the junction and ground. If covering the LDR raises values, your divider may be reversed; either correct the wiring or reverse the interpretation consistently.

Use the Arduino analog and smoothing examples to extend measurement handling. The next motor lesson adds actuators, where a correct measurement can lead to physical movement and therefore requires more careful power planning.

Important terms

Sensor
A device that converts a physical quantity or event into a usable signal.
ADC
Analog-to-digital converter, which turns voltage into a finite numerical reading.
Voltage divider
Two series resistances with a measurable midpoint voltage.
Calibration
Relating a measurement to known conditions using observations.
Hysteresis
Different thresholds for entering and leaving a state.
Noise
Unwanted variation in a measurement.

Mini project: Calibrate a desk-light indicator

  1. Wire and inspect the divider with power disconnected.
  2. Record ten uncovered and ten covered readings.
  3. Choose separate on and off thresholds inside the gap between your observed ranges.
  4. Upload the adjusted sketch and test gradual changes.
  5. Finish when the recorded observations explain both thresholds and the LED switches predictably.

Common mistakes and debugging

  • Calling ADC counts lux: retain raw units until you have a valid calibration.
  • Copying thresholds from another room: measure the actual installation.
  • Assuming all modules share a voltage: check each exact sensor and breakout.
  • Using a single boundary despite flicker: add a justified hysteresis gap.

Independent challenge

Move the sensor near a window and compare its readings at two times of day. Explain whether your original definition of dark still matches the task.

Check your understanding: 10 questions

  1. What does an LDR change with light?

  2. Why do we need the fixed resistor?

  3. What range does analogRead normally return on Uno R3?

  4. What happens between the two thresholds?

  5. Is this threshold controller a trained ML model?

  6. In your own words, what does “Sensor” mean?

  7. In your own words, what does “ADC” mean?

  8. In your own words, what does “Voltage divider” mean?

  9. In your own words, what does “Calibration” mean?

  10. In your own words, what does “Hysteresis” mean?

Quiz answers

Reveal all 10 answers after your attempt
  1. Its electrical resistance.
  2. Together with the LDR it converts changing resistance into a measurable midpoint voltage.
  3. 0 through 1023.
  4. The indicator preserves its previous state.
  5. No. Its rules are explicitly programmed.
  6. A device that converts a physical quantity or event into a usable signal.
  7. Analog-to-digital converter, which turns voltage into a finite numerical reading.
  8. Two series resistances with a measurable midpoint voltage.
  9. Relating a measurement to known conditions using observations.
  10. Different thresholds for entering and leaving a state.

Summary

Useful sensor work begins with identifying the measured quantity, checking the interface and observing real data. A calibrated rule with hysteresis is a strong first control system.

Continue learning

ARD06 introduces servo and DC motors, including the separate power and drivers needed for movement.

Choose a connected learning path

Sources and further reading

Prepared 2026-09-18. Editorial draft; primary documentation consulted. Hardware build not bench-tested; code has not been executed on the reference board.