Advertisement
gabbyshimoni

yardLampWithSensors

Nov 2nd, 2019
193
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 1.08 KB | None | 0 0
  1. #define potPinLight A1
  2. int potValueLight = 0;
  3. #define potPinTime A2
  4. int potValueTime = 0;
  5. #define ldrPin A0
  6. int ldrValue = 0;
  7. #define ledPin 8
  8. long lightDuration = 0;
  9.  
  10. void setup() {
  11.   pinMode(ledPin, OUTPUT);
  12.   pinMode(potPinLight, INPUT);
  13.   pinMode(potPinTime, INPUT);
  14.   pinMode(ldrPin, INPUT);
  15.   Serial.begin(9600);
  16.  
  17.   digitalWrite(ledPin, LOW);
  18. }
  19.  
  20. void loop() {
  21.   potValueLight = analogRead(potPinLight);
  22.   potValueTime  = analogRead(potPinTime);
  23.   ldrValue = analogRead(ldrPin);
  24.   Serial.print("ldr = "+String(ldrValue));
  25.   Serial.print("   pot Light = "+String(potValueLight));
  26.   Serial.println("      pot Time = "+String(potValueTime));
  27.  
  28.  
  29.   if (ldrValue > potValueLight) { // עוצמת האור בחוץ גבוהה מגבול הרגישות ולכן מכבים את הנורה
  30.     digitalWrite(ledPin, LOW);
  31.   }
  32.   else {
  33.     lightDuration = potValueTime * 30000L / 1023L;
  34.     Serial.print("   Light Duration =");
  35.     Serial.println(lightDuration);
  36.     digitalWrite(ledPin, HIGH);
  37.     delay(lightDuration);
  38.     digitalWrite(ledPin, LOW);
  39.   }
  40. delay(1000);
  41. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement