Skip to content

Instantly share code, notes, and snippets.

@richmarr
Last active February 17, 2017 12:41
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save richmarr/e31dd8a470b3753e78bb93b3c815d80c to your computer and use it in GitHub Desktop.
Save richmarr/e31dd8a470b3753e78bb93b3c815d80c to your computer and use it in GitHub Desktop.
Arduino code my Dad wrote to automate his greenhouse lamps
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);
}
@richmarr
Copy link
Author

Richard,

Here’s the entirety of my Arduino program. The print statements are just diagnostics one can view while it runs. Rather lacking in comments.

Two photo resistors as inputs, with a resistor each to make a voltage divider. One binary output that then drives a relay. Araldite on the bottom of the relay to insulate the 240V!

Dad

He wants to stop his seedlings from getting leggy so switches on lamps when the sky is gloomy

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment