Very simple Arduino Uno question

Hey guys.

I'm wondering what the arduino reads on an input pin. I have a separate circuit that uses a relay that when the relay trips I want my wav shield attached to my arduino uno to play a sound. My separate circuit is already working and the relay trips when I need it to. I just want to add this extra sound and I have my wav shield and arduino already doing another task right beside this circuit. I am thinking I can just run 5V through the relay so when it trips it goes to say pin 6 on my arduino. Then the arduino will do a digitalread on pin 6 and see a HIGH value. Is this right or am I thinking about this wrong.



Sounds good. The arduino can easily read a 0-5V signal on a digital input.

does the 5v need to come from the arduino or can it come from my serperate circuit?

It can come from the Arduino. It can come from a separate circuit if the ground of the Arduino is connected to the ground of the separate circuit.

Note: There is "a rat" in "separate".

It should work. One thing you might want to be careful of is to make sure the GROUND pins are connected as well. If they are two separate circuits, the ground will be the common reference. Otherwise, 5V on one circuit has no meaning on the other circuit.

There's an elegant way to achieve your aim, using an interrupt. Several options are available to configure hardware interrupts on digital pins 2 or 3. The relay could "send" a high or a low (note other posts about ensuring the ground is shared) to the interrupt pin which could be set to read a high, low or pin change and then trigger the sound output. This way, you need not scan the pin for a signal, the interrupt will respond when the pin condition is met.

This is a good practice way to respond to an uncertain external event (one which may happen at any time). It will also teach you heaps about interrupts, which are your friend when it comes to having any microprocessor react to external events. Good luck and keep asking great questions.


As if it matters if the sound plays after a millisecond or after 100 milliseconds. With properly designed code, there is no need to use an interrupt for this.

I do not agree that this is a good practice way to respond to an uncertain external event. Beginners find interrupts difficult with which to deal. They do not understand how to use the volatile modifier and they have great difficulty in debugging an ISR. If used as intended, the loop() function is executed several thousand times per second and polling an input in the loop() function once per cycle is sufficient for most purposes.

I am not against some uses of interrupts but most Arduino programs are not multitasking (in the sense of actually having multiple independent tasks, not sharing of the loop() function) and the throughput that could be saved by using interrupts is thrown away anyway.

I prefer event-driven programs and interrupts are part of making that happen but interrupts do not seem to be the way to go for beginners in an Arduino environment.