COMP 1045 Lab 4 - F24
COMP 1045 Lab 4 - F24
Circuit diagram: Today's lab will be using the photoresistor(light sensor). Create the diagram
below and paste the source code. Then open your serial monitor and change the light value to
check that the circuit works.
int lightPin = A1; //The light sensor is plugged into pin A1 of the Arduino.
int data = 0; //This will store the data from the sensor.
Level 3:Light meter Challenge– Write a program that will control 3 different LED's lights. Create
a program that meets the following criteria.
→ LED #1 Will turn on when light sensor is above 50% value
→ LED #2 will turn on when light sensor is above 30% value and below 60%
→ LED #3 will blink slowly when below 33% light value, and quickly when above 66% value
You can use map() function to determine the max/min values of your system.
Level 4: Develop a circuit that utilizes a light sensor to display binary numbers through a
sequence of 4 differently colored LEDs.
LED Configuration: Arrange 4 LEDs in a sequence from left to right. Each LED has a
corresponding binary value as follows: Far left LED: 8 , Next LED: 4, Next LED: 2, Far right
LED: 1 These values will be used to represent binary numbers.
Light Sensor Operation: Map the light sensor to values ranging from 0 to 15. As you adjust the
light sensor slider from its leftmost to its rightmost position, the LEDs should display the
corresponding binary value. For instance, if the light sensor reads a value equivalent to 5, the
LED pattern should be: OFF - ON - OFF - ON. Here, the ON LEDs have values of 4 and 1,
which add up to 5.
Use the following code to map the light sensor data: data = map(data, 6, 679, 0, 15); // map the
data value to the range 0-15
Extra challenge: Change your code in level 4 to convert the light sensor value into an array of
size 4, that will contain the binary representation of the number. If the light sensor = 6 your array
would be { 0,1,1,0}. Then pass the array to a function called lightsON(). In the function turn the
lights on or off using the array value. Ex: digitalWrite(farRightLight, array[0])
digitalWrite(farLeftLight, array[3])