i have a project that will open/close blinds based on the amount of light coming through a window. the ide keeps returning a ‘else’ without a previous ‘if’ error. here’s the code:
///// the purpose of this program is to open shades when its sunny out and close them when its not. there will be a 5 minute delay between photocell
///// readings. if the initial read and the delay read are the same, the shades will respectively be opened/closed.
int sensorPin0 = A0; // select the input pin for the primary photocell
int sensorPin1 = A1; // select the input pin for the secondary photocell
int openPin = 12; // select the pin for relay(open)
int closePin = 11; // select the pin for relay(close)
int sensorValue0 = 0; // variable to store the value coming from the primary photocell
int sensorValue1 = 0; // variable to store the value coming from the secondary photocell
int sensorValue2 = 0; // variable to compare the value coming from the primary photocell
int sensorValue3 = 0; // variable to compare the value coming from the secondary photocell
int openPoint = 400; // variable for the point at which the shades will open
int closePoint = 900; // variable for the point at which the shades will close
void setup() {
pinMode(openPin, OUTPUT);
pinMode(closePin, OUTPUT);
}
void loop() {
sensorValue0 = analogRead(sensorPin0); // read primary photocells and assign value to sensorValue0:
sensorValue1 = analogRead(sensorPin1); // read secondary photocells and assign value to sensorValue1:
delay(5000); // wait for 5 minutes:
sensorValue2 = analogRead(sensorPin0); // read primary photocells and assign value to sensorValue2:
sensorValue3 = analogRead(sensorPin1); // read secondary photocells and assign value to sensorValue3:
// close sequence
else if ((sensorValue0 / sensorValue1) > 1.1 &&
(sensorValue2 / sensorValue3) > 1.1 &&
(sensorValue0 > closePoint) &&
(sensorValue2 > closePoint));
{
digitalWrite(closePin, LOW);
}
else
{
digitalWrite(closePin, HIGH);
}
delay(500);
digitalWrite(closePin, HIGH);
// open sequence
if ((0.9 < (sensorValue0 / sensorValue1) < 1.1) &&
(0.9 < (sensorValue2 / sensorValue3) < 1.1) &&
(sensorValue0 < openPoint) &&
(sensorValue2 < openPoint));
{
digitalWrite(openPin, LOW);
}
else
{
digitalWrite(openPin, HIGH);
}
delay(500);
digitalWrite(openPin, HIGH);
}
the controller i am using uses an inverted control signal for some reason so turn on=low, turn off=high. i would appreciate any help your folks can offer. thanks in advance.