How to protect a digital output at HIGH when an override switch pulls it to ground

I an using an arduino with a typical relay board which needs to be pulled LOW to activate the relay, so is normally at HIGH

I would like to have a manual override switch that pulls the relay input to ground and I know I could use an input pin for that but I would prefer to have manual operation available at all times)

Is there a simple way to protect the output pin so that it stays at HIGH while I am pulling the relay LOW (momentarily - it's for points motors on a model railway)

Here's the idea:

Have you tried it? It looks ok to me.

If the pin of the switch is intended to be connected as shown by my red wire, then it wouldn't be a good idea to short the high Arduino pin output to Gnd. Adding a 1k resistor would make it safe. The resistor would limit the current from the output pin to 5mA.


[Edit, the 1k resistor may be too high to drive the relay coil if there's no coil driving buffer on the board]

Put a pull-up resistor on the input to the relay board, then a diode to the Arduino output pin so that it can only pull the input to the relay board low. The switch is then connected from the relay board input to ground.

The pullup resistor may not be needed, the typical opto-isolated relay board uses the input to provide the ground path for an LED inside the opto isolator.

@johnstrudwick
Your post title is "Protect digital pin ..."

In your drawing you say "when Arduino is not used"

So which one do you need?

Your relay module is like this?

If so, you can remove R1 put a jumper connecting VCC to pin 1 of 817C,
and use 1K from arduino and IN1.
Then connect your switch at IN1 and GND.

By doing this you can put IN1 to GND and not damage the Arduino, because if the pin is HIGH the current will be 5V/1000 = 5mA.
Hth

Careful, that will leave no current limiting resistor when the switch is used.

@mikedb : I want to use the layout in manual mode without a processor but the arduino will still be switched on.

@ruilviana : No it isn't like that - I put a link in the post - it's a multi way relay - I just simplified the drawing

I'd use an SPDT switch. Common terminal to the relay board, one "throw" terminal to the arduino, the other terminal to ground. That way, regardless of arduino state, you can activate the relay without potentially causing damage.

1 Like

@david_2018 : OK but I am new to electronics so can you sketch the circuit and name the diode and the resistor value please ? Thanks

@cedarlakeinstruments : The switches are small momentary ones to go onto a model railway control panel, so SPDT would be a) more exepnsive and b) take up too much land space

I think I Also read somewhere that these boards have a pullup resistor built in?

@Delta_G : Sure but I am new to electronics so which diode and how would it be wired?

6Pin 5.8x5.8/7x7/8x8/8.5x8.5mm Latching or Momentary PCB Push Button Switch DPDT

Put the override switch on the contact side of the relay.

Diode OR gate !

3 Likes

So if I use a diode, what diode would I use and which way would I orient it. (Sorry but not up to speed yet on electronics). Could it be combined with the resistor idea of @Dave_Lowther ?

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