0

At the moment I have a switch that connects to a digital pin on an Arduino as per the schematic below. (Obviously there is an pull-up resistor on the pin).

schematic

simulate this circuit – Schematic created using CircuitLab

I now want this switch to also connect to another Arduino via an optocoupler. Is it as simple as just adding the optocoupler between the switch and ground with the necessary resistor for it?

1 Answer 1

0

Is it as simple as just adding the optocoupler between the switch and ground with the necessary resistor for it?

Probably not, because of two issues. First, adding circuit elements between the switch and ground raises the voltage the pin will see when the switch is closed, which might keep a switch closure from registering as a low pin voltage. For example, with Vcc=5V, table 30.2 DC Characteristics in the Rev. 8271J 11/2015 ATmega328P datasheet shows the guaranteed maximum input low voltage as 0.3 Vcc and the guaranteed minimum input high voltage as 0.6 Vcc; that is, 1.5 V and 3 V if Vcc=5V. If the voltage drop across the optocoupler is between 1.5 and 3 V then the pin might register high or low with no guarantee which.

Second, if the pullup is large, not enough current will flow to trigger the optocoupler. For example, at Vcc=5V if the internal pullup is used and the optocoupler drops two volts, I/O Pin Pull-up Resistor Current will be about 80 μA, too little to trigger a typical optocoupler. (See figure 35-17, ATmega328P: I/O Pin Pull-up Resistor Current vs. Input Voltage (Vcc = 5V) in datasheet.)

What you might do instead is use two optocoupler channels in parallel or series, one for each of the Arduinos. The switch lets current pass through an appropriate resistor or resistors and the optocoupler inputs; optocoupler outputs go to Arduino inputs.

Or, tie one side of the switch to +5V and the other to a resistor in series with an optocoupler input. Connect the first Arduino's input pin to the low side of the switch. I think that input will register low when the switch is open. It will register high when the switch is closed.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.