Relay making voltage going down

Hello!

I have a problem that i cannot understand. I´m just learning electronics, so it may be a silly thing:

I´m trying to use an arduino nano (DCCduino clone) to activate a relay using de D2 pin. I´m using a 9V DC batt to power the arduino nano, and a DC/DC (9V to 5V) converter connected to the battery to power the relay.

After setting D2 pin to high and BEFORE connecting D2 to relay signal pin, I´ve tested voltage with a multimeter between the cable coming from de D2 , and the ground comming from arduino... and it gives my 4.70V, that seems ok and close to 5V expected. But then, after i connect the cable comming from D2 to the signal pin of the realy, if i read with the multimeter it gives me 2,38V. Why?.

No need to say, that the relay doesn´t get triggered (although the LED in the relay lights on).

This is the relay i´m using: https://www.amazon.es/gp/product/B07BVXT1ZK/ref=ppx_yo_dt_b_asin_title_o05_s00?ie=UTF8&psc=11

I´ve tested with several relays of the same kind, just in the case one was broken... and same result.

Do you have any hint about this?.

Thank you a lot in advance!! .:ismael:.

Let us see a schematic of the circuit.

Let us see a good image of the actual wiring.

Let use see the sketch.

Does the 5V to the Nano also drop to something less than 5V?

I’m using a 9V DC batt to power the Arduino nano, and a DC/DC (9V to 5V) converter connected to the battery to power the relay.

If you mean what I know of as a PP3, mostly used in smoke alarms, then they are great for smoke alarms, not much use for anything else and not really up to the job of powering an Arduino project. I suggest a 5V power supply, such as a mobile phone charger.

Can’t help more without a schematic and your code, don’t forget the code tags </>.

Compare the required current to operate the relay and the current the GPIO pin can supply. I think you will find that the relay coil wants more I than the GPIO can supply.

The relay COIL draws 72mA @ 5V, big load for a puny 9V batt.

Hello!

Yes... indeed is a little more complicated... just tried to simplify the post, but here you have the whole schema (sorry for the poor handmade... i´ve not learned to manage fritzing yet).

In few words: I am just trying to use arduino to control when to output 12V.

I have a "big" 12V 12aH as main power source. From that i extract 9V with a DC/DC converter (12V-->9V) that can draw 2Amp. I use this to power the arduino nano with its VIn and GND pins (since I read that power the nanodirectly with 12V could be harmful).

From the 9V converter ouput, i also connected another DC/DC converter from 9V to 5V... to power the relay separately from the arduino (max current drive from tihs DC/DC is 3Amp).

When i set pin D2 to high WITHOUT conecting D2 to S pin of the relay, i can read 4.5V with the multimeter. But when i connect D2 to S, it becames 2.38V.

I dont´t think would be useful to copy the sketch.... it just set the D2 pin to high, and that part is working properly.

I don´t know if this clarify... obviously i´m missing something.... or doing something wrong.

Thank you a lot to you all for your responses....

phornee: Just tried to simplify the post, but here you have the whole schema (sorry for the poor handmade... i´ve not learned to manage fritzing yet).

Hand drawn is fine, use a ruler for neat lines. Fritzing is pretty much universally hated on here! Learn to use either Kicad or Eagle to do proper schemtics.

I have a "big" 12V 12aH as main power source. From that i extract 9V with a DC/DC converter (12V-->9V) that can draw 2Amp. I use this to power the Arduino nano with its VIn and GND pins (since I read that power the Nano directly with 12V could be harmful).

From the 9V converter output, i also connected another DC/DC converter from 9V to 5V... to power the relay separately from the Arduino (max current drive from this DC/DC is 3Amp).

You should feed the 5V pin of the Nano with the 5V from the converter, feeding 9V into an Arduino when you have 5V available is daft.

When i set pin D2 to high WITHOUT connecting D2 to S pin of the relay, i can read 4.5V with the multimeter. But when i connect D2 to S, it becomes 2.38V.

Need to see the schematic we are waiting for...

I don't´t think would be useful to copy the sketch.... it just set the D2 pin to high, and that part is working properly.

