Advertisement
pleasedontcode

Arduino Automation rev_01

Jan 9th, 2024
179
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: Arduino Automation
  13.     - Source Code compiled for: Arduino Nano
  14.     - Source Code created on: 2024-01-09 22:09:43
  15.  
  16. ********* Pleasedontcode.com **********/
  17.  
  18. /****** SYSTEM REQUIREMENTS *****/
  19. /****** SYSTEM REQUIREMENT 1 *****/
  20.     /* eğer ldr sensörü Okunan ışık değeri 35'den küçük */
  21.     /* ise  led %20 parlaklıkla yansın bu durumda led */
  22.     /* yanıyorken harekeret sensöründen hareket */
  23.     /* algılanırsa parlaklık seviyesi %100 olsun eğer bu */
  24.     /* durumdayken hareket algılanmazsa led % 20 */
  25.     /* parlaklıkla yanm */
  26. /****** END SYSTEM REQUIREMENTS *****/
  27.  
  28. /****** DEFINITION OF LIBRARIES *****/
  29. #include <Arduino.h>
  30.  
  31. /****** FUNCTION PROTOTYPES *****/
  32. void setup(void);
  33. void loop(void);
  34.  
  35. /***** DEFINITION OF DIGITAL OUTPUT PINS *****/
  36. const uint8_t led_LED_PIN_D2 = 2;
  37. const uint8_t ldr_SENSOR_PIN_A0 = A0;
  38. const uint8_t motion_SENSOR_PIN_D3 = 3;
  39.  
  40. void setup(void)
  41. {
  42.   // put your setup code here, to run once:
  43.   pinMode(led_LED_PIN_D2, OUTPUT);
  44.   pinMode(ldr_SENSOR_PIN_A0, INPUT);
  45.   pinMode(motion_SENSOR_PIN_D3, INPUT);
  46. }
  47.  
  48. void loop(void)
  49. {
  50.   // put your main code here, to run repeatedly:
  51.  
  52.   // Read the light intensity from the LDR sensor
  53.   int lightIntensity = analogRead(ldr_SENSOR_PIN_A0);
  54.  
  55.   // Check if the light intensity is less than 35
  56.   if (lightIntensity < 35) {
  57.     // Set the LED brightness to 20%
  58.     analogWrite(led_LED_PIN_D2, 51);
  59.    
  60.     // Check if motion is detected by the motion sensor
  61.     if (digitalRead(motion_SENSOR_PIN_D3) == HIGH) {
  62.       // Set the LED brightness to 100%
  63.       analogWrite(led_LED_PIN_D2, 255);
  64.     }
  65.   }
  66.   else {
  67.     // Set the LED brightness to 20%
  68.     analogWrite(led_LED_PIN_D2, 51);
  69.   }
  70.  
  71.   // Add a delay to avoid continuous readings
  72.   delay(100);
  73. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement