Hi there
I'm very new to electronics. I'm switching an Omron relay (12VDC) from a separate source and trying to send 5VDC through the contacts to alternate two arduino inputs on (i.e. relay = ON then switch one of my arduino inputs on and if relay is OFF then switch another of my arduino inputs on).
I've got 5VDC (same 5VDC that I'm using to power the Arduino Mega) that goes through the relay contacts N/O and N/C and on to two different arduino inputs.
I've set up the input pins in the software as "Pinmode(xx, INPUT)" and INPUT_PULLUP.
However, it doesn't seem to "switch" the input?
When I've belled out the relay - the "switched" contact has the +5VDC (as expected) but the other contact has +1.5VDC and I wondered if the Arduino will just see both of them as "High" ??
I'm presuming I need to do something with resistors across something or some setting in the software but thought it best to just ask for advice before I break something!
Thank you for your help.
(after a request - I've uploaded a quick sketch below)
A schematic would be of more help than your description. A picture of a hand drawn circuit is good enough
I would question the need to use 2 Arduino pins to detect the 2 states (on and off) because if the relay is on it is not off and vice versa. You could, therefore, detect the state of the relay with a single pin and deal with it in software
Hi Bob
Thanks for replying. I've uploaded a quick sketch to my post which hopefully shows what I'm trying to describe.
You're correct about not needing the two pins but, at this stage, I'm just learning things and so experimenting. But, it's a very good point for when I get my head around it more.
Using pinMode(xx, INPUT_PULLUP); causes the input to be pulled high when it is not connected, so it remains high whether the relay contacts are open or closed.
Use INPUT_PULLUP, but use the relay to connect each of the two inputs to GND instead of +5V.
It's a single contact switched between two outputs. Apologies for the misleading drawing, I'm not very good at trying to illustrate things so it was just a "best effort" (and not a very good one!!)
When the relay contact is open the input to the Arduino is 'floating' i.e. it is not defined. If you add a resistor, say 10k (value is not critical) to 0V then the input will be pulled to 0V and the Arduino will be able to read accordingly.
Even easier, use INPUT_PULLUP in pinMode() for both pins and wire the circuit so that the common relay contact is wired to GND so that it takes one or other pin LOW when connected to that contact. Detect the LOW state of the pin to indicate that the contact is connected to that pin
@UKHeliBob thanks for that. That was also @JohnLincoln suggestion. And, it would certainly solve the problem but it's good to know "why" it doesn't work the way it is so I've marked Steve's answer as the solution in this case but thank you very much for all your help.
Have you got it working now ? If so, then please post your full sketch. Even without seeing it I suspect that it can be made shorter and/or smarter and you might learn something else, but we shall see
Yep, I've got it working now. I did learn something else though... I'd fed the Arduino with 5VDC and wondered why my 5VDC pin had dropped voltage to 3.5VDC.
Yesterday, whilst testing, I had the board plugged in via USB so this must have been supplying a higher voltage. I've no idea why I convinced myself that the board needed 5VDC?
However, I've connected it up to 12VDC now and all is good. And my relay is switching the inputs too which is excellent.
No point posting the sketch as I'm literally just playing around with it at the moment. There's nothing to see. I'll post again when I hit my next hurdle... something tells me it won' t be far away!