Main Menu

Secondary Menu

Light Sensor

Introduction: Light Sensor

We will be making a light sensor. This inscrutable will teach you how to turn on and off a LED with the amount of ambient light in the room. This project will open up the world of microcontrollers. Microcontrollers are used in every integrated circuit that does not have a CPU. In order to complete this project, you will need some coding experience and be able to operate a breadboard. We will be using the PIC16f690 microcontroller to control our circuit. You will learn how to download all the operating software, and setup and execute your circuit with the PIC. If you are using a different microcontroller some of the steps will be different.

Download the most up-to-date environment on the machine EX: MPLAB XIDE 2.05

If you are using a PICkit2 download MPLAB XIDE 2.00

Follow the installment instructions

Step 2: Downloading Compilers and PICkit Operationg System

Once we have our coding environment we need something to check our code and download it onto our PIC; in order to do this we need to have a compiler. It is important that you have a compiler with the same number of bits as your PIC. If you do not know how many bits your PIC is, look at your data sheet. We will also need operating system for the PICkit3.

Step 3: Configuring the Sensor

In this step we will be finding out what voltage will be inputted to the ADC of our PIC microcontroller, and what that ADC value will be.

Finding the resistance of the photo resistor

Set up the mulitimeter to read resistance

Put the resistor in the breadboard and read the resistance.

It is important that in this step you have the same amount of light when you want to turn on the LED.

Read the resistance off the multi mentor. EX: 51k ohms

Clear the bread board

Step 4: Calculations

In this step we are going to figure out the voltage that the PIC is going to read, and calculate the correct ADC value for our code.

Calculate the voltage at the ADC

Using a voltage divider method we can solve for the voltage across the photo resistor

Look at picture above for calculation

Calculate the ADC value

We are using a 10 bit ADC, so n=10

Vreff=5V can be changed in the registry for the ADC conversions

Look at picture above for calculation

Step 5: Connecting the PICkit

In this step we will start the connection to the PICkit. It is important to get the pins correct in this step or you might break the PIC. Pleas double check your work with the attached PDF and the datasheet.

Put the PIC in the center of the breadboard

The notch is at the top of the PIC indicating that pin 1 is the first on to the left.

Attachments

Step 9: Exciting the Code of the Sensor

In this step we will be adding code to the PIC microcontroller to operate our circuit.

To run the project

Run > run main project

This will not compile and download if there is an error with your code or if there is a problem connecting to the PICkit.

Test you code

Turn the lights on and off or cover the photo resistor with your finger to turn the LED on and off.

You have created your first integrated circuit using the PIC microcontolller. Now that you have a general knowledge on coding a mircocontler, try making projects of your own. Integrated circuits using CMOS, BJT, and diodes will be a great place to start making more complicated designs. Microcontollers are in just about everything from shoes to cars to video game controllers to clocks; the list is endless. So just remember to play around with the technology and have fun. Thank you for completing my inscrutable.