One-sentence summary
A sensor is the part that detects something in the environment — light, temperature, distance, sound or touch — and turns it into an electrical signal a circuit can read.
Why does it matter?
A robot or smart device cannot make good decisions without knowing what is happening around it. A street lamp that does not know it is dark cannot tell when to switch on, and a robot that does not know there is a wall ahead cannot tell when to stop.
Sensors are a device's sense organs. You detect light with your eyes, sound with your ears and heat with your hands. A device does the same job with sensors. Without them, a program only repeats the steps it memorised; it cannot react to the world.
In the previous lesson we built a warning circuit. In this lesson we will see how that circuit gains its eyes, ears and skin.
What exactly does a sensor do?
A comparison with human senses
Think of your own body as a robot:
- Your eyes work like a light sensor.
- Your ears work like a sound sensor.
- Your fingertips work like a touch sensor.
- Your skin works like a temperature sensor.
When you reach for a door, your skin tells your brain whether it is hot or cold. Your brain decides, and your arm moves. A sensor does the first step of this job: it collects information from the environment and sends it to the "brain" of the circuit (the microcontroller).
Turning physical information into a signal
Inside a sensor is a small part that reacts to a change in the outside world. In a light sensor (LDR), for example, the electrical resistance changes as more light falls on it. The circuit reads that change.
A sensor's job in one sentence is this: measure something physical and turn it into electricity. Temperature, distance, sound or light — in the end they all become an electrical signal so the circuit can understand them.
Common sensors
Light sensor (LDR)
- What it measures: The amount of light around it.
- How it works (simply): Its resistance drops as more light falls on it.
- Everyday example: Garden and street lamps that switch on by themselves when it gets dark. A phone that adjusts its screen brightness to the room also uses a light sensor.
Temperature sensor
- What it measures: The temperature of the air or a surface.
- How it works (simply): An element inside it changes its electrical behaviour as the temperature changes.
- Everyday example: Air conditioners and heaters measure the room temperature and stop once they reach the target. A fridge tracks its inside temperature the same way.
Distance sensor (ultrasonic)
- What it measures: How far away an object in front of it is.
- How it works (simply): It sends out a sound wave we cannot hear and measures how long the wave takes to come back. It is a little like how a bat finds its way in the dark.
- Everyday example: A car's parking sensor, which beeps faster as you get closer to a wall.
Sound sensor (microphone)
- What it measures: How loud the sound around it is.
- How it works (simply): It turns the vibration made by sound waves into an electrical signal.
- Everyday example: Lamps that switch on when you clap, or voice assistants that wake up when you say "Hey!"
Button
- What it measures: Whether it is being pressed or not.
- How it works (simply): Pressing it joins two metal contacts and closes the circuit.
- Everyday example: An elevator call button or the keys on a game controller. A button is the simplest sensor: it has only two states, pressed or not.
Information from a sensor becomes a number
A sensor does not say "very bright"; instead it sends a number to the circuit. This is a very important idea.
There are two kinds of output:
- On/off (digital): Like a button. Only two values:
0(not pressed) or1(pressed). - Graded (analog): Like a light sensor. For example a number between
0and1023, where0means very dark and1023means very bright.
The program reads this number and compares it with a threshold (a limit). As pseudocode:
light = read_light_sensor()
If light is less than 300
display "It got dark"
Otherwise
display "The room is bright"
The same idea in micro:bit-style code looks like this:
from microbit import *
while True:
light = display.read_light_level()
if light < 50:
display.show(Image.HEART) # show a heart in the dark
else:
display.clear()
sleep(200)
The form of the code may change; the idea is the same: read the sensor, compare the number with a limit, then decide.
Where the sensor sits in the sense–decide–act loop
Every smart device runs a loop that repeats over and over: sense, decide, act.
Repeat:
SENSE -> read information from the sensor
DECIDE -> compare the information with a rule
ACT -> drive an actuator (LED, motor, sound)
In this loop the sensor is the first link. Without a sensor, the "decide" step has no information to compare. Think of a line-following robot:
- Sense: A light sensor underneath reads whether the floor is black or white.
- Decide: Did it see the black line?
- Act: It steers the motors.
In the next lesson we will study the last step of this loop — the actuators that create movement. For now, keep this in mind: a sensor takes information in, and an actuator sends movement out.
Mini practice
Without writing code, plan a "sense–decide–act" design on paper. Your goal: a night light that switches on by itself when it gets dark.
Fill in this table:
| Step | What is used? | What does it do? |
|---|---|---|
| Sense | Light sensor | Turns the surrounding light into a number |
| Decide | ? | ? |
| Act | ? | ? |
Then write the decision as pseudocode:
light = read_light_sensor()
If light is less than ___
turn the LED ___
Otherwise
turn the LED ___
Fill the blanks with a threshold value you choose. If you set the limit too high, the lamp turns on even in daylight; too low, and it never turns on. Finding the right number by testing is a normal part of an engineer's work.
Common mistakes
Thinking the sensor makes the decision
A sensor does not decide; it only measures and sends a number. The program's rules make the decision. A sensor is like a thermometer: it tells you the temperature, but it does not open the window.
Forgetting the threshold value
If you do not compare the sensor's number with a limit, the program cannot know when to react. You should set a sensible threshold for every analog sensor.
Choosing the wrong sensor
Using a light sensor when you want to measure distance will not work. First answer "what do I want to measure?", then choose the sensor.
Ignoring the environment
A light sensor may read "dark" even in daytime because of a shadow falling on it. When you test a sensor, think about the real place where it will be used.
Safety note
- In this lesson use only low-voltage educational sources: a battery, USB, micro:bit or Arduino. Never touch mains electricity (a wall socket).
- When you connect a sensor, watch the connection direction (the polarity). A wrong connection can heat the sensor; if a part gets warm, cut the power at once.
- Do not hold sensors with wet hands, and keep the circuit away from water, food and drinks.
- Always make connections while the power is off, then switch it on.
- Do your first attempts together with an adult. If you are unsure about a connection, ask before trying it.
Lesson summary
- A sensor detects a physical piece of information from the environment and turns it into an electrical signal a circuit can read.
- Sensors are like a device's sense organs: they can measure light, temperature, distance, sound and touch.
- A sensor's output is a number; the program decides by comparing that number with a threshold.
- Some sensors, like a button, are digital (0/1); others, like a light sensor, give a graded (analog) value.
- The sensor is the first link in the "sense–decide–act" loop; actuators provide the movement.
Check questions
- What is a sensor's basic job?
- What physical information does a light sensor measure, and where is it used in everyday life?
- Give an example of a sensor that gives a digital (0/1) output.
- Why do we compare the number from a sensor with a threshold value?
- In the "sense–decide–act" loop, which step does the sensor belong to?
Answers
- To measure a physical piece of information from the environment (light, temperature, distance and so on) and turn it into an electrical signal a circuit can read.
- It measures the amount of light around it. Example: street lamps that switch on when it gets dark, or a phone's automatic screen-brightness setting.
- A button — it has only two states, pressed (1) or not pressed (0).
- So the program can decide when to react. The threshold lets us make a rule such as "when the number is below/above this, do that."
- The first step, the "sense" step. The sensor collects information; deciding and acting are the steps that follow.
Source and verification note
For “What Is a Sensor?”, verification focuses on whether the relationship between What exactly does a sensor do? and Turning physical information into a signal remains consistent across examples. Sensor readings can change with the model, supply voltage and environment. Thresholds in the lessons are therefore examples; a real project should use a measurement table and calibration.
Next lesson
What Is an Actuator? We will learn how a device moves in response to the information a sensor collects — that is, how LEDs, motors and sounds work.