Skip to content
RoboLearn
Not completed

What is a sensor?

SensorsBeginner20 minRead a knob in the simulator ↓Before this: Arduino C++ basics

What you’ll learn

  • What a sensor does
  • The difference between digital and analog signals
  • How an Arduino reads each one

Sensors turn the world into numbers

A sensor measures something (light, distance, touch, tilt, temperature) and turns it into an electrical signal the controller can read. It’s the sense part of sense, think, act.

Digital signals: on or off

A digital signal has two states: HIGH (about 5 V on an UNO) or LOW (0 V). Buttons, bump switches and many obstacle modules are digital.

int state = digitalRead(2); // HIGH or LOW

Analog signals: anything in between

An analog signal can be any voltage in a range, like 0 to 5 V. Knobs (potentiometers), light sensors and some distance sensors are analog. The UNO’s analog pins A0–A5 measure the voltage and give a number from 0 to 1023:

Voltage on A0 analogRead(A0)
0 V 0
2.5 V about 512
5 V 1023
int raw = analogRead(A0); // 0–1023
float volts = raw * 5.0 / 1023.0; // back to volts

Common robot sensors

Sensor Measures Signal
Push button, bump switch Touch Digital
Potentiometer Knob position Analog
LDR (light-dependent resistor) Brightness Analog
IR line sensor Dark or light floor Digital or analog
Ultrasonic (HC-SR04) Distance Pulse timing
IMU (MPU6050) Tilt and rotation I²C (a data bus)
Encoder Wheel turns Pulses

Finished this lesson?