Trouble with Relay Boards and Mega 2560

I’m having some trouble here and I thought I would reach out for the first time on the forum. I’m building a simple solar tracker device that turns a rotating platform forward 15 degrees every hour, landing at 180 degrees south at noon each day. All together I have 4 relays. One to advance forward by energizing a relay for a very short time (<1 sec, or for however long it takes my platform to move 15 degrees) one to reverse at the end of the day (sum of each forward advance), one to energize an alarm for 4 seconds prior to each forward or reverse motion, and fourth relay for energizing a DHT11 controlled small cooling fan in the charge controller housing. I know there are more elegant ways to do this…. Forgive me but I have to go one step at a time here.

My trouble is with these 2 relay boards. It’s as if the coils are always energized, however when I disconnect the jumpers and measure voltage at the digitalpins, I’m right on with the intention of the my code (write HIGH for 1 sec, every hour, else write LOW) meaning, I have 5V out for only a second. When measuring voltage from IN1 or IN2 pins on the relay board to Ground, I get odd voltages… like 1.8V or 2.4V out. The relays will audibly click when I plug these jumper wires back in. I should mention the led lights on the relay board are always on, except for the one corresponding to the cooling fan.
Could this odd voltage ‘coming out’ of IN1 and IN2 be a grounding issue? Possibly it has to do with the jumper at RY VOC? I’ve read about how these boards could use a 2nd 5V power source and maintain optical isolation. I’d rather stay away from another power source unless it’s really necessary.
This is the relay board I’m using. To be clear, I have two of these hooked up now.

Also, when I energize my 12V power source my alarm relay closes for a few seconds, regardless of what time it is. I would have thought this was a code issue, but I dont see it when applying 5V power via USB.

AND…. any idea what size fuse I could use to protect the board? I’ve searched and have not found a direct answer. Now there is a 1 amp automotive fuse between my 12V power source and the MEGA 2560.

Ok….thank you all who read this and especially to those who can offer some guidance

#include <Wire.h>
#include "RTClib.h"
#include "DHT.h"
#define DHTPIN 2
#define DHTTYPE DHT11

DHT dht(DHTPIN, DHTTYPE);
RTC_DS1307 rtc;

void setup() {

  Serial.begin(9600);
  Serial.println("DHT Test");
  
  dht.begin();
  Wire.begin();

  rtc.begin();

  if (! rtc.isrunning())
  {
    Serial.println("RTC is NOT running!");
    rtc.adjust(DateTime(__DATE__, __TIME__));
  }
  //assigning functions to pins
  
  pinMode(4, OUTPUT); //tracker motor forward relay
  pinMode(5, OUTPUT); //tracker motor reverse relay
  pinMode(6, OUTPUT); //future tracker motor alarm relay
  pinMode(7, OUTPUT); //control box cooling fan relay

}

