This page demonstrates using a light sensor as an analog input. However, the same process can be used for other analog input components on Adafruit IO such as the potentiometer.

Your microcontroller board has both digital and analog signal capabilities. Some pins are analog, some are digital, and some are capable of both. Check the Pinouts page in this guide for details about your board.

Analog signals are different from digital signals in that they can be any voltage and can vary continuously and smoothly between voltages. An analog signal is like a dimmer switch on a light, whereas a digital signal is like a simple on/off switch. 

Digital signals only can ever have two states, they are either are on (high logic level voltage like 3.3V) or off (low logic level voltage like 0V / ground).

By contrast, analog signals can be any voltage in-between on and off, such as 1.8V or 0.001V or 2.98V and so on.

Analog signals are continuous values which means they can be an infinite number of different voltages. Think of analog signals like a floating point or fractional number, they can smoothly transiting to any in-between value like 1.8V, 1.81V, 1.801V, 1.8001V, 1.80001V and so forth to infinity.

Many devices use analog signals, in particular sensors typically output an analog signal or voltage that varies based on something being sensed like light, heat, humidity, etc.

Analog to Digital Converter (ADC)

An analog-to-digital-converter, or ADC, is the key to reading analog signals and voltages with a microcontroller. An ADC is a device that reads the voltage of an analog signal and converts it into a digital, or numeric, value. The microcontroller can’t read analog signals directly, so the analog signal is first converted into a numeric value by the ADC. 

The black line below shows a digital signal over time, and the red line shows the converted analog signal over the same amount of time.

Once that analog signal has been converted by the ADC, the microcontroller can use those digital values any way you like!

Light Sensor

A light sensor (also known as a CdS cell, light-dependent resistor, or photoresistor) detects light. They change their resistive value (in ohms, Ω) depending on how much light shines into the photocell. 

When a light sensor is exposed to more light, the resistance decreases. When it is exposed to less light, the resistance increases. 

By using a light sensor wired in a specific way (as a voltage divider), we can turn resistance into voltage. That change is then read by your board's Analog-to-Digital converter and sent to Adafruit IO.

Where is the Light Sensor on my board?

There is an ambient light sensor on the side, which points through to the front.

Create a Light Sensor Component

On the device page, click the New Component (or "+") button to open the component picker.

Search for the component name by entering light into the text box on the component picker, the list of components should update as soon as you stop typing.

Filtering and searching for components

WipperSnapper supports such a large number of components we added filtering!
Try searching for various keywords, like:

  • component names: aht20servobuzzerbutton, relay, etc
  • sensor types: lighttemperaturepressurehumidity, etc
  • interface: i2cuartds18x20pin, etc (also I2C addresses e.g. 0x44)
  • vendor: AdafruitASAIRInfineonBosch, Honeywell, Sensirion, etc

We’ve also added product and documentation links to every component, follow the links beneath the component descriptions to be taken to the appropriate product page or Learn-Guide.

Select the Light Sensor from the list of results to go to the component configuration page.

There will be a back button if you select the wrong component, and you can use the Edit component icon (⚙️) on the device page to update the component configuration in the future.

The name and pin for the light sensor on your board are automatically selected. The Period determines how frequently the light sensor's value will be checked and sent to Adafruit IO. Set it to check the light sensor value every 30 seconds.

Click Create Component.

The device page shows a new light sensor component. The value of this component will change every 30 seconds.

Light Sensor Usage

To test the light sensor, try covering the light sensor with a piece of paper. Navigate to the feed page by clicking the graph icon on the top right corner of the light sensor component.

On the light sensor feed page, you'll be able to observe a graph of the light sensor values as they change over time.

This guide was first published on Feb 26, 2019. It was last updated on Jun 21, 2024.

This page (Analog Input (Light Sensor)) was last updated on Apr 09, 2024.

Text editor powered by tinymce.