Bright or Not?

In this project we will use the Adafruit Starter Pack for Windows 10 IoT Core on Raspberry Pi 2 components to make a speaking light sensor.  This will show how to use an MCP3008 Analog Digital Converter (ADC) chip to interface the Pi2 to three analog components.  Two variable resistors (potentiometers) and one CdS photocell.bright or not

Hardware setup

Connect the Raspberry Pi2 to the breadboard and the other components as per the Fritzing diagram below.

Note: While setting up the circuit, make sure your MCP3008 chip is oriented correctly. The chip has a half-moon shape marker along with a dot on one side. This should be oriented as shown in the diagram below.


If you have a pair of headphones with a 1/8″ jack or a set of powered speakers with a 1/8″ jack you can connect them to the Pi2 audio output jack to hear the prompts from the speech system.



You can download the code starting project from and we will lead you through the addition of the code needed to talk to the web service and get your pin on the map. What map?

Open up “Lesson_204\StartSolution\Lesson_204.sln and open the mainpage.xaml.cs file.

We have filled in a few methods as a starting point for you in this solution. If you want to jump ahead you can find a solution with all the code completed at:”Lesson_204\FullSolution\Lesson_204.sln”

Add the following lines at the top of the MainPage class.

 // Use for configuration of the MCP3008 class voltage formula
        const float ReferenceVoltage = 5.0F;

        // Values for which channels we will be using from the ADC chip
        const byte LowPotentiometerADCChannel = 0;
        const byte HighPotentiometerADCChannel = 1;
        const byte CDSADCChannel = 2;

        // Some strings to let us know the current state.
        const string JustRightLightString = "Ah, just right";
        const string LowLightString = "I need a light";
        const string HighLightString = "I need to wear shades";

        // Some internal state information
        enum eState { unknown, JustRight, TooBright, TooDark};
        eState CurrentState = eState.unknown;

        // Our ADC Chip class
        MCP3008 mcp3008 = new MCP3008(ReferenceVoltage);

        // The Windows Speech API interface
        private SpeechSynthesizer synthesizer;

        // A timer to control how often we check the ADC values.
        public Timer timer;

schematic bright or not

Now add these lines to the MainPage constructor to setup the windows speech synthesizer and the ADC chip.

 // Create a new SpeechSynthesizer instance for later use.
 synthesizer = new SpeechSynthesizer();

 // Initialize the ADC chip for use

Now add these lines to the OnNavigatedTo method.  This will setup a timer callback which will call our code once per second on a different thread.

For more detail: Bright or Not?

About The Author

Scroll to Top
Read previous post:
These tiny batteries can be charged in seconds and last for a week
These tiny batteries can be charged in seconds and last for a week

Battery anxiety is a modern day problem for many of us. Mobile phone and wearable technologies are getting developed rapidly,...