Dear Friends,
In this opportunity I writing to you asking help in order to find a solution to this short sketch. The main purpose is to powering a sensor through the enabling of a pin according to the hour (starting and finish hour) given by a RTC.
Although the IDE can compile the sketch and the serial print can work, the snippet "if" statement does not work.
I appreciate so much your help.
Kind Regards,
#include <Sodaq_DS3231.h>
#include <Wire.h>
// set pin numbers:
const int ledPin = 13;
const int powerPin = 8; // the number of the power pin
const uint8_t horaInicio = 17; // set thestating hour
const uint8_t horaFin = 19; // set the finish hour
void setup()
{
pinMode(powerPin, OUTPUT);
pinMode(ledPin, OUTPUT);
Serial.begin(9600);
Wire.begin();
rtc.begin();
}
void loop()
{
DateTime now = rtc.now(); //get the current date-time
Serial.print(now.hour(), DEC);
Serial.println();
delay (2000);
if ( horaInicio <= now.hour() >= horaFin )
{
//power on
digitalWrite (powerPin, HIGH);
// turn LED on:
digitalWrite(ledPin, HIGH);
}
else {
// turn LED off:
digitalWrite(ledPin, LOW);
}
delay (1000);
}
powerPin_8.ino (771 Bytes)