0% found this document useful (0 votes)
18 views3 pages

COMP 1045 Lab 4 - F24

The document outlines a lab exercise using a photoresistor with an Arduino, including circuit diagrams and source code for various levels of complexity. It provides instructions for creating a light meter that controls LEDs based on light sensor readings and includes challenges for binary representation using multiple LEDs. The final challenge involves modifying the code to use an array for binary representation and controlling the LEDs accordingly.

Uploaded by

fetat29455
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
18 views3 pages

COMP 1045 Lab 4 - F24

The document outlines a lab exercise using a photoresistor with an Arduino, including circuit diagrams and source code for various levels of complexity. It provides instructions for creating a light meter that controls LEDs based on light sensor readings and includes challenges for binary representation using multiple LEDs. The final challenge involves modifying the code to use an array for binary representation and controlling the LEDs accordingly.

Uploaded by

fetat29455
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 3

COMP 1045 Lab 4

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.

Level 1: Copy and run the following source code.

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.

void setup() { //The Setup function runs once.


Serial.begin(9600);
}

void loop() { //The loop function runs forever.


data = analogRead(lightPin); //Read the value from the light sensor and store it in the lightData
variable.
data = map(data,6,679,0,100); //map the data value to a percentage
Serial.print("Light value =");
Serial.println(data); //Print the data to the serial port.
delay(1000); //Wait 1 second (1000mS) before running again.
}
Level 2: Write a program that will turn on both the red LED (D12) and blue LED (D13) at the
same time when the sensor detects darkness.

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])

You might also like

pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy