Download Lab 8 - Automatic 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

Electrical ballast wikipedia , lookup

History of electric power transmission wikipedia , lookup

Electrical substation wikipedia , lookup

Ohm's law wikipedia , lookup

Current source wikipedia , lookup

Metadyne wikipedia , lookup

Rectifier wikipedia , lookup

Triode wikipedia , lookup

Power MOSFET wikipedia , lookup

Power electronics wikipedia , lookup

Alternating current wikipedia , lookup

Immunity-aware programming wikipedia , lookup

Buck converter wikipedia , lookup

Surge protector wikipedia , lookup

Resistive opto-isolator wikipedia , lookup

Stray voltage wikipedia , lookup

Schmitt trigger wikipedia , lookup

Switched-mode power supply wikipedia , lookup

Voltage regulator wikipedia , lookup

Voltage optimisation wikipedia , lookup

Mains electricity wikipedia , lookup

Opto-isolator wikipedia , lookup

Transcript
Lab 8: Automatic Nightlight
In this lab, we will again be using the Digilent Analog Discovery DAQ device and your
knowledge of MATLAB to design a simple automatic nightlight (turns on and off automatically
and adjusts the brightness based on the surrounding light level).
This idea is similar to what you phone or computer may do when it adjusts the brightness of the
screen based on whether you are out in the sun or in a dimly lit room. When you are out in the
sun, the ambient light level is usually high, which causes the device to increase the brightness of
the screen so you can see it better. When you are in a dimly lit room, it can be very difficult to
read a screen if it is at full brightness, so the device may set the screen to a lower brightness
level. In our situation, we will be doing the opposite: making an LED brighter as the room gets
darker.
In order to accomplish these tasks, you will be required to use your knowledge of conditional
structures and loops. You will work in groups of three to design and test your system.
A. Building the Circuit
The circuit you must build for this lab is shown below. To construct it, you will need the
following items:
 1x Light Emitting Diode (LED)
 1x Photocell
 1x 1kΩ resistor
 1x 10kΩ resistor
 1x yellow connector wires
 2x orange connector wires
 1x black connector wire
 1x red connector wire
W1
V+
LED
1+
1-
Photocell
10kΩ
resistor
1kΩ
resistor
Notes:
 Just like the capacitors we used in lab 5, the LED has a polarity. Connect the longer lead
