PMOD ALS Sensor demonstration

This demonstration shows how to use the PmodALS. You will also see how to plot a graph using matplotlib.

The PmodALS and a light source is required. E.g. cell phone flashlight.

The ambient light sensor is initialized and set to log a reading every 1 second. The sensor can be covered to reduce the light reading, and a light source can be used to increase the light reading

1. Use ALS read() to read the current room light

In [1]:
from pynq import Overlay

In [2]:
from pynq.iop import Pmod_ALS
from pynq.iop import PMODB

# ALS sensor is on PMODB
my_als = Pmod_ALS(PMODB)


2. Starting logging light once every second

In [3]:

3. Modifying the light

  • Decrease the light reading by covering the sensor
  • Increase the light by shining a flashlight on the device

Stop the logging whenever you are finished trying to change the sensor's value.

In [4]:
log = my_als.get_log()

4. Plot values over time

In [5]:
%matplotlib inline

import matplotlib.pyplot as plt
plt.plot(range(len(log)), log, 'ro')
plt.title('ALS Sensor log')
plt.axis([0, len(log), min(log), max(log)])

In [ ]: