5V Relay, logic level converter necessary?

Hi, I’ve got the “Arduino nano” and I would like to control the following relay: SRD-05VDC-SL-C (amazon-link). As the logic level is providing 3.3V and the level for the relay is 5V, will I need a logic level converter? I’m also asking, because some ARE saying “it will work (without a converter)” because 3.3V could already be identified as “HIGH”.

Well, I’ve tried it and it DOES work, however, the startup of the sketch I’m writing is a bit strange: The startup takes place twice and during startup the relay switches off then on then off again (like being backlashed from the 5V by the induction of the coil … or is this instruction circuit already on my relay shield?)

Here’s my sketch (sorry variables in German) … it’s supposed to read a water level sensor and switch on/off a water pump.

/*
  Wasserpumpensteuerung
*/

/* PIN-Konfiguration */
int wassersensorpin = 4;  
int pumpenpin = 2;

/* Einstellvariablen */
int schwellwert = 50;
int nachlaufsekunden = 10;

/* Sonstige Variablen */
char zeile[100];

// the setup function runs once when you press reset or power the board
void setup() {
  Serial.begin(9600);
  Serial.println("Wassersensor");

  pinMode(LED_BUILTIN, OUTPUT);
  pinMode (wassersensorpin, INPUT);
  pinMode (pumpenpin, OUTPUT);

  digitalWrite(pumpenpin, LOW);
}

// the loop function runs over and over again forever
void loop() {
  digitalWrite(LED_BUILTIN, HIGH);   // turn the LED on (HIGH is the voltage level)
  delay(1000);                       // wait for a second
  digitalWrite(LED_BUILTIN, LOW);    // turn the LED off by making the voltage LOW
  delay(1000);                       // wait for a second
  boolean eingeschaltet = (digitalRead(pumpenpin) == HIGH);
  if (analogRead(wassersensorpin) < schwellwert) {
    if (eingeschaltet) {
      sprintf(zeile, "Wartezeit %d Sekunden", nachlaufsekunden);
      Serial.println(zeile);
      delay(nachlaufsekunden*1000);
    }
    Serial.println("Kein Wasser");
    digitalWrite(pumpenpin, LOW);
  } else {
    sprintf(zeile,"Wassersensor: %d", analogRead(wassersensorpin));
    Serial.println(zeile);
    digitalWrite(pumpenpin, HIGH);
  }
}

So, I’m almost there, except for my 3.3V/5V question and the strange startup behaviour, maybe you can provide me with advise?
Thank you in advance
Michael

The nano operates at the 5V logic level already. Why did you think it's a 3V3 MCU?

Well, I've tried it and it DOES work, however, the startup of the sketch I'm writing is a bit strange: The startup takes place twice and during startup the relay switches off then on then off again (like being backlashed from the 5V by the induction of the coil ... or is this instruction circuit already on my relay shield?)

Your relay is "low level trigger" which means that it energizes (turns on) when the Arduino output is LOW. The relay turns off when the Arduino output goes HIGH.

To keep the relay OFF during setup, then do this

pinMode (pumpenpin, INPUT_PULLUP) //this will change the default to HIGH if the pin is set as output
pinMode (pumpenpin, OUTPUT); //output goes HIGH, relay remains OFF

Your relay is "low level trigger" which means that it energizes (turns on) when the Arduino output is LOW. The relay turns off when the Arduino output goes HIGH.

This should alleviate any concerns about the voltage level. (Since it is turned on by SINKING the opto led current.)

raschemmel:
This should alleviate any concerns about the voltage level. (Since it is turned on by SINKING the opto led current.)

What optocoupler?

Thank you very much for your valuable input, it is working now as it should! You guys are awesome!
The “INPUT_PULLUP” during init actually did the trick. And sorry for the 3.3V/5V confusion, the clarification makes it clear. Very cool, project #1 done. That really motivates me to continue with my next projects around the house; there will be much to do, but I really enjoy it!
The init is run twice when I launch with the Serial Monitor which is well documented ==> Solved.
Thank you again!
T<— only standing here for cosmetical purposes, has no meaning … Kind Regards :wink: