All lessons
🛰️Components 7 min read

Sensors

How electronics can feel light, heat, distance and movement.

In 10 seconds

  • Sensors turn the real world into numbers.
  • LDR = light, ultrasonic = distance, thermistor = heat.
  • Print readings with Serial before you build logic on them.

A sensor is any component that turns something physical into something electrical. Light becomes a voltage. Heat becomes a resistance. Distance becomes a length of time. Once the world has been converted into numbers, your Arduino can make decisions about it — and that is the moment a circuit stops being a toy and starts being a machine.

The three families of sensor

1. Analog sensors

These give a voltage that changes smoothly. A photoresistor gets less resistant in bright light, a TMP36 outputs a voltage that climbs with temperature, a potentiometer changes as you turn it. You read them with analogRead() and get a number from 0 to 1023. They are the easiest to start with because a single wire carries the answer.

2. Digital sensors

These answer a yes/no question. A PIR motion sensor outputs HIGH while it sees movement and LOW when the room is still. A tilt switch says whether it is upright. You read them with digitalRead() and treat them like a button that presses itself.

3. Communicating sensors

More advanced sensors have a small computer inside and send whole messages. A DHT11 sends temperature and humidity as digital data. An MPU-6050 accelerometer sends motion in three axes over a system called I2C. These usually need a library — code someone else wrote that handles the tricky conversation — so you can just write dht.readTemperature() and get a number.

Calibration: sensors are honest but not precise

Here is something that surprises new makers: two identical sensors rarely give identical readings. Manufacturing varies, temperature drifts, and your room is not the same as the tutorial author's room. So the first thing you do with any new sensor is look at it. Print the raw value to the Serial Monitor and watch how it changes as you cover it, warm it, or wave at it. Write down the value in the two situations you care about, then pick a threshold between them.

This one habit — read the sensor before you write the logic — will save you more time than any other tip on this site.

Sensors lie sometimes

Real signals are noisy. A distance sensor occasionally reports a wild number because the echo bounced off something odd. A light sensor jumps as a cloud passes. Good code expects this:

  • Average several readings instead of trusting one.
  • Ignore impossible values, such as a distance of 900 cm from a sensor that only reaches 400.
  • Add hysteresis — turn on at one level and off at a slightly different one, so a value hovering at the edge does not flicker.

Think of it like listening to a friend in a noisy room. You do not react to every sound; you wait until you are sure you heard something.

Quick quiz: Sensors

3 questions to check it stuck.

Take the quiz

Next lesson

⚙️ Motors

Keep learning

Ready to try it for real?

Reading is good. Wiring is better. Pick a project and put this to work.

Explore projects