Home · Academy · Robotics & Coding · Sensors and Actuators · Digital and Analog Signals

Digital and Analog Signals

Learn the difference between digital (on/off) and analog (continuous value) signals and the range of read values.

LESSON COMPASS

What will you use this page for?

Core idea

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.

Evidence to produce

Complete the page task with your own input, test conditions and reasoning.

Control trap

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…

Next connection

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.

Module sources: Python Tutorial · Arduino Learn

LevelBeginner
Age10–16
Duration30–45 min
PrerequisiteWhat Is an Actuator?
ContentStandard lesson · 1,713 words
Last updated

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:

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:

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

Putting the two side by side table
FeatureDigital signalAnalog signal
Number of values2 (0 / 1)Many across a range
Example sensorButton, touch sensorLight, temperature, sound, potentiometer
How the board reads itDirectly 0 or 1Via ADC, e.g. 0–1023
Everyday comparisonLight switchWater tap / dimmer

Mini activity

You do not need a board for this activity; paper and a pencil are enough.

  1. For each device below, write whether it produces a digital or analog signal:
  1. 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.
  2. 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

Review questions

  1. How does a digital input differ from an analogue input?
  2. Why does an analogue-to-digital converter have limited resolution?
  3. What is a threshold doing when an analogue reading becomes an on/off decision?
  4. How can electrical noise affect a value near the threshold?
  5. What is one reason a PWM output is not the same as a true steady analogue voltage?
  6. Which boundary tests should be used for a digital decision based on an analogue sensor?

Answers

  1. A digital input represents discrete states such as low/high, while an analogue input represents a measured range converted into a number.
  2. It maps a continuous input range into a finite number of codes determined by its bit depth.
  3. It defines which side of a chosen value is treated as false/true or off/on.
  4. Small fluctuations can make the state switch rapidly; filtering, hysteresis or confirmation time can stabilise it.
  5. PWM rapidly switches between fixed levels and relies on timing or filtering to create an average effect.
  6. Test just below, exactly at and just above the threshold, plus noisy readings around the boundary.

Lesson summary

Check your understanding

  1. How many different values can a digital signal take, and what names are they known by?
  2. Explain an analog signal in one sentence using the water tap comparison.
  3. What is the job of the ADC?
  4. If a light sensor gives values in the 0–1023 range, what does a value of 950 tell you about the surroundings?
  5. Why is a button a digital sensor rather than an analog one?

Answers

  1. 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.
  2. 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.
  3. 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.
  4. 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).
  5. 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.

Start QuizBack to Sensors and Actuators
QUESTION POOL

Reinforce this lesson with 10 questions

This lesson has a pool of 20 questions. Each attempt selects 10 and reshuffles the choices.