int LedGelap = 12; // Set pin 12 as LED pin
int LedRedup = 11; // Set pin 11 as LED pin
int LedTerang = 10; // Set pin 10 as LED pin
int Sensor = A0; // Set pin A0 as Sensor pin
void setup() {
Serial.begin(9600); // initializing serial begin of Arduino Uno
pinMode(LedTerang, OUTPUT); // Set pin as output LED red
pinMode(LedRedup, OUTPUT); // Set pin as output LED yellow
pinMode(LedGelap, OUTPUT); // Set pin as output LED Green
pinMode(Sensor, INPUT); // Set pin as input Sensor
}
void loop() { // Set the Variable function
int SensorStatus = analogRead(Sensor); // SensorStatus reading digital data from Sensor
if(SensorStatus <= 306){ // If the movement on sensor less than 306
digitalWrite(LedGelap, LOW); // LED red will turn off
digitalWrite(LedRedup, LOW); // LED yellow will turn off
digitalWrite(LedTerang, HIGH); // LED green will turn off
Serial.print("Terang, Led Hidup : "); // Serial will print this
Serial.println(SensorStatus); // Serial will reading digital data from SensorStatus
}
else if(SensorStatus <= 512){ // If the movement on sensor less than 306
digitalWrite(LedGelap, LOW); // LED red will turn off
digitalWrite(LedRedup, HIGH); // LED yellow will turn on
digitalWrite(LedTerang, LOW); // LED green will turn off
Serial.print("Redup, Led Hidup : "); // Serial will print this
Serial.println(SensorStatus); // Serial will reading digital data from SensorStatus
}
else{
digitalWrite(LedGelap, HIGH); // LED red will turn on
digitalWrite(LedRedup, LOW); // LED yellow will turn off
digitalWrite(LedTerang, LOW); // LED green will turn off
Serial.print("Gelap, Led Hidup : "); // Serial will print this
Serial.println(SensorStatus); // Serial will reading digital data from SensorStatus
}
}