void loop() {
  
  float h = dht.readHumidity();
  float t = dht.readTemperature();
  
  if (isnan(t) || isnan(h)) {
    Serial.println("Failed to read from DHT");
    } else {
    Serial.print("Humidity: ");
    Serial.print(h);
    Serial.print(" %\t");
    Serial.print("Temperature: ");
    Serial.print(t);
    Serial.println(" *C");
    }
 
  DateTime now = rtc.now();

  Serial.print(now.year(), DEC);
    Serial.print('/');
    Serial.print(now.month(), DEC);
    Serial.print('/');
    Serial.print(now.day(), DEC);
    Serial.print(" (");
    Serial.print(now.hour(), DEC);
    Serial.print(':');
    Serial.print(now.minute(), DEC);
    Serial.print(':');
    Serial.print(now.second(), DEC);
    Serial.print(")");
    Serial.println();

    Serial.println();
    delay(2000); //add 2 second delay to accommodate slow sensor, before when reading temperature/humidity AND time 

    //THERMOSTAT CONTROL
    //lines immediatey following are thermostat section for enclosure cooling fan
    //Pin6 is 5V output for cooling fan relay

    if ((t) >= 30) //if temperature is greater than or equal to 30C, or 86F
    {
      digitalWrite(7,HIGH); //turn on cooling fan relay 
    }
    else
    {
      digitalWrite(7,LOW); //otherwise cooling fan relay is off
    }

     //CLOCK TIMER MOTOR CONTROL
     //following lines are clock control section for forward and reverse action of motor, and alarm control
     //The time is set as 24 hours
     //0 is sunday,1 is monday. 
     //0 is 12AM,1 is 1AM
     //Pin 4 on for short 'bursts' at and between every hour between 9AM and 5PM
     //Pin 4 on time is equivalent to 15 degrees (360deg/24hrs) clockwise rotation of tracker every 1 hour. 
     //estimating 1 second ON time is equivalent of 15 degrees
     //Pin 5 on only at 6PM for 9 seconds to return to AM starting position. 
     //Pin 6 on for 4 seconds prior to each forward or reversing motion

    if (now.hour() == 9 & now.minute() == 0 & now.second() == 0)
    {
      digitalWrite(6,HIGH); //energizes alarm relay
      delay(4000); //for 4 seconds, then,
      digitalWrite(4,HIGH); //energizes relay for 1 second at 9AM
      delay(1000); //amount of time moving in forward direction
    }
    else if (now.hour() == 10 & now.minute() == 0 & now.second() == 0)
    {
      digitalWrite(6,HIGH); //energizes alarm relay
      delay(4000); //for 4 seconds, then,
      digitalWrite(4, HIGH); //energizes relay for 1 second at 10AM
      delay(1000);
    }
     else if (now.hour() == 11 & now.minute() == 00 & now.second() == 0)
    {
      digitalWrite(6,HIGH); //energizes alarm relay
      delay(4000); //for 4 seconds, then,
      digitalWrite(4, HIGH); //energizes relay for 1 second at 11AM
      delay(1000);
    }
    else if (now.hour() == 12 & now.minute() == 0 & now.second() == 0)
    {
      digitalWrite(6,HIGH); //energizes alarm relay
      delay(4000); //for 4 seconds, then,
      digitalWrite(4, HIGH); //energizes relay for 1 second at 12PM
      delay(1000);
    }
      else if (now.hour() == 13 & now.minute() == 0 & now.second() == 0)
    {
      digitalWrite(6,HIGH); //energizes alarm relay
      delay(4000); //for 4 seconds, then,
      digitalWrite(4, HIGH); //energizes relay for 1 second at 1PM
      delay(1000);
    }
      else if (now.hour() == 14 & now.minute() == 0 & now.second() == 0)
    {
      digitalWrite(6,HIGH); //energizes alarm relay
      delay(4000); //for 4 seconds, then,
      digitalWrite(4, HIGH); //energizes relay for 1 second at 2PM
      delay(1000);
    }
      else if (now.hour() == 15 & now.minute() == 0 & now.second() == 0)
    {
      digitalWrite(6,HIGH); //energizes alarm relay
      delay(4000); //for 4 seconds, then,
      digitalWrite(4, HIGH); //energizes relay for 1 second at 3PM
      delay(1000);
    }
      else if (now.hour() == 16 & now.minute() == 0 & now.second() == 0)
    {
      digitalWrite(6,HIGH); //energizes alarm relay
      delay(4000); //for 4 seconds, then,
      digitalWrite(4, HIGH); //energizes relay for 1 second at 4PM
      delay(1000);
    }
      else if (now.hour() == 17 & now.minute() == 0 & now.second() == 0)
    {
      digitalWrite(6,HIGH); //energizes alarm relay
      delay(4000); //for 4 seconds, then,
      digitalWrite(4, HIGH); //energizes relay for 1 second at 5PM
      delay(1000);
    }
      else if (now.hour() == 18 & now.minute() == 0 & now.second() == 0)
    {
      digitalWrite(6,HIGH); //energizes alarm relay
      delay(4000); //for 4 seconds, then,
      digitalWrite(5, HIGH); //energizes reversing relay for total of forward time since 8AM.
      delay(9000); //sum of each forward movement delay time
    }
    else
    {
      digitalWrite(4, LOW); //de-energizes relay at times other than entered above
      digitalWrite(5, LOW); //de-energizes reversing relay at times other than entered above
      digitalWrite(6, LOW); //de-energizes alarm relay
    }
}

20170605_112755[1].jpg

5V from USB probably isn't enough power to run the 4 relays.
USB maximum is about 500 mA.

The relay board is an active low. That means that:

digitalWrite(PIN,LOW); will turn the relay ON.

digitalWrite(PIN,HIGH); Will turn the relay OFF.

Great! I’ll change it over now and see what I get. Thanks you two

Does anyone know how much current is required to activate the relays? I had read before it was very little… 15-20mA. Can’t remember where I saw that. Would I measure resistance between IN1 and Ground to found out? Anyone know what the max output at the 5V pin is?

fieldsofdan:
Great! I'll change it over now and see what I get. Thanks you two

Does anyone know how much current is required to activate the relays?

Google the part number for the relay to get the datasheet.

OK. So just the relay? The electronics in between won’t (substantially) effect the current draw?

This is working great now BTW. Thanks both of you for your help.

15-20mA is what the Arduino needs to sink to turn on LED in the optoisolator, whose output turns on the transistor that actually sinks the relay coil current, which can be tens of mA or more, depending on if it is a 12V relay or a 5V relay. 5V will need more generally: power needed to move the mechanical bit of the relay is the same, so 12V x current = 5V x 12/5 current.

Crossroads thanks for detailed answer.
This clears things up a lot for me.

CrossRoads:
15-20mA is what the Arduino needs to sink to turn on LED in the optoisolator,...

No, it's about 2mA.

Most of those relay boards have a ~1..8volt indicator LED, a ~1.2volt opto LED, and a 1k resistor in series.
That's 5volt - 1.8 LED -1.2 LED = 2volt across the 1k CL resistor >> 2mA.

The coil of a common 5volt blue sugar-cube relay draws about 75mA.
The 12volt version draws about 30mA.
Leo..