Sensors Explained: How Robots See and Feel
Sensors Explained
A sensor is a device that converts something physical — light, distance, temperature, motion, touch — into an electrical signal a microcontroller can read. Sensors are how a robot perceives the world; without them, it is blind and can only repeat fixed motions. In the sense–think–act loop from What is Robotics?, sensors handle the "sense" step.
There are two broad families of sensors you will meet constantly: analog and digital.
Analog vs Digital Sensors
- Analog sensors output a continuous range of voltage. A light sensor might output anything from near 0 V (dark) to near 5 V (bright). On an Arduino you read these with
analogRead(), which returns a number from 0 to 1023. - Digital sensors output only two states: HIGH or LOW (on or off). A simple touch button or a basic infrared obstacle sensor is digital. You read these with
digitalRead(), which returns HIGH or LOW.
Knowing which family a sensor belongs to tells you which command to use to read it.
Common Sensors for Beginners
- Ultrasonic distance sensor (HC-SR04): Measures distance by timing an echo, like a bat. Great for obstacle avoidance.
- Infrared (IR) sensors: Detect nearby objects or distinguish black from white lines — the heart of line-following robots.
- Light-dependent resistor (LDR): An analog sensor whose resistance changes with light, useful for "is it dark?" projects.
- Temperature sensors (e.g. LM35, DHT family): Report ambient temperature, often paired with humidity.
- PIR motion sensor: A digital sensor that fires HIGH when it detects movement, common in security and automation projects.
Reading an Analog Sensor
Here is how to read a light sensor (LDR) on analog pin A0 and print the value so you can watch it change. Open the Serial Monitor at 9600 baud to see the numbers.
// Read an analog sensor (e.g. an LDR) and print the value.
// Wire the sensor as a voltage divider into analog pin A0.
const int sensorPin = A0; // analog input pin
void setup() {
Serial.begin(9600); // start serial so we can see readings
}
void loop() {
int value = analogRead(sensorPin); // SENSE: returns 0..1023
Serial.print("Sensor value: ");
Serial.println(value); // print to Serial Monitor
// Simple decision based on the reading:
if (value < 300) {
Serial.println("It is dark.");
} else {
Serial.println("It is bright.");
}
delay(500); // read twice per second
}
Watching these numbers move as you cover and uncover the sensor teaches you how raw sensor data feels — which is the first step to acting on it.
Want to learn this properly?
Join the waitlist for our courses — beginner-friendly, project-first classes in Jalgaon.
Browse coursesReading a Digital Sensor
For a digital sensor such as a PIR motion detector wired to pin 2:
// Read a digital sensor (e.g. a PIR motion sensor) on pin 2.
const int pirPin = 2; // digital input
const int ledPin = 13; // on-board LED for feedback
void setup() {
pinMode(pirPin, INPUT); // sensor sends a signal in
pinMode(ledPin, OUTPUT); // LED is our output
Serial.begin(9600);
}
void loop() {
int motion = digitalRead(pirPin); // HIGH if motion detected
if (motion == HIGH) {
digitalWrite(ledPin, HIGH); // light up on motion
Serial.println("Motion detected!");
} else {
digitalWrite(ledPin, LOW);
}
delay(100);
}
Common Mistakes
- Using the wrong read command. Calling
digitalRead()on an analog-only signal (or vice-versa) gives meaningless results. Match the command to the sensor type. - Forgetting the ground connection. A sensor needs power, ground, and signal. Missing ground gives unstable or floating readings.
- Powering 3.3 V sensors with 5 V. Some sensors and boards run at 3.3 V. Feeding 5 V can damage them. Always check the datasheet voltage.
- Not calibrating. Raw thresholds vary with lighting and parts. Print values first, then choose thresholds for your actual environment.
- Ignoring sensor warm-up. Some sensors (like PIR) need a short settle time after power-on before readings are reliable.
FAQ
How many sensors can an Arduino read at once? Several. An Uno has 6 analog inputs and many digital pins, so you can combine multiple sensors in one robot.
Why does my analog reading jump around? Small fluctuations are normal. You can average several readings or add a small delay to smooth them.
Which sensor should a beginner try first? An ultrasonic distance sensor or an IR sensor — both are cheap, well-documented, and lead naturally to fun projects.
Put Sensors to Work
Once your robot can sense, the next step is making it move. Continue with Motors & Actuators Explained, then combine the two into real builds. For guided, project-based learning with a mentor, join the waitlist for the Robotics & Automation course at Infoplanet in Jalgaon.
Want to learn this properly?
Join the waitlist for our courses — beginner-friendly, project-first classes in Jalgaon.
Browse coursesFounder, Infoplanet
Atul Kabra founded Infoplanet in 2001 and has spent over two decades teaching programming — C, C++, Java, databases and more — to students across Maharashtra.
Related guides
Arduino for Beginners: A Complete Starter Guide
A friendly introduction to Arduino for complete beginners: what the board is, how a sketch runs, what hardware you need, and a fully explained first program that blinks an LED.
10 Arduino Project Ideas for Beginners
Ten practical Arduino project ideas for beginners, ordered roughly from easiest to most ambitious, each with the skills it teaches and the parts you need.
Setting Up the Arduino IDE (2.x): Step-by-Step
A step-by-step guide to installing the modern Arduino IDE 2.x, connecting your board, selecting the correct board and port, and uploading a first sketch to confirm everything works.