from the LED to the W1 connection and the shorter lead to the connection with the 1kΩ
resistor.
A possible breadboard layout is shown below:
B. Software Check for Digilent DAQ
Note: if you used your computer on Lab 5 and you have not uninstalled any software, you
can skip to step 5 to check MATLAB communication with the DAQ
1. Form teams of 3 students at your recitation tables making sure that at least one team member
does not have a MAC because the software does not run on a MAC.
2. Ask your T.A. to give you one of the Digilent Analog Discovery DAQs.
3. Hopefully, at least one of your team members installed the WaveForms software and the
MATLAB support package for the Digilent Analog Discovery last week for Engineering
Foundations. If not, have one team member (without a MAC computer) go to the Recitation
Folder on the Blackboard metasite and follow the instructions for the MATLAB Update
under Recitation 5.
4. Software Check #1: Use the USB cable to connect the Analog Discovery DAQ to the
computer that has the software installed. Run the Waveforms Software – it should be in a
folder called Digilent. If you get a message that no device was detected, then you failed
to install the Waveforms software correctly. Go back to Blackboard, Step 1 under the
Recitation 5: MATLAB Update and run the program: digilent.waveforms V2.5.4.exe to
install the drivers and software for the Digilent. If you installed everything correctly, you
should see the image below indicating the software is ready to go and is connected to the
Discovery DAQ.
5. Software Check #2: Assuming Software Check #1 worked, close the Digilent Waveforms
software program. Once the Waveforms software has been closed, type the following
command in MATLAB: >> clear all; d = daq.getDevices
If you get an output like this then you are good to go:
d =
digilent: Digilent Inc. Analog Discovery Kit Rev. C (Device ID:
'AD1')
Analog input subsystem supports:
-2.5 to +2.5 Volts,-25 to +25 Volts ranges
Rates from 0.1 to 1000000.0 scans/sec
2 channels ('1','2')
'Voltage' measurement type
Analog output subsystem supports:
-5.0 to +5.0 Volts range
Rates from 0.0 to 1000000.0 scans/sec
2 channels ('1','2')
'Voltage' measurement type
Properties, Methods, Events
If you get the message that No Data Acquisition Devices Are Available, then you have
not installed the MATLAB support package properly. Go back and repeat Step 2 in the
Recitation 5: MATLAB Update folder; that is, run the install called
digilentanalogdiscovery.mlpkginstall. Then try this MATLAB command once again:
>> clear all; d = daq.getDevices
NOTE: If you lose connectivity with the DAQ at any point, type clear all at the command
prompt. This will clear out the old session and allow you to start a new one.
C. Simple DAQ Input/Output Commands
1. Wire the circuit and connect to the Digilent DAQ following the diagrams shown in Part A.
2. Run the following commands by copying them into a script file and running it:
DAQ = daq.createSession('digilent');
measurement = DAQ.addAnalogInputChannel('ad1',1,'Voltage');
LED = DAQ.addAnalogOutputChannel('ad1',1,'Voltage');
DAQ.setPowerSupply('positive','on');
These commands will set up a new communication session with the DAQ device, add an
input channel to allow you to read the voltage measurement for the photocell, and add an
output channel to control up the LED. It will also turn on the power supply to provide
the necessary voltage for the photocell to run.
3. Execute the following line of code at the command prompt:
DAQ.outputSingleScan(5);
Record what happens to the LED – check you circuit:
4. Execute the following line of code at the command prompt:
DAQ.outputSingleScan(0);
Record what happens to the LED:
5. Execute the following line of code at the command prompt:
VoltageLevel = DAQ.inputSingleScan
Record the value of VoltageLevel – if it is zero (or negative), check your circuit:
Explanation:
The inputSingleScan and outputSingleScan commands allow you to read data from your
input lines or send signals out to your output lines, respectively. If you have multiple input lines,
the inputSingleScan command will return the values in a vector for each input line. If you
have multiple output lines, you will need to provide values for each line in order to use
outputSingleScan. However, as you saw, the voltage will remain at the level set until you
change the value again.
D. Nightlight Setup
The nightlight will function by progressively turning on the LED as the light level of the
surrounding environment decreases. In your circuit, as the ambient light level decreases, the
voltage you measure for the photocell portion of the circuit will also decrease. For this
system, we want to have 11 light levels (1 off level and 10 different levels of brightness when
turned on). Before we can create the code to do this, we first need to test our system to
determine the voltage range over which the photocell will vary.
1. Clear out all of your previous connections to the DAQ by typing:
>> clear all;
2. Run the code from step 2 of part C to establish a connection with the DAQ and create
your communication channels.
3. Use a single input scan to measure the voltage of the photocell when illuminated by the
light in the room. Record the value below and place the value as the minimum voltage
level for the 0V output level and as the maximum value for level 1 in the table below:
Voltage level of ambient light:
4. One of the group members will now need to place their fingers over the photocell,
covering as much of the device as possible. Use a single input scan to measure the
voltage of the photocell when dark. Record the value below and place the value as the
maximum voltage for the 5V output level and as the minimum voltage for level 9 in the
table below:
Voltage level of darkness:
5. Complete the following table to determine the voltage ranges for each of the different
light levels. Any voltage above your ambient light level should turn the LED off while
any voltage level less than your dark voltage level should be fully on. All other ranges
should be evenly spaced. You will also need to determine the output voltage levels for
the LED so that the On levels are evenly spaced between 2V and 5V.
Hint: There is a way that you can use only one column (Minimum Voltage Level or
Maximum Voltage Level) to set the output voltage level to the LED in your program. It
is not necessary to do it this way, but if you can figure it out, it will make your code
easier.
Level
Off
On – level 1
On – level 2
On – level 3
On – level 4
On – level 5
On – level 6
On – level 7
On – level 8
On – level 9
Fully On
Minimum Voltage
Level
Maximum Voltage
Level
Output Voltage to LED
0V
2.00V
5.00V
Describe how you determined the voltage ranges and output voltage levels:
E. Creating the Nightlight Code
Download the script Nightlight.m from Blackboard and complete the required sections using
the information from parts C and D. You will need to use a while loop to continuously take
voltage measurements from the photocell circuitry and determine at what level to set the
voltage of the LED. You should set the condition of the while loop such that if the voltage
level measured drops below 0.5V, the loop will terminate. This will allow you to gracefully
exit the script by disconnecting the wire from the 1+ terminal of the DAQ.
Notes:
 Use the DAQ.inputSingleScan and DAQ.outputSingleScan commands to read
your voltage measurements and to set the voltage level of the LED.
 You will need to have some type of conditional structure inside your loop to
determine at what level the LED voltage needs to be set. You should use the values
you determined in part D when creating your conditions.
When you have your nightlight working, demonstrate it to your TA.
Thought Question:
You may have noticed that as you changed the light level around the photocell, you could see
distinct changes in the brightness of the LED. Describe how you could make the transition
between levels of brightness smoother so that the changes in brightness were less noticeable:
To be turned in:
 Everyone should submit the m-file created during this lab activity, Nightlight.m, and a
copy of this lab report with the all calculations, measurements, and observations entered.
The team member who has this information should e-mail these documents to the other
members of his/her team.
 Please place the names of your team members in the header of your script file, at the
beginning of your Word document, and in the submission box.