Pin shutting down after around 8min

Hey all,

i've encountered a weird problem with my system.

I'm controlling a lamp with the arduino relay module, together with a RTC.
From 8am-7pm i want the light to be turned on by setting the outpin pin high on the relay module.
It works great at start, but after around 8min it randomly turns the pin off, measuring 0V.
At first i thought it's because of the high power demand, so i disconnected the relay module completely and measured again.
Same story, after around 8min the voltage is 0V.

But the weird thing is, as soon as i connect it to a PC via USB, the pin stays HIGH.
What could cause this kind of issue?
The rest of the sensors/displays are working perfectly fine all the time, so i don't think this is a power drain issue.

Here's the (relevant) code.

Thanks in advance!

unsigned long currentTime;

//RTC (Real-Time-Clock)
  #include <Wire.h>
  #include <RTClib.h>
  RTC_DS1307 rtc;
  DateTime now;
  
//Lampe
  const byte lampPin=4;

void setup() {
  Serial.begin(9600);
  analogReference(EXTERNAL);
  pinMode(pinCS,OUTPUT);
    digitalWrite(pinCS,HIGH);
  pinMode(lampPin, OUTPUT);
  
//RTC (Real-Time-Clock)
    rtc.begin();
    Wire.begin();
    if(!rtc.begin()){
      Serial.println(F("Couldn't find RTC"));
    }
    if(!rtc.isrunning()){
      Serial.println(F("RTC is NOT running"));
    }
    rtc.adjust(DateTime(F(__DATE__), F(__TIME__)));         //Zeit/Datum neu justieren
  
 void loop() {
  
  //Lampe
    if(now.hour()<19 && now.hour()>7){
      digitalWrite(lampPin,HIGH);}
      else{
          digitalWrite(lampPin,LOW);
        }
  
  //RTC
    now=rtc.now();
    if(now.day()<10){                              //Uhrzeit anzeigen
      Serial.print("0");
      }
    Serial.print(now.day(), DEC);
    Serial.print("/");
    if(now.month()<10){
      Serial.print("0");
      }
    Serial.print(now.month(), DEC);
    Serial.print("/");
    Serial.print(now.year(), DEC);
    Serial.print("  ");
    if(now.hour()<10){
      Serial.print("0");
      }
    Serial.print(now.hour(),DEC);
    Serial.print(":");
    if(now.minute()<10){
      Serial.print("0");
      }
    Serial.print(now.minute(),DEC);
    Serial.print(":");
    if(now.second()<10){
      Serial.print("0");
      }
    Serial.print(now.second(),DEC);
    Serial.println();

That code will not compile, it's incomplete (closing } are missing).

Create a minimal sketch that still has the behaviour you describe, and post that in whole. As you already indicate things are left out from this, and usually the error is the part that's been left out. So it's not even worth the effort to go through this piece of code.

You do not use these, so remove or comment-out...

  // pinMode(pinCS, OUTPUT);
  // digitalWrite(pinCS, HIGH);

You are missing a close-brace for setup() and a close-brace for loop()

Then it compiles.

show module

#include <Wire.h>
#include <RTClib.h>
RTC_DS1307 rtc;
DateTime now;

//Lampe
const byte lampPin = 4;

void setup() {
  Serial.begin(115200);
  pinMode(lampPin, OUTPUT);

  rtc.begin();

  if (!rtc.begin()) {
    Serial.println(F("Couldn't find RTC"));
  }
  if (!rtc.isrunning()) {
    Serial.println(F("RTC is NOT running"));
  }
  //rtc.adjust(DateTime(F(__DATE__), F(__TIME__)));         //Zeit/Datum neu justieren
}

void loop() {
  now = rtc.now();

  //Lampe
  digitalWrite(lampPin, now.hour() < 19 && now.hour() > 7);

   //Uhrzeit anzeigen
  char bufer[30];
  sprintf(bufer, "%02d/%02d/%02d %02d:%02d:%02d\r\n", now.day(), now.month(), now.year(), now.hour(), now.minute(), now.second());
  Serial.print(bufer);

  delay(1000);
}

Post an annotated schematic showing exactly how you have wired it, be sure to include all connections, parts, power sources and grounds. Also post links to the technical information on the hardware devices.

I found the problem. I had the adjust.time command active in the setup, and when i started the system without a PC connected to it, it set the time to a weird default time which was out of the scope of my "turn the lamp on"-time, so the uC set the pin low.

Thanks anyways for the answers!

1 Like

This topic was automatically closed 180 days after the last reply. New replies are no longer allowed.