I am new to Arduino. The digital pins can be configured as output (https://www.arduino.cc/en/Tutorial/DigitalPins) for triggering some sensors. I am now setting a digital (output pin), say no. 7,which is connected to the in1
pin of a SRD relay (https://blog.siliconstraits.vn/relay-what-is-it-and-how-to-use-it/):
enter image description here
I am not very clear about the direction of current flowing in the wire connecting the arduino digital pin to in1
. To my understanding, when digitalWrite(pin, HIGH)
, no current flow into the arduino pin, the relay is not triggered, while digitalWrite(pin, LOW)
, the current flow into the arduino, and the relay is triggered. Please correct me if I am wrong. Thanks.
-
You are not driving the relay directly, are you?Edgar Bonet– Edgar Bonet2019年06月27日 14:35:31 +00:00Commented Jun 27, 2019 at 14:35
-
I updated the post.jingweimo– jingweimo2019年06月27日 14:46:27 +00:00Commented Jun 27, 2019 at 14:46
-
1In your question, you mention connecting the Arduino to a relay, yet in the figure, you show a relay board. That's not the same! Please clarify. If using a relay board, please link to the datasheet or the supplier's product page.Edgar Bonet– Edgar Bonet2019年06月27日 14:50:35 +00:00Commented Jun 27, 2019 at 14:50
-
2you did not answer my first questionjsotola– jsotola2019年06月27日 17:47:08 +00:00Commented Jun 27, 2019 at 17:47
-
1The relay board in the picture has a transistor on it that turns on the (blue) relay. The Arduino pin only turns on the transistor, which in then turns on the relay. The transistor makes it so that only a small amount of current is needed from the Arduino pin. This is because the coil in the relay requires more current that the Arduino pin can (safely) provide.Gerben– Gerben2019年06月27日 18:56:50 +00:00Commented Jun 27, 2019 at 18:56
1 Answer 1
When you set a pin to HIGH then that pin will provide 5V. When you set a pin to LOW then that pin will be set to 0 volts. Which direction the current flows depends on what is at the other end of the wire. Current always flows from higher voltage to lower voltage. If you set a pin to HIGH and the thing it is connected to is at ground then current will flow out of the pin towards ground. If you set a pin to HIGH but the thing it is connected to is already at 5V then no current flows. If you set a pin to LOW and the thing it is connected to has some positive voltage then current will flow to the pin. If you set the pin to HIGH (5V) but the thing it is connected to has more voltage than that (say 10V) then current will flow towards the lower voltage and into the pin, probably damaging the Arduino in the process.