Last active
February 17, 2017 12:41
-
-
Save richmarr/e31dd8a470b3753e78bb93b3c815d80c to your computer and use it in GitHub Desktop.
Arduino code my Dad wrote to automate his greenhouse lamps
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
int lightPin0 = 0; | |
int lightPin1 = 1; | |
int relayPin = 2; | |
int night = 1000; | |
int sunny = 8000; | |
float filter = 0.0; | |
void setup() { | |
pinMode(relayPin,OUTPUT); | |
Serial.begin(9600); | |
} | |
void loop() { | |
int r0 = analogRead(lightPin0); | |
int reading = analogRead(lightPin1); | |
// first order filter | |
filter = filter*0.9 + r0; | |
Serial.print("Raw "); | |
Serial.print(reading); | |
Serial.print(" Filtered "); | |
Serial.print(filter); | |
Serial.print(" Secondary "); | |
Serial.println(r0); | |
if (filter < night || filter > sunny) { | |
digitalWrite(relayPin, LOW); | |
} | |
else { | |
digitalWrite(relayPin, HIGH); | |
} | |
delay (1000); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
He wants to stop his seedlings from getting leggy so switches on lamps when the sky is gloomy