Introduction

In this project, we're going to use the light sensor module included with the TINKERkit to control the brightness of the eight channel RGB LED strip using two different approaches:

  1. Set the number of ON LEDs as the measured light changes
  2. Set the brightness of all the LEDs as the measured light changes

Required Parts

The following parts are required for this project:

  • A TINKERplate attached to a preprogrammed Raspberry Pi
  • From a TINKERkit
    • Three male to female jumper wires
    • the light sensor module
    • the mini breadboard
    • the 74HCT125 IC chip
    • the 8 channel RGB LED module
    • seven male to male jumper wires

Steps

Assembly

Using the parts called out above, assemble the night light electronics as shown below. Use the three male to female wires to connect the light sensor to the Analog Input block on the left, and the seven male to male wires for the remaining connections to the IC and REG LED strip on the bottom part of the diagram.

Theory of Operation

The light sensor module consists of a light sensitive resistor in series with fixed resistor. When connected to the TINKERplate +5V and ground pins, the circuit looks like:

In the schematic above, R1 and FTR1 form a simple resistive divider with the voltage at the SIG output being equal to +5V*FTRI/(FTR1+R1). As the light intensity increases on the photoresistor, its resistance decreases which will result in a lower voltage reaching the SIG pin and the analog input.

Code 1

This code measures the voltage from the light sensor ten times per second, compares it to a high and low limit, then converts it to a value in the range of 0 to 1. This value is then used to scale the brightness of all of the RGB LEDs equally.

As you cover the sensor with your hand, the LED strip will gradually go from off to full white. You may also notice that when the LED strip gets very dim, only the green LEDs turn on - this is not a bug but the result of some round-off errors in the TINKERplate firmware. Note that the sensor and the LED strip should be optically isolated from each other - otherwise you'll create a feedback situtaion which will cause the LEDs to flash off and on.

Code 2

This version of the code controls the brighness of the LED strip by increasing the number of ON LEDs as the room gets darker.

The above programs can be downloaded from github by typing the following instructions on the command line:

  1. git clone https://github.com/pi-plates/TINKERplate-Projects.git
  2. cd TINKERplate-Projects
  3. python3 NIGHTlight1.py or python3 NIGHTlight2.py
Series Navigation<< Battery Tester IIUltrasonic Parking Assistant >>