Categories
TUTORIALS

Using an LED bar graph to indicate sensor readings

This tutorial will guide you through creating an LED bar graph that responds to data collected by a sensor, and produces a visual representation of the data.

The example demonstrated above uses a photo resistor to determine the brightness of the surroundings. A photo resistor is a sensor that responds to changes in light by sensing the amount of light and emitting (/allowing to pass through) a corresponding amount of voltage that is read using the analog pin (A0).

In this tutorial, the resulting data (via A0) corresponds to the number of bars that are ON or OFF in the bar graph (for example, 0 bars = absolute darkness; ~3-5 bars = dim room; ~6-8 = bright room; 10 bars = 100 percent brightness).

YOU WILL NEED:

PREPARING YOUR CIRCUIT:

  1. Attach the Bar Graph LED to the center of the breadboard
  2. Connect a red wire from 5V to +
  3. Connect a black wire from GND to –
  4. Attach 10 wires to the bread board, in each pin next to the right side of the Bar Graph LED. Connect these wires to Arduino pins 2-11 , maintaining order (e.g. pin 11 connects to the bottom of the LED, while pin 2 is the top)
  5. On the opposite side of the Bar Graph LED, attach 10 330OHM resistors that connect to – (grounded)
  6. Place the photo resistor to the left of the breadboard; this should also connect to – on one leg and A0 on the other leg.
  7. Attach a 10k resistor that connects to the analog leg of the photo resistor. Using the resistor and a wire, connect this path to +
  8. As you prepare your breadboard, trace the path of the circuit ensuring each LED has a corresponding connection to the arduino and a 330OHM resistor that connects to ground (GND), and ensure that the photoresistor connects to both – and +, and A0

THE CIRCUIT DIAGRAM:

Before uploading your code, ensure that your board looks similar to the photos below.

*Note: for easier identification, wires are color coded based their connections: black wires connect to GND; red wires connect to 5V; the white wire connects to the analog (A0), and orange wires connect to the arduino pins.

 

 

THE CODE:

 

Thank you for visiting, using, and sharing this code!

 

*Note: This tutorial serves to provide an introduction and boost familiarity with the equipment and coding framework that can be adapted for other sensors using the bar graph LED. For the purposes the final project required for CPLN571, this project will ultimately be adapted to respond to an ultrasonic sensor (SEN-13959 ROHS).

Leave a Reply

Your email address will not be published. Required fields are marked *