Transcript Slide 1

Program Light Sensor in
Autonomous Mode
Available at: www.etcurr.com
Lesson 3.5 – Program Light Sensor in Autonomous Mode
Program Light Sensor in
Autonomous Mode






Performance Objective: Given the components of a
VEX robotics design system program a light sensor in
autonomous mode to have the robot travel full speed
forward when a lot of light is detected, but to move
slowly forward when there is little to no light detected.
Enabling Objectives:
explain the purpose of a light sensor
explain how a light sensor operates
draw a flow chart for using a light sensor
program a light sensor
Available at: www.etcurr.com
Lesson 3.5 – Program Light Sensor in Autonomous Mode
Light sensor




The light sensor enables a robot to detect light
Robots can be programmed to have a specific reaction
if a certain amount of light is detected because of the
analog input
The light sensor uses a cadmium sulfosolenide (CdS)
photoconductive photocell
The CdS photocell is a photo resistor, meaning that its
resistance value changes based on the amount of
incident light (The direct light that falls on the surface)
Available at: www.etcurr.com
Lesson 3.5 – Program Light Sensor in Autonomous Mode
Verify the sensor




Plug the sensor into an analog port
Open easyC and download the light
sensor test code
Move your hand over the light sensor to
see the change in value
The more light there is, the lower the
analog value
Available at: www.etcurr.com
Lesson 3.5 – Program Light Sensor in Autonomous Mode
Program the light sensor


Program a VEX robot equipped with a
light sensor to move forward quickly
when there is a lot of light in the room,
and move slowly when there is little or
no light in the room
Draw the flow chart of a program that
can complete the above task
Available at: www.etcurr.com
Lesson 3.5 – Program Light Sensor in Autonomous Mode
Program the light sensor



Open a new competition project and
configure the microcontroller for the
light sensor
Add a variable for the light sensor
Insert an appropriate driving mode block
into the operator tab
Available at: www.etcurr.com
Lesson 3.5 – Program Light Sensor in Autonomous Mode
Program the light sensor


Insert a while loop
where 1==1
Insert the get light
sensor value block
Available at: www.etcurr.com
Lesson 3.5 – Program Light Sensor in Autonomous Mode
Program the light sensor

Insert an If
statement to move
the robot forward
at full speed if the
light sensor value is
less than 50,
meaning there is a
lot of light
Available at: www.etcurr.com
Lesson 3.5 – Program Light Sensor in Autonomous Mode
Program the light sensor

Insert an Else-If
statement to
move the robot
forward slowly if
there is very little
to no light in the
room
Available at: www.etcurr.com
Lesson 3.5 – Program Light Sensor in Autonomous Mode
Test your code



Build and download your code
Run the code with the Competition
Switch Simulator
The robot should move forward quickly
with the lights on, and move forward
slowly when the lights are turned off
Available at: www.etcurr.com
Lesson 3.5 – Program Light Sensor in Autonomous Mode
Show it off!



If your code works, show it to your instructor
If the robot does not run correctly, go back
through the lesson and double check your
code
For more technical data on the light sensor
visit:
http://www.vexforum.com/wiki/index.php/Lig
ht_Sensor
Available at: www.etcurr.com
Lesson 3.5 – Program Light Sensor in Autonomous Mode