We would appreciate it if you will please just accept that we think it is vital to show us the code, all the code, in code tags.

Thank you.

It was a mistake to buy that relay to use when switching 12V. This is a very common beginner mistake. You should have purchased a 12V relay. That way, the relay coil can be powered directly from the 12V supply and does not burden the Arduino. If the other components attached to the Nano require only small currents, they and the Nano can be powered directly from 12V and no dc-dc converter is needed.

5V:
12V:

Also, go ahead and use Fritzing if you want. But use the schematic view when posting on the forum. Do not post breadboard view images on the forum because forum members hate the breadboard view.

Hi!. I think that the schema was missing in my last post, because itwas too big. I´ve reduced itsoit let me attach it.

I appreciate a lot you comments.

I´ll feed the arduino with the 5V instead of 12V… i guess that that way arduino will dissipate less energy to step down to its native 5V.

Also, you are right… now i realize that i should have got a 12V relay… i just got 5V ones because i thought that it was better for arduino use. Can be a 12V relay be powered with 12V, but triggered with a 5V signal?

I am posting the whole code… its a very simple one. Every MILLI_PERIOD it sets to HIGH pin 2 for MILLI_ENABLED time.

When testing, i just modify those parameters so that pin 2 its constantly high.

THank you a lot for your help.

/*
  Daily Timer
*/


static unsigned long previous_time = 0; // RTC

#define MILLI_PERIOD 24UL*60*60*1000    // Period of timer to enable signal... default is every 24 hours
//#define MILLI_PERIOD 10UL*60*1000    // Period of timer to enable signal... default is every 24 hours
#define MILLI_ENABLED 20UL*60*1000      // Time that the signal will remain enabled
//#define MILLI_ENABLED 20UL*60*60*1000      // Time that the signal will remain enabled

#define MILLI_BLINKING_PERIOD 20UL*1000 // Period of "hours left to enable" blinking info.
#define MILLI_BLINKING_TENS 1000        // Blinking time for tens of "hours" during indicator.
#define MILLI_BLINKING_UNITS 300        // Blinking time for units of "hours" during indicator.
#define MILLI_BLINKING_DELAY 100        // Time between two blinks.

#define MILLI_CONTROL_PIN 2

// the setup function runs once when you press reset or power the board
void setup() {
  // initialize digital pin LED_BUILTIN as an output.
  pinMode(LED_BUILTIN, OUTPUT);
  previous_time = millis();
      
  Serial.begin(9600);
  while (!Serial);
}

void Blink(int iBlinkMillis)
{
  digitalWrite(LED_BUILTIN, HIGH);   // turn the LED on (HIGH is the voltage level)
  delay(iBlinkMillis); 
  digitalWrite(LED_BUILTIN, LOW);
  delay(MILLI_BLINKING_DELAY);
}

// the loop function runs over and over again forever
void loop() {
  
  unsigned long now = millis();

  unsigned long deltatime = now - previous_time;

  if (deltatime >= MILLI_PERIOD) // Turn on cycle!
  {
    previous_time += MILLI_PERIOD;
    
    String str = String("TRIGGER: Now=") + now + String(" | previous=") + previous_time + String(" | Delta=") + deltatime ;
    Serial.println(str);

    digitalWrite(MILLI_CONTROL_PIN, HIGH);
    digitalWrite(LED_BUILTIN, HIGH);
    delay(MILLI_ENABLED);       // Keep the pin HIGH for the time needed
    digitalWrite(MILLI_CONTROL_PIN, LOW);
    digitalWrite(LED_BUILTIN, LOW);
  }
  else
  {
    // Code for just indicate remaining hours by using long and short blinks.
    unsigned long hours = 24 - deltatime / (60UL*60*1000);
    unsigned long tens = hours / 10;
    unsigned long units = hours - tens*10;

    String str = String("Tens: ") + tens + String(" | Units: ") + units;
    Serial.println(str);
     
    for (int i=0; i<tens; i++)
      Blink(MILLI_BLINKING_TENS);

     for (int i=0; i<units; i++)
      Blink(MILLI_BLINKING_UNITS);

    int del = int(MILLI_BLINKING_PERIOD - tens*(MILLI_BLINKING_TENS + MILLI_BLINKING_DELAY) - units*(MILLI_BLINKING_UNITS + MILLI_BLINKING_DELAY));
    delay(del);
  }

}

How to post an image |391x500

Thanks for the code and schematic.

Your code is WAY too complicated to test for the problem you are asking us about. Start with something simple and see if the relay works as expected, then increase the functionality of the code in small steps. I suggest you use the blink example in the IDE (file/01.examples/blink) and modify it so it flashes the in-built LED and the relay output pin (D2) in your project. Maybe try slightly longer delay times so you have time to read the voltage on D2 before it changes.

Also as discussed get rid of the 9V buck converter and power from 5V.

Also, you are right.... now i realize that i should have got a 12V relay... i just got 5V ones because i thought that it was better for Arduino use. Can be a 12V relay be powered with 12V, but triggered with a 5V signal?

Yes, if it has the appropriate circuitry on the board, which the ones supplied on a circuit board like yours generally do.

When testing, i just modify those parameters so that pin 2 its constantly high.

See my reply #10, we can only go by the code you post, not your description of what you think you are doing. Please use a simple program as described and post that if you still have a problem.

I can't see anywhere in your code where you set pin 2, MILLI_CONTROL_PIN, as an output.

Other things wrong with your code.

You can't mix milllis timing with delay timing. While delay is delaying nothing else is happening, including the millis based timers. If they mature while delay is delaying then they will be missed.

static unsigned long previous_time = 0; // RTC

Variables do not need to be static when their scope is global as they never go out of scope so never lose their value.

You are using String (capital S), the problem with String is it tends to corrupt the memory and eventually your program stops working for no obvious reason. There's loads of discussion on here about it, do some searching and reading for both the cause of the problem and what to use instead.

It would be better if you started to think in terms of functions instead of having everything in loop. A function should do one clearly defined task, do it quickly then return. Loop should consist of calls to various functions and nothing else.

Can be a 12V relay be powered with 12V, but triggered with a 5V signal?

Yes, because the 5V signal triggers a small transistor or opto-isolator on the relay module. The transistor/opto then switches the 12V to the relay coil. For your project, using an opto-isolator is not important, so do not pay more for relay modules with opto-isolators.

PerryBebbington: You can't mix milllis timing with delay timing. While delay is delaying nothing else is happening, including the millis based timers. If they mature while delay is delaying then they will be missed.

The millis interrupt still occurs and the millis value still counts up during a delay(), but anything that was depending on millis for timing won't get tested until released from the delay().

SteveMann: The millis interrupt still occurs and the millis value still counts up during a delay(), but anything that was depending on millis for timing won't get tested until released from the delay().

Yes, agreed, I was just keeping it simple.

Hello!

Perry, this made my day...

I can't see anywhere in your code where you set pin 2, MILLI_CONTROL_PIN, as an output.

Thank you so much, that was my error.... you were right when you said that you needed to see the code, not only the schema.

Just set the pin 2 to output, and now its working :)

You are using String (capital S), the problem with String is it tends to corrupt the memory and eventually your program stops working for no obvious reason. There's loads of discussion on here about it, do some searching and reading for both the cause of the problem and what to use instead.

Thank you for your tip... i´ve faced the fragmentation issue many times in the past in another platforms, and now i realize how important this can be for a platform with such small memory as a nano. I´ll get rid of them. Talking about the delay/milliseconds mix.... i know it can be problematic, but in this case i don´t need the relay to switch on exactly at the same time... i can assume a 20 seconds difference.

Thank you all for your patience and your help... you made me a little less ignorant. .:ismael:.

Arduino malloc() uses a buddy system so isn't too bad w.r.t. fragmentation - but there's so little RAM anyway that String use can sometimes push things over the edge. You can dynamically measure RAM use with the MemoryFree library to see if you are likely to be hitting the limit.

MarkT: Arduino malloc() uses a buddy system

Never heard of that, v. interesting. +1 karma