Running LED Menggunakan Arduino Uno dan Sensor LDR

Pada jejak kali ini mencoba membuat pengaruh intensitas cahaya terdapat perubahan keluaran Arduino.

Rangkaian Running LED dengan Arduino Uno dan LDR

Alat dan bahan yang dibutuhkan untuk membuat sistem ini :

  • LDR
  • Arduino Uno
  • Resistor
  • LED
  • Kabel

List Program

int ldr=A0;//Set A0(Analog Input) for LDR.
int value=0;

void setup() {
Serial.begin(9600);
pinMode(8,OUTPUT);
pinMode(9,OUTPUT);
pinMode(10,OUTPUT);
pinMode(11,OUTPUT);
pinMode(12,OUTPUT);

}

void loop() {
value=analogRead(ldr);//Reads the Value of LDR(light).
Serial.println("LDR value is :");//Prints the value of LDR to Serial Monitor.
Serial.println(value);
if (value >= 5 && value < 50) {
digitalWrite(8, HIGH);
digitalWrite(9, LOW);
digitalWrite(10, LOW);
digitalWrite(11, LOW);
digitalWrite(12, LOW);
}
else if (value >= 50 && value < 100) {
digitalWrite(8, HIGH);
digitalWrite(9, HIGH);
digitalWrite(10, LOW);
digitalWrite(11, LOW);
digitalWrite(12, LOW);
}
else if (value >= 100 && value < 150) {
digitalWrite(8, HIGH);
digitalWrite(9, HIGH);
digitalWrite(10, HIGH);
digitalWrite(11, LOW);
digitalWrite(12, LOW);
}
else if (value >= 150 && value < 200) {
digitalWrite(8, HIGH);
digitalWrite(9, HIGH);
digitalWrite(10, HIGH);
digitalWrite(11, HIGH);
digitalWrite(12, LOW);
}
else if (value >= 200 ) {
digitalWrite(8, HIGH);
digitalWrite(9, HIGH);
digitalWrite(10, HIGH);
digitalWrite(11, HIGH);
digitalWrite(12, HIGH);
}
else {
digitalWrite(8, LOW);
digitalWrite(9, LOW);
digitalWrite(10, LOW);
digitalWrite(11, LOW);
digitalWrite(12, LOW);
}
delay(100);
}

 

Tinggalkan Balasan

Alamat email Anda tidak akan dipublikasikan.