Вы находитесь на странице: 1из 2

EKSKUL MEKATRONIKA MODUL 1a-LED dan LDR

A. LED Example code:


Schematic : int LED = 3; //pin for LED
int LDR = A0; //pin for LDR
int user_val = 500; //here we are defining the
threshold value for turning on lights

void setup() {
// put your setup code here, to run once:
pinMode(LED, OUTPUT); //Led is declared as
output
pinMode(LDR, INPUT); //Ldr is declared as
input
}

void loop() {
// put your main code here, to run repeatedly:
int LDR_val = analogRead(LDR); //Here we are
Example code: fetching the values from Ldr
if(LDR_val > user_val) //Here we are checking
int ledPin = 10; //sesuai dengan kabel yang
if the light intensity of room is lesser than our
terhubung pada pin arduino
requirment
void setup() {
{
pinMode(ledPin, OUTPUT);
digitalWrite(LED, HIGH); //Here we are turning
}
on LED.
void loop() {
}
digitalWrite(ledPin, HIGH);
else{
delay(1000);
digitalWrite(LED, LOW); //Here we are turning
digitalWrite(ledPin, LOW);
off LED
delay(1000);
}
}
delay(50); //delay is for stability purposes
}
B. LED dengan sensor LDR
Schematic : C. Modifikasi program
Modifikasilah program-program diatas sehingga
sesuai dengan lebutuhan.

D. Advance Project
Buatlah design lampu merah pertigaan jalan
menggunakan sensor LDR, misalnya keadaan
saat siang hari dan malam hari.

Вам также может понравиться