One-sentence summary
A digital signal carries only two values (on/off, 0/1), while an analog signal carries a continuous range of values between two ends; knowing which kind a sensor produces is the first step to reading it correctly.
Why does it matter?
A robot "senses" the world through sensors, but not every sensor speaks the same language. A button only says "pressed" or "not pressed"; that is two states. A light sensor can produce many values in between, such as "a bit dark," "medium," or "very bright."
If we mix up these two languages, the code will not behave as we expect. Reading a light sensor as only "on/off" throws away most of the information we have.
In this lesson we will get to know the two basic kinds of signal. In the previous lesson we saw how actuators (parts that create movement or output, such as motors, LEDs and buzzers) act on the world. Now we look the other way: in what form does information from the world reach the board?
Short definition: A digital signal takes only two values; an analog signal changes continuously across a range.
What a signal is, and its two kinds
A signal is information carried from one place to another. In robotics it is usually a voltage: a sensor measures a situation in the world and turns it into a voltage, and the board reads that voltage to understand the situation.
Digital signal: two states
A digital signal has only two values. We call them by different names, but they all describe the same idea:
- On / off
- 1 / 0
- High (HIGH) / low (LOW)
- Present / absent
Think of a light switch. It is either on or off; there is no "half on" position. A digital signal is the same: no in-between values, only two ends.
Everyday example 1 — A doorbell: The bell is either pressed or not. When you press it the circuit closes and it rings; when you let go it stops. That is exactly a digital signal: two states.
In robotics the most familiar digital sensor is a button. For it, the board usually reads something like this:
Read the button
If the value is 1 (pressed)
turn on the LED
Otherwise (0, not pressed)
turn off the LED
Analog signal: a continuous range
An analog signal has countless in-between values between the two ends. Not only "on" and "off," but "low," "medium," "high" and every shade between them.
Think of a water tap. It can be opened slowly from fully closed to fully open, with many positions in between: a thin flow, a medium flow, a strong flow. An analog signal changes continuously in the same way.
Everyday example 2 — A dimmer switch: Some lamp switches slowly increase the light as you turn them. It is not an "on/off" switch; it can give every brightness in between. This is a great example of analog behaviour.
Analog sensors in robotics include the light sensor (brightness), the temperature sensor, the sound sensor, and the potentiometer (a rotating knob). None of these gives a single "yes/no"; each produces a range.
How does the board read an analog value?
The processor inside a board works only with numbers, that is, with digital values. So how does it understand a continuously changing analog voltage?
ADC: the bridge from analog to digital
Inside the board there is a small circuit called an ADC, short for "Analog-to-Digital Converter." Its job is to measure the incoming analog voltage and give it a number.
We can compare this to a ruler. We have a stick of some continuous length; the ruler reads it and turns it into a number like "17 centimetres." The ADC does the same with the incoming voltage.
The value range: for example, 0–1023
On most educational boards, the ADC turns the voltage it reads into a number between 0 and 1023. Here:
- 0 represents the lowest voltage (usually 0 volts).
- 1023 represents the highest voltage (usually the board's operating voltage).
- Every number in between represents a value between the two.
So if a light sensor returns 0 the surroundings are very dark, 1023 means very bright, and 500 means medium brightness. (In some wiring this can be reversed; what matters is the logic of the range.)
Why exactly 1023? Because many ADCs store the value as a 10-digit binary number, and the largest number 10 digits can hold is 1023. You do not need to memorise this; the thing to remember is: an analog reading is not a single number but a point on a range.
The reading logic
When we read an analog sensor, we usually set a threshold (a boundary value):
Read the light sensor # a number between 0 and 1023 comes in
If the value is less than 300
display "It is dark"
turn on the lamp
Otherwise
display "It is bright enough"
turn off the lamp
Notice this: the sensor gives an analog range, but to make a decision we digitise it with a threshold. We do this very often in robotics: take a continuous measurement and reduce it to "is it below or above this boundary?"
Putting the two side by side
| Feature | Digital signal | Analog signal |
|---|---|---|
| Number of values | 2 (0 / 1) | Many across a range |
| Example sensor | Button, touch sensor | Light, temperature, sound, potentiometer |
| How the board reads it | Directly 0 or 1 | Via ADC, e.g. 0–1023 |
| Everyday comparison | Light switch | Water tap / dimmer |
Mini activity
You do not need a board for this activity; paper and a pencil are enough.
- For each device below, write whether it produces a digital or analog signal:
- Button
- Light sensor
- Door open/closed sensor (magnetic switch)
- Temperature sensor
- Rotating sound knob (potentiometer)
- Design a threshold scenario for a light sensor. Fill in the blank in "If the value is below ___, turn on the lamp" with a number from the 0–1023 range, and explain in one sentence why you chose it.
- Find one digital and one analog "signal" example in your home (a tap, a light switch, a dimmer) and write why it belongs to that group.
Some of the answers are in the "Answers" section below.
Common mistakes
Treating an analog sensor as on/off
If we read the 0–1023 value from a light sensor as only "is it 0 or 1," we throw away most of our information. We should read an analog sensor with an analog function.
Expecting an analog value from a button
A button is digital; it does not give an in-between value like "half pressed." Trying to read it with an analog command creates confusion.
Never adjusting the threshold
A single threshold may not be correct in every setting. The same number means something different in daytime and at night. A good project sets the threshold by measuring.
Assuming 0–1023 for every board
0–1023 is a common range but is not the same everywhere. Some boards use a different range, so check your own board's documentation.
Safety note
- This lesson works only with low-voltage, educational sources: a battery, USB, or a board like micro:bit or Arduino. Never take measurements from mains (wall socket) electricity.
- When connecting a sensor, do not exceed the voltage limit the board allows. The wrong voltage can damage the sensor and the board.
- Turn off the board's power while making connections; after plugging in the wires, check them and only then apply power.
- If you are also working with an actuator (motor, LED), remember the previous lesson's rules: keep fingers and hair away from moving parts, do not power a motor directly from the board's pins, and use a driver and a proper power source.
- If this is your first time with electronics, have an adult with you.
Review questions
- How does a digital input differ from an analogue input?
- Why does an analogue-to-digital converter have limited resolution?
- What is a threshold doing when an analogue reading becomes an on/off decision?
- How can electrical noise affect a value near the threshold?
- What is one reason a PWM output is not the same as a true steady analogue voltage?
- Which boundary tests should be used for a digital decision based on an analogue sensor?
Answers
- A digital input represents discrete states such as low/high, while an analogue input represents a measured range converted into a number.
- It maps a continuous input range into a finite number of codes determined by its bit depth.
- It defines which side of a chosen value is treated as false/true or off/on.
- Small fluctuations can make the state switch rapidly; filtering, hysteresis or confirmation time can stabilise it.
- PWM rapidly switches between fixed levels and relies on timing or filtering to create an average effect.
- Test just below, exactly at and just above the threshold, plus noisy readings around the boundary.
Lesson summary
- A signal is the carrying of information (usually a voltage), and it has two basic kinds.
- A digital signal carries only two values: on/off, 1/0; a button is an example.
- An analog signal carries a continuously changing range between two ends; light and temperature sensors are examples.
- The board turns an analog voltage into a number using an ADC (Analog-to-Digital Converter); on many educational boards this number is in the 0–1023 range.
- We usually digitise an analog measurement with a threshold in order to make a decision.
Check your understanding
- How many different values can a digital signal take, and what names are they known by?
- Explain an analog signal in one sentence using the water tap comparison.
- What is the job of the ADC?
- If a light sensor gives values in the 0–1023 range, what does a value of 950 tell you about the surroundings?
- Why is a button a digital sensor rather than an analog one?
Answers
- A digital signal takes only two values. They are known by names such as on/off, 1/0, or high (HIGH)/low (LOW); all describe the same two states.
- An analog signal carries values that change continuously between two ends, just as a water tap can take every position between fully closed and fully open.
- The ADC (Analog-to-Digital Converter) measures the continuous analog voltage from a sensor and gives it a number, so that the processor, which works only with numbers, can understand it.
- A value of 950 is close to the top of the range, so it tells you the surroundings are very bright (if the wiring is reversed the meaning flips too, but what matters is the closeness to the top end).
- A button produces only two states: pressed or not pressed. There is no in-between value like "half pressed," which is why it is digital.
Source and verification note
For “Digital and Analog Signals”, verification focuses on whether the relationship between What a signal is, and its two kinds and Analog signal: a continuous range 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
The Light Sensor: In this lesson we will apply the analog-reading idea we learned here with a real sensor; we will build a small circuit that measures the brightness of the surroundings and makes a decision based on it.