Advertisement
pleasedontcode

**Lamp Control** rev_02

Nov 12th, 2024
50
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. /********* Pleasedontcode.com **********
  2.  
  3.     Pleasedontcode thanks you for automatic code generation! Enjoy your code!
  4.  
  5.     - Terms and Conditions:
  6.     You have a non-exclusive, revocable, worldwide, royalty-free license
  7.     for personal and commercial use. Attribution is optional; modifications
  8.     are allowed, but you're responsible for code maintenance. We're not
  9.     liable for any loss or damage. For full terms,
  10.     please visit pleasedontcode.com/termsandconditions.
  11.  
  12.     - Project: **Lamp Control**
  13.     - Source Code NOT compiled for: Arduino Uno
  14.     - Source Code created on: 2024-11-13 00:45:21
  15.  
  16. ********* Pleasedontcode.com **********/
  17.  
  18. /****** SYSTEM REQUIREMENTS *****/
  19. /****** SYSTEM REQUIREMENT 1 *****/
  20.     /* Control an LED based on LDR sensor readings, */
  21.     /* displaying the light intensity on a LiquidCrystal */
  22.     /* I2C LCD. The LED will turn on in low light and off */
  23.     /* in bright conditions. */
  24. /****** SYSTEM REQUIREMENT 2 *****/
  25.     /* Control an LED based on LDR sensor readings, */
  26.     /* displaying light intensity on a LiquidCrystal I2C */
  27.     /* LCD. The LED activates in low light and */
  28.     /* deactivates in bright conditions, ensuring optimal */
  29.     /* visibility and energy efficiency. And using */
  30.     /* breadboard mini */
  31. /****** END SYSTEM REQUIREMENTS *****/
  32.  
  33. /* START CODE */
  34.  
  35. /****** DEFINITION OF LIBRARIES *****/
  36. #include <LiquidCrystal_I2C.h>  //https://github.com/marcoschwartz/LiquidCrystal_I2C
  37.  
  38. /****** FUNCTION PROTOTYPES *****/
  39. void setup(void);
  40. void loop(void);
  41.  
  42. /****** DEFINITION OF LIBRARIES CLASS INSTANCES*****/
  43. LiquidCrystal_I2C lcd(0x27, 16, 2); // Initialize the LCD with I2C address 0x27, 16 columns and 2 rows
  44.  
  45. int sensorPin = A0;
  46. int sensorValue = 0;
  47.  
  48. void setup(void)
  49. {
  50.     // Initialize serial communication
  51.     Serial.begin(9600);  
  52.     // Set pin 6 as an OUTPUT for the LED
  53.     pinMode(6, OUTPUT);  
  54.     // Initialize the LCD
  55.     lcd.begin();  
  56.     lcd.print("LDR Lampu Otomatis");  
  57.     lcd.setCursor(0, 1);  
  58.     lcd.print("Praktek Otodidak");  
  59.     delay(3000);  
  60.     lcd.clear();
  61. }  
  62.  
  63. void loop(void)
  64. {
  65.     // Read the sensor value from the LDR
  66.     sensorValue = analogRead(sensorPin);  
  67.     Serial.println(sensorValue);  
  68.     // Convert the sensor value to voltage
  69.     float voltage = sensorValue * (5.0 / 1023.0);  
  70.     Serial.println(voltage);  
  71.  
  72.     // Control the LED based on light intensity
  73.     if (voltage <= 1) {    
  74.         digitalWrite(6, HIGH); // Turn on the LED in low light
  75.         lcd.clear();    
  76.         lcd.setCursor(0, 0);    
  77.         lcd.print("Volt : ");    
  78.         lcd.print(voltage);    
  79.         lcd.setCursor(0, 1);    
  80.         lcd.print("Lampu Nyala"); // Display LED ON message
  81.         delay(1000);    
  82.     }
  83.     else if (voltage > 1) {    
  84.         digitalWrite(6, LOW); // Turn off the LED in bright light
  85.         lcd.clear();      
  86.         lcd.setCursor(0, 0);    
  87.         lcd.print("Volt : ");    
  88.         lcd.print(voltage);    
  89.         lcd.setCursor(0, 1);    
  90.         lcd.print("Lampu Mati"); // Display LED OFF message
  91.         delay(1000);    
  92.     }
  93. }
  94.  
  95. /* END CODE */
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement