Chicken Coop notes
Features
|
POA
|
LDR Code when sun is directly over head open coop door, when light is 0, close door.
use this to determine LDR values:
int analogPin = 3; // potentiometer wiper (middle terminal) connected to analog pin 3
// outside leads to ground and +5V int val = 0; // variable to store the value read void setup() { Serial.begin(9600); // setup serial
}
void loop()
{ val = analogRead(analogPin); // read the input pin Serial.println(val); // debug value } |
General Idea:
int RaiseDoor(5); // A5
int LowerDoor(6); // A6
boolean doorup = false; //
int dusk = 500 // will adjust once I have some reference numbers
int LDRE = analogRead(1);
int LDRW = analogRead(0);
void setup()
{
pinMode(RaiseDoor, OUTPUT);
pinMode(LowerDoor, OUTPUT);
}
void Loop() //check door
{
if (LDRE == LDRW && doorup == false);
{
digitalWrite(RaiseDoor, HIGH);
delay(10000);
doorup = true;
digitalWrite(RaiseDoor, LOW);
}
else if (LDRW > dusk && doorup == true);
{
digitalWrite(lowerdoor, HIGH);
delay10;
doorup = false;
digitalWrite(lowerdoor, LOW);
}
}
CODE:
int LDRW = 0; //analog pin to which LDR is connected, here we set it to 0 so it means A0
int LDRE = 1;
int LDRValue = 0; //that’s a variable to store LDR values
int light_sensitivity = 500; //This is the approx value of light surrounding your LDR
void setup()
{
Serial.begin(9600); //start the serial monitor with 9600 buad
pinMode(13, OUTPUT); //we mostly use13 because there is already a built in yellow LED in arduino which shows output when 13 pin is enabled
}
void loop()
{
LDRValue = analogRead(LDR); //reads the ldr’s value through LDR which we have set to Analog input 0 “A0″
Serial.println(LDRValue); //prints the LDR values to serial monitor
delay(50); //This is the speed by which LDR sends value to arduino
if (LDRValue < light_sensitivity)
{
digitalWrite(13, HIGH);
}
else
{
digitalWrite(13, LOW);
}
}
No comments:
Post a Comment