If Statement Not Working..? - Programming Questions - Arduino Forum Home » Arduino If Statement Not Working » If Statement Not Working..? - Programming Questions - Arduino Forum Maybe your like Arduino If Statement Return Arduino If Then Multiple Conditions Arduino If Two Conditions Arduino Inventor's Guide Pdf Arduino Inverter 12v 220v if statement not working..? Projects Programming mateyb December 17, 2015, 5:46am 1 I'm looking for experienced arduino coders or just a second look. I've gone over this code dozens of times, trying all sorts of solutions only to get the same result. It seems like the if statement in my loop is basically ignored. The arduino doesn't care whether the condition is met or not, it proceeds right on through like the "if" wasn't even there. Do i have a simple typo that I've glazed over? Or do I need a something more? Thanks #include <OneWire.h> #include <Wire.h> #include "RTClib.h" RTC_DS1307 rtc; const int motorup = 11; const int motordown = 9; const int topSwitch = 1; const int bottomSwitch = 0; int topSwitchRead; int bottomSwitchRead; int nowtime; int sunrise; int sunset; //********************************************************************************************************************************************** void setup(void) { Serial.begin (9500); Wire.begin(); rtc.begin(); rtc.adjust(DateTime(2015,12,16,19,41,0)); pinMode(motorup, OUTPUT); digitalWrite(motorup, LOW); pinMode(motordown, OUTPUT); digitalWrite(motordown, LOW); pinMode(topSwitch, INPUT); digitalWrite(topSwitch, LOW); pinMode(bottomSwitch, INPUT); digitalWrite(bottomSwitch, LOW); } //********************************************************************************************************************************************** void getTimes(){ DateTime now = rtc.now(); float common = cos( ((now.month()-1)*30.5+now.day() + 8 ) / 58.091554) ; int sunrise = 370 + 90 * common; int sunset = 1106 - 88 * common; int nowtime = now.hour() * 60 + now.minute(); Serial.print("Now Time: "); Serial.println(nowtime); Serial.print("Sunrise: "); Serial.println(sunrise); Serial.print("Sunset: "); Serial.println(sunset); delay(1000); } void readSwitches(){ topSwitchRead = digitalRead(topSwitch); bottomSwitchRead = digitalRead(bottomSwitch); Serial.println(topSwitchRead); Serial.println(bottomSwitchRead); if (topSwitchRead == 0) { Serial.print ("Door is Up"); } else if(bottomSwitchRead == 0) { Serial.print ("Door is Down"); } else { Serial.print("Door is Moving"); } } //********************************************************************************************************************************************** void loop() { getTimes(); readSwitches(); if (nowtime == sunrise) { digitalWrite(motorup, HIGH); digitalWrite(motordown, LOW); if (topSwitchRead == 0) { digitalWrite(motorup, LOW); digitalWrite(motordown, LOW); } Serial.print("Openning Door"); } else if (nowtime == sunset) { digitalWrite(motorup, HIGH); digitalWrite(motordown, LOW); if (topSwitchRead == 0) { digitalWrite(motorup, LOW); digitalWrite(motordown, LOW); } Serial.print("Closing Door"); } else { digitalWrite(motorup, LOW); digitalWrite(motordown, LOW); Serial.print("No Change"); } } nickgammon December 17, 2015, 5:52am 2 int nowtime; ... void getTimes(){ ... int nowtime = now.hour() * 60 + now.minute(); You have two nowtime variables. One is local to getTimes, the other is global. Get rid of the "int" from inside getTimes: nowtime = now.hour() * 60 + now.minute(); Related topics Topic Replies Views Activity If statement/else if statement logic question Programming 3 536 May 5, 2021 If statement help pls Programming 17 2751 May 5, 2021 Problema con if Software 5 571 May 7, 2021 issue with if statement Programming 6 773 May 5, 2021 if statement without else Programming 7 2310 May 5, 2021 Tag » Arduino If Statement Not Working If And Else Statements, If Statement Not Working - Arduino Forum [SOLVED] If Statement Not Working With String - Arduino Forum 2nd If Statement Not Working - Arduino Forum If Statement Not Working - Programming Questions - Arduino Forum If Statement Does Not Work! What Am I Doing Wrong? - Arduino Forum If Statement Not Working - Programming Questions - Arduino Forum If Statement Not Working - Programming Questions - Arduino Forum IF Statement Doesn't Work Properly - Arduino Forum Not Getting Proper Output In Arduino (if Statement) - Stack Overflow If Statements Not Working As Expected On ESP32 - Stack Overflow Arduino IDE: Conditional(if-else-if) Statements - STEMpedia Serial Communication, If Statement Not Working 2.7 Understanding If / Else And While Statement In Arduino