Download Creating a Night Light

Survey
yes no Was this document useful for you?
   Thank you for your participation!

* Your assessment is very important for improving the workof artificial intelligence, which forms the content of this project

Document related concepts

Stepper motor wikipedia , lookup

History of electric power transmission wikipedia , lookup

Islanding wikipedia , lookup

Variable-frequency drive wikipedia , lookup

Pulse-width modulation wikipedia , lookup

Three-phase electric power wikipedia , lookup

Memristor wikipedia , lookup

Rectifier wikipedia , lookup

Test probe wikipedia , lookup

P–n diode wikipedia , lookup

Photomultiplier wikipedia , lookup

Surge protector wikipedia , lookup

Voltage regulator wikipedia , lookup

Switched-mode power supply wikipedia , lookup

Stray voltage wikipedia , lookup

Power MOSFET wikipedia , lookup

Buck converter wikipedia , lookup

Triode wikipedia , lookup

Current source wikipedia , lookup

Alternating current wikipedia , lookup

Schmitt trigger wikipedia , lookup

Multimeter wikipedia , lookup

Voltage optimisation wikipedia , lookup

Electrical ballast wikipedia , lookup

Mains electricity wikipedia , lookup

Resistor wikipedia , lookup

Ohm's law wikipedia , lookup

Opto-isolator wikipedia , lookup

Resistive opto-isolator wikipedia , lookup

Transcript
Creating a Night Light using a Light Dependent Resistor and an LED
This tutorial will show you another way to control the brightness of an LED, instead of a
potentiometer, we will now use a photocell. A photocell is a component which changes its
resistance depending on how bright its surroundings are. By the end of this tutorial you will have
an LED which will turn on when it’s dark and then will turn off when exposed to light.
Part 1. Gathering Materials
For this tutorial, you’ll need the following parts:
•
•
•
•
A computer with the Arduino IDE installed and setup for the Sparkfun Redboard
1 x Light Dependent Resistor (photocell)
1 x LED
1 x 330 Ω resistor
• 1 x 10k Ω resistor
• 5 x 6” Jumper Wire
• 1 x breadboard
• 1 x Sparkfun Redboard
• 1 x USB (B) Cable
Part 2. Wiring the Components
Figure 1. Wiring Diagram for a Night Light
Wire the components as shown in Figure 1 with the Pin 3 connected to a 330 ohm
resistor, which then connects to the non-flat side of the LED, with the other side of the LED
connected to GND. The photocell works in a similar way, with 5V connected to a 10k ohm
resistor, which then connects to one side of the photocell. The other side of the photocell is then
connected to GND. The same row where the photocell and 10k ohm resistor meet will have a
pin that connects that to an analog input, in this case, A0. This creates a voltage divider that the
Arduino can then read.
Part 3. What is a Voltage Divider?
The 10k resistor and photocell produce a voltage divider. When a voltage is introduced
into a series combination of two or more resistor, it is divided between the resistors proportional
to their resistance. For example, if two resistors of equal resistance are connected in series at 5
volts, then where the two meet, the voltage will read 2.5V. For these two resistors, the equation
of the voltage that is present where they meet is as follows:
Where Vout is the voltage at the junction of the two resistors, R1 is the resistor that has
one end connected to power, R2 is the resistor that has one end connected to ground, and Vin
the voltage of the power connection, in this case 5V.
Lets take R1 to be a 10k ohm resistor, R2 to be 30k ohm resistor and Vin to be 5V.
Using the above equation results in Vout to be 1.25V. If this value were to be read by an analog
input by an Arduino, using the equation that relates voltage to the analog input introduced in the
previous tutorial: analog value = Input Voltage / 0.004888. This gives an analog value of 256.
For the Night Light application, R1 is 10k ohms and R2 varies depending on how bright it is near
the photocell with darkness being a high resistance (around 40k ohms) and bright having a low
resistance (around 4k ohms).
When read by the analog input of the Arduino, this correlates to a value of about 800 for
darkness and 300 for brightness.
Part 4. How Does a Photocell Work?
A photocell is a type of semiconductor, typically Cadmium Sulphide and takes advantage
of the photoconductive effect. In a normal conductor, as electrons pass through a material, the
material pushes back with some resistance and causes the electrons to lose energy in the form
of a lower voltage. With a semiconductor, certain conditions can cause it to have a low
resistance or high resistance. The photoconductive effect explains how, when exposed to light,
certain materials can put extra electrons into the material, lowering the resistance. That is
exactly what is going inside the photocell. The discovery of the photoconductive effect was
made in 1873 by Willoughby Smith with selenium rods by accident. Smith had been
experimenting with resistance of materials and had found that selenium rods gave consistent
resistance when inside the lab, but outside, depending on cloud cover and time of day, the
resistance varied wildly.
We will be taking advantage of both the photoconductive effect and the voltage divider
property of resistors to allow an Arduino to monitor the brightness levels in a room.
Part 5. Programming
void setup() {
//we will be using pin 3 to control the LED brightness
pinMode(3, OUTPUT);
//turn off the LED at the start of the program
digitalWrite(3, LOW);
}
void loop() {
/*
* If the photocell is covered, it will have
* a high resistance, causing A0 to read a large
* value. If it's larger than a preset value,
* then the photocell is dark and the LED
* will turn on.
*/
int photoReading = analogRead(A0);
//if its a high value, turn on the LED using digitalWrite
/*in this case, higher than 750
* we’ll use an if statement to check the values.
* an if statement works by checking the statement
* inside the parenthesis. If it’s true, then it executes
* the code inside the curly braces, if it’s false, then it
* skips that section of code and immediately goes to the line
* after the ending curly brace
* the else statement will execute only when the if statement
* is false
*/
if(photoReading > 750){
/*digitalWrite will put 5V on the pin
* specified if HIGH or 0V on the pin
* if LOW
*/
digitalWrite(3, HIGH);
}
else{
digitalWrite(3, LOW);
}
}
Part 6. Uploading the program and testing
Now try uploading the code to the Arduino. If the LED turns on without doing anything,
then the line of code that states “if(photoReading > 750){“ may need to be raised to a higher
value than 750 and then the code will need to be uploaded again.
Try covering the photocell with a piece of paper, you should observe that the LED turns
on when it is covered, and then turns off when it is uncovered.
This concludes the fourth tutorial, and you have now learned how to use a voltage
divider, a photocell and how to integrate if statements that do different things depending on the
inputs given. The next tutorial will cover how to “flip a coin” and do perform an action based on
the coin flip.
Happy Tinkering!