/********* Pleasedontcode.com ********** Pleasedontcode thanks you for automatic code generation! Enjoy your code! - Terms and Conditions: You have a non-exclusive, revocable, worldwide, royalty-free license for personal and commercial use. Attribution is optional; modifications are allowed, but you're responsible for code maintenance. We're not liable for any loss or damage. For full terms, please visit pleasedontcode.com/termsandconditions. - Project: **Lamp Control** - Source Code NOT compiled for: Arduino Uno - Source Code created on: 2024-11-13 00:41:31 ********* Pleasedontcode.com **********/ /****** SYSTEM REQUIREMENTS *****/ /****** SYSTEM REQUIREMENT 1 *****/ /* Control an LED based on LDR sensor readings, */ /* displaying the light intensity on a LiquidCrystal */ /* I2C LCD. The LED will turn on in low light and off */ /* in bright conditions. */ /****** END SYSTEM REQUIREMENTS *****/ /* START CODE */ /****** DEFINITION OF LIBRARIES *****/ #include // https://github.com/marcoschwartz/LiquidCrystal_I2C /****** FUNCTION PROTOTYPES *****/ void setup(void); void loop(void); /****** DEFINITION OF LIBRARIES CLASS INSTANCES*****/ LiquidCrystal_I2C lcd(0x27, 16, 2); // Initialize the LCD with I2C address 0x27, 16 columns and 2 rows int sensorPin = A0; int sensorValue = 0; void setup(void) { // Initialize serial communication Serial.begin(9600); // Set pin 6 as an output for the LED pinMode(6, OUTPUT); // Initialize the LCD lcd.begin(); lcd.print("LDR Lampu Otomatis"); lcd.setCursor(0, 1); lcd.print("Praktek Otodidak"); delay(3000); lcd.clear(); } void loop(void) { // Read the sensor value from the LDR sensorValue = analogRead(sensorPin); Serial.println(sensorValue); // Convert the sensor value to voltage float voltage = sensorValue * (5.0 / 1023.0); Serial.println(voltage); // Control the LED based on light intensity if (voltage <= 1) { digitalWrite(6, HIGH); // Turn on the LED in low light lcd.clear(); lcd.setCursor(0, 0); lcd.print("Volt : "); lcd.print(voltage); lcd.setCursor(0, 1); lcd.print("Lampu Nyala"); delay(1000); } else { digitalWrite(6, LOW); // Turn off the LED in bright light lcd.clear(); lcd.setCursor(0, 0); lcd.print("Volt : "); lcd.print(voltage); lcd.setCursor(0, 1); lcd.print("Lampu Mati"); delay(1000); } } /* END CODE */