Embedded

You might also like

Download as pdf or txt
Download as pdf or txt
You are on page 1of 5

TECHNOLOGICAL INSTITUTE OF THE PHILIPPINES

363 P. CASAL ST., QUIAPO, MANILA

HANDS-ON ACTIVITYY:
TEMPERATURE SENSOR AND LDR SENSOR
CPE 400 – CPE41S2
EMBEDDED SYSTEM

TOLENTINO, DARELLE LUIS F.

ENGR. YUNEZA CLAIRE MORTOS


November 27, 2022
2. Using one LDR and three LEDs, make a program that would light based on three different
conditions:

• If the value of the LDR is between 200 and 150, the Green LED should light, and the other LEDs
off.
• Else if the value of the LDR is between 100 and 149, the Yellow LED should light, and the other
LEDs off.
• Else the Red LED should light and the other LEDs off.

Source Code:

const int ldrpin = A0; }


const int RedLed = 5; else if (ldrval >= ldrpin + 100 && ldrval <
ldrpin + 149 ) {
const int YellowLed = 4;
digitalWrite(GreenLed,LOW);
const int GreenLed = 3;
digitalWrite(YellowLed,HIGH);
int ldrval = 0;
digitalWrite(RedLed,LOW);
void setup()
}
{
else if (ldrval < ldrpin + 99) {
pinMode(ldrpin, INPUT);
digitalWrite(GreenLed,LOW);
pinMode(RedLed, OUTPUT);
digitalWrite(YellowLed,LOW);
pinMode(YellowLed, OUTPUT);
digitalWrite(RedLed,HIGH);
pinMode(GreenLed, OUTPUT);
}
Serial.begin(9600);
else if (ldrval >= ldrpin + 200 && ldrval <
}
ldrpin + 254) {
void loop()
digitalWrite(GreenLed,LOW);
{
digitalWrite(YellowLed,LOW);
int ldrval = analogRead(ldrpin);
digitalWrite(RedLed,HIGH);
ldrval/=4;
Serial.print("LDR VALUE: ");
if (ldrval >= ldrpin + 150 && ldrval < ldrpin
Serial.print(ldrval);
+ 200 ) {
Serial.print("\n-----------------------");
digitalWrite(GreenLed,HIGH);
Serial.println("");
digitalWrite(YellowLed,LOW);
delay(1000)’
digitalWrite(RedLed,LOW);
CIRCUIT:

OUTPUT:
TINCKERCAD LINK:
https://www.tinkercad.com/things/8pdSYy43ZH5-funky-
albar/editel?sharecode=vEfUALRoqeePz5hATr1bd6h3Mn1Wv03v6s1ZfASEcQI

You might also like