14
Lab 8 Introduction

Write a program that will automatically control the brightness of a light based on the surrounding light level. Automatic Night Light

Embed Size (px)

Citation preview

Lab 8Introduction

Write a program that will automatically control the brightness of a light based on the surrounding light level.

Automatic Night Light

Diodes are “one-way” devices that only allow current to flow in one direction. An LED is a diode that emits light when sufficient current is flowing through it. Diodes are used in many, many applications such as:

• LED flashlights and light bulbs provide very bright light and use significantly less power than incandescent bulbs, last much longer than incandescent bulbs, and stay cool.

• Diodes are used in circuits to convert AC power to DC power (laptop chargers, phone chargers, appliances that run on dc …)

• LEDs are used in displays, signs, and traffic signals.

DIODES

When the positive side of a voltage source is applied to the anode (+) side of an LED, current will flow through the circuit and the LED will light up.

Light Emitting Diode (LED)

Anode (+) Anode (+)Cathode (-) Cathode (-)

When the positive side of a voltage source is applied to the cathode (-) side of an LED, current will not flow through the circuit and the LED will not light up.

CurrentFlows

No CurrentFlows

Analog Discovery DAQ

Analog OUT Channel:

The yellow wire labeled W1 and black ground wire labeled form an Analog OUT channel. OUT means out of the DAQ and applied to the circuit.

This output channel will be used to apply a voltage between 0 and 5V across the LED and 1 kΩ resistor.

Analog Discovery DAQ

Sample MATLAB Commands to Digilent:

DAQ.outputSingleScan(5)% Provides 5V across LED/Resistor

DAQ.outputSingleScan(2.5)% Provides 2.5V across LED/Resistor

• Photocells are sensors that detect the surrounding light level.

• The resistance of the photocell decreases as the surrounding light level increases.

• The photocells we will be using have a resistance of about 1 kΩ in bright light and a resistance of about 10 kΩ when it is completely dark.

Photocells

PHOTOCELLS

+VR_

Voltage Divider Rule:

In Bright Light:

In Complete Darkness:

Analog Discovery DAQAnalog IN Channels:

The two orange wires labeled 1+ and 1- form an Analog IN channel. IN means into the DAQ from hardware.

This input channel is our replacement for the multi meter. The orange wires will be placed across the 10 kΩ resistor to measure the voltage.

A smaller voltage reading for VR means it is darker around the photocellso we should make the LED brighter.

Analog Discovery DAQ

MATLAB Command to Read Voltage:

VoltageLevel = DAQ.inputSingleScan% Reads Voltage

Analog Discovery DAQTo apply a constant 5V supply across the photocell and 10 kΩ resistor, we will use the Red wire (V+) and the Black wire (GND)

MATLAB Command to turn on Power Supply:

DAQ.setPowerSupply('positive','on');

Complete Circuit

W1

V+

1+

1-

LED

Photocell

10kΩ resistor

1kΩ resistor

How the system works:• As the light level

decreases, the voltage measured between the photocell and the 10kΩ resistor decreases

• Your program will take the measured voltage and determine an appropriate voltage level to send to the LED

• The voltage output to the LED will cause it to illuminate at different levels

Measuredvoltage

Outputvoltage

Circuit

Pay close attention to the color code on the resistors. The 1 kΩ (Brown-Black-Red) should be connected in series with the LED. The 10 kΩ (Brown-Black-Orange) should be connected in series with the photocell.

The USB cable should fit very easily into the Digilent DAQ.

If it doesn’t fit easily, you may have it upside down.

Under no circumstances should you attempt to force it – ask a T.A. for assistance if needed!