[go: up one dir, main page]

0% found this document useful (0 votes)
7 views5 pages

PROGRAMMING FINALS

Uploaded by

Dorothy Cadungog
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)
7 views5 pages

PROGRAMMING FINALS

Uploaded by

Dorothy Cadungog
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/ 5

ICT III.

Connect the other leg of the photoresistor


WHAT IS A LIGHT SENSOR? to the A0 (analog 0) pin of the Arduino
• Light sensors detect the amount of light and board
vary its electrical properties based on the IV. Add the LED. Attach a 220 ohms resistor
amount of illumination. on its negative leg, then connect it to
ground
• Light sensors are commonly known as
V. Connect the positive leg of the LED to
“Photoelectric Devices” or “Photo Sensors”
any of the input pins of the Arduino
because it converts light energy (photons) into
Board (except 0 and 1)
electricity (electrons).

a) Set the int first


• One type of light sensor is the Light
Dependent Resistor (LDR), known by many int sensor = A0;
as photoresistor or photoconductor.
Int LED = 2;
• Photoresistors are light-sensitive variable
resistors whose resistance decreases as light
intensity increases, allowing more electrical b) The setup:
conduction.
void setup(){
APPLICATION OF LIGHT SENSORS pinMode (sensor, INPUT); //Sets A0 as an
input
• LDRs are inexpensive, widely available
sensors used in applications like streetlights pinMode (LED, OUTPUT); // Sets pin 3 as
and solar lamps to detect light and activate an output
when needed.
}
• LDRs are common in gadgets but lack
c) The loop:
accuracy, with inconsistent behavior even
within the same batch. Their low sensitivity
void loop() {
makes them unsuitable for light intensity
measurements.
int ligthRead = analogRead(A0);
The Program:
if (lightRead > 500){

digitalWrite (LED, HIGH);

else{
digitalWrite (LED, LOW);

I. Add power to our breadboard


II. Add the 10K ohms resistor and the
Photoresistor
Example:
ICT
 Write a program for an emergency light sensor
with the following conditions:

 When there are ambient light, a GREEN light


should turn on, but when there is no light, the
GREEN light should turn off and a RED light
should turn on along with the Emergency light
(YELLOW LED)
TEMPERATURE INDICATORS
ICT
WHAT IS TEMPERATURE?

• Temperature indicates how hot or cold an


environment is. While people often debate
what qualifies as "room temperature," using
temperature sensors provides an accurate
measurement of the environment's
temperature.

TEMPERATURE AND ITS CONVERSION

• Temperature is the degree of hotness in a • These temperature sensors can only take up
substance. DC power supply that is in between 2.7 - 5.5
• The SI (Systeme Internationale) or the V, so direct connection of a 9V battery can be
standard unit of temperature in the dangerous.
International System of Units is kelvin. • Voltage output is directly proportional to the
• However, Celsius (centigrade) is the most Celsius temperature. Its range is from -40 deg
commonly used temperature unit around the C up to +125 deg C.
world.

Formulas to convert analog voltage


• Temperature Sensors are devices that detects reading into temperature
the changes in temperature and converts it to a
signal that can be understood either by an • Voltage at pin in milliVolts = (reading from
observer or device. ADC) * (5000/1024) This formula converts
the number 0-1023 from the ADC into 0-
TMP36 5000mV (= 5V)
• If you're using a 3.3V Arduino, you'll want to
• The TMP36 sensor, a low-voltage, analog,
use this formula: Voltage at pin in milliVolts
precision centigrade temperature sensor.
= (reading from ADC) * (3300/1024) This
Unlike photoresistors, it does not act as a
formula converts the number 0-1023 from the
resistor, so temperature values are read by
ADC into 0-3300mV (= 3.3V)
connecting its output pin directly to an analog
• Then, to convert millivolts into temperature,
pin.
use this formula: Centigrade temperature =
[(analog voltage in mV) - 500] / 10
BUILDING THE CODE
ICT • Then use the equation that converts reading
into a 0 t0 5 true voltage value
Create variables • Use the formula that converts true voltage
value into degrees Celsius
Name the TMP36 sensor as tempPin and
assigned it to analog pin A0 of your Arduino
board
• Name the Red LED as redled and assigned it
to digital pin 7 of your Arduino board
• Name the Green LED as greenled and
assigned it to digital pin 6 of your Arduino
board
• Name the Blue LED as blueled and assigned it
to digital pin 5 of your Arduino board
SEND DATA FROM YOUR ARDUINO
BOARD TO SERIAL MONITOR WINDOW

• Use Serial.print() function


• Use Serial.println() function to print the
data into the next line
• Use delay(1000) to read the temperature
every 1 second
Set variables either
inputs or outputs

• Use void setup() function


• Configure redled, greenled and blueled as an
output using pinMode
• Use Serial.begin() function to initialize the
port and set communication speed Setup indicator lights
• Set 9600 as a baud rate, this will let you
transfer 10 characters per second • Create a conditional statement for each
indicator light
• Assigned temperature range for each indicator
light.
• Close the loop

Create Loop

• Use void loop() function


• Declare 3 floating-points variable
• Use analogRead() to read a 0 to 1023 value
ICT

You might also like