# Rasberry Pi GPIO pins not switching

**URL:** <https://discourse.nodered.org/t/rasberry-pi-gpio-pins-not-switching/61658>\
**Category:** General\
**Created:** [22 April 2022 18:17 UTC](https://discourse.nodered.org/t/rasberry-pi-gpio-pins-not-switching/61658 "2022-04-22T18:17:13Z")\
**Posts on this page:** 20\
**Page:** 1

<div class="post-metadata">

**Author:** ![Jsimon003](https://avatars.discourse-cdn.com/v4/letter/j/7ea924/32.png) [@Jsimon003](https://discourse.nodered.org/u/Jsimon003)\
**Post date:** [22 April 2022 18:17 UTC](https://discourse.nodered.org/t/rasberry-pi-gpio-pins-not-switching/61658/1 "2022-04-22T18:17:13Z")

</div>

I have a simple GPIO set up where I inject a 1 and a 0 into the standard GPIO node to turn a relay on and off. my GPIO pins will not change state

---

<div class="post-metadata">

**Author:** ![jbudd](https://avatars.discourse-cdn.com/v4/letter/j/5f8ce5/32.png) [@jbudd](https://discourse.nodered.org/u/jbudd)\
**Post date:** [22 April 2022 18:34 UTC](https://discourse.nodered.org/t/rasberry-pi-gpio-pins-not-switching/61658/2 "2022-04-22T18:34:02Z")

</div>

H @Jsimon003 , welcome to the forum.

Perhaps you could give a little more information:

What device are you running Node-red on?  
What operating system does it run?  
What version of Node-red and node.js?  
Exactly what "standard GPIO node" are you using?  
How do you know that the pins do not change state?  
Can you show us your flow? Export it from Node-red and paste it here after clicking the `</>` button.

---

<div class="post-metadata">

**Author:** ![Jsimon003](https://avatars.discourse-cdn.com/v4/letter/j/7ea924/32.png) [@Jsimon003](https://discourse.nodered.org/u/Jsimon003)\
**Post date:** [22 April 2022 18:51 UTC](https://discourse.nodered.org/t/rasberry-pi-gpio-pins-not-switching/61658/3 "2022-04-22T18:51:22Z")

</div>

What device are you running Node-red on?  
Rasbery Pi 4  
What operating system does it run?  
Rasberry pi OS  
What version of Node-red and node.js?  
v1.0.6  
Exactly what "standard GPIO node" are you using?  
node-red-node-pi-gpio is the pallet and im using rip GPIO out

How do you know that the pins do not change state?  
Because the relay constantly stay on even though I inject a 0

Can you show us your flow? Export it from Node-red and paste it here after  
clicking the `</>` button.

```auto
[{"id":"1def1387.cd722c","type":"tab","label":"Flow 1","disabled":false,"info":""},{"id":"a04aa8dc.1f7988","type":"inject","z":"1def1387.cd722c","name":"","topic":"","payload":"0","payloadType":"num","repeat":"","crontab":"","once":false,"onceDelay":0.1,"x":310,"y":220,"wires":[["6383dbad.370dc4"]]},{"id":"6383dbad.370dc4","type":"rpi-gpio out","z":"1def1387.cd722c","name":"","pin":"40","set":"","level":"0","freq":"","out":"out","x":570,"y":200,"wires":[]},{"id":"7ebaf35.02cca0c","type":"inject","z":"1def1387.cd722c","name":"","topic":"","payload":"1","payloadType":"num","repeat":"","crontab":"","once":false,"onceDelay":0.1,"x":310,"y":140,"wires":[["6383dbad.370dc4"]]}]

```

---

<div class="post-metadata">

**Author:** ![jbudd](https://avatars.discourse-cdn.com/v4/letter/j/5f8ce5/32.png) [@jbudd](https://discourse.nodered.org/u/jbudd)\
**Post date:** [22 April 2022 19:10 UTC](https://discourse.nodered.org/t/rasberry-pi-gpio-pins-not-switching/61658/4 "2022-04-22T19:10:08Z")

</div>

Thanks! I'm in my phone just now so I can't look at the flow but my first thought is whether your relays work with 3.3V and the very low current from a Pi gpio pin.

The current node red version is 2.2.2 so if you are on 1.0.6 it's probably a good idea to run the installation script to update NR and node.js, then update your nodes individually in palette manager.

---

<div class="post-metadata">

**Author:** ![dceejay](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/dceejay/32/38_2.png) [@dceejay](https://discourse.nodered.org/u/dceejay)\
**Post date:** [22 April 2022 19:35 UTC](https://discourse.nodered.org/t/rasberry-pi-gpio-pins-not-switching/61658/5 "2022-04-22T19:35:28Z")

</div>

There have definitely been updates to the gpio nodes recently to do with the latest raspiOS and it’s use of python 3. So it is probably worth upgrading, and ensuring you have the latest gpio nodes as well.

---

<div class="post-metadata">

**Author:** ![ghayne](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/ghayne/32/39_2.png) [@ghayne](https://discourse.nodered.org/u/ghayne)\
**Post date:** [22 April 2022 19:47 UTC](https://discourse.nodered.org/t/rasberry-pi-gpio-pins-not-switching/61658/6 "2022-04-22T19:47:20Z")

</div>

> [@Jsimon003](#):
>
> How do you know that the pins do not change state?  
> Because the relay constantly stay on even though I inject a 0

Apart from the advice above from @dceejay regarding upgrading, which you really should follow, can you measure the voltage on the GPIO pins with a multi-meter to see if they are turning on and off? @jbudd's question whether the relays work on 3.3V is important too.

---

<div class="post-metadata">

**Author:** ![Jsimon003](https://avatars.discourse-cdn.com/v4/letter/j/7ea924/32.png) [@Jsimon003](https://discourse.nodered.org/u/Jsimon003)\
**Post date:** [22 April 2022 20:28 UTC](https://discourse.nodered.org/t/rasberry-pi-gpio-pins-not-switching/61658/7 "2022-04-22T20:28:51Z")

</div>

I have updated to node-red 2.2.2 and ensured the GPIO palette was updated with no change. Every digital pin on the Rasberry pi is reading 3.3 volts. When I unplug the wire coming from the relay to the Rasberry pi the relay turns off. I switch the wire to another pin on the Rasberry pi and the relay activates again even though that pin is not in use.

---

<div class="post-metadata">

**Author:** ![ghayne](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/ghayne/32/39_2.png) [@ghayne](https://discourse.nodered.org/u/ghayne)\
**Post date:** [22 April 2022 20:31 UTC](https://discourse.nodered.org/t/rasberry-pi-gpio-pins-not-switching/61658/8 "2022-04-22T20:31:13Z")

</div>

Which relay are you using?  
And how are you configuring the GPIO pins in node-red?

---

<div class="post-metadata">

**Author:** ![Jsimon003](https://avatars.discourse-cdn.com/v4/letter/j/7ea924/32.png) [@Jsimon003](https://discourse.nodered.org/u/Jsimon003)\
**Post date:** [22 April 2022 21:03 UTC](https://discourse.nodered.org/t/rasberry-pi-gpio-pins-not-switching/61658/9 "2022-04-22T21:03:37Z")

</div>

im using a sainsmart 12volt relay. attached is the code im using.

```auto
`[{"id":"1def1387.cd722c","type":"tab","label":"Flow 1","disabled":false,"info":""},{"id":"a04aa8dc.1f7988","type":"inject","z":"1def1387.cd722c","name":"","topic":"","payload":"0","payloadType":"num","repeat":"","crontab":"","once":false,"onceDelay":0.1,"x":310,"y":220,"wires":[["6383dbad.370dc4"]]},{"id":"6383dbad.370dc4","type":"rpi-gpio out","z":"1def1387.cd722c","name":"","pin":"40","set":"","level":"0","freq":"","out":"out","x":570,"y":200,"wires":[]},{"id":"7ebaf35.02cca0c","type":"inject","z":"1def1387.cd722c","name":"","topic":"","payload":"1","payloadType":"num","repeat":"","crontab":"","once":false,"onceDelay":0.1,"x":310,"y":140,"wires":[["6383dbad.370dc4"]]}]`

```

---

<div class="post-metadata">

**Author:** ![ghayne](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/ghayne/32/39_2.png) [@ghayne](https://discourse.nodered.org/u/ghayne)\
**Post date:** [22 April 2022 21:22 UTC](https://discourse.nodered.org/t/rasberry-pi-gpio-pins-not-switching/61658/10 "2022-04-22T21:22:39Z")

</div>

Have you measured the pin with a multi-meter, without attaching the relay?

---

<div class="post-metadata">

**Author:** ![Jsimon003](https://avatars.discourse-cdn.com/v4/letter/j/7ea924/32.png) [@Jsimon003](https://discourse.nodered.org/u/Jsimon003)\
**Post date:** [22 April 2022 21:23 UTC](https://discourse.nodered.org/t/rasberry-pi-gpio-pins-not-switching/61658/11 "2022-04-22T21:23:01Z")

</div>

yes its 3.3 volts

---

<div class="post-metadata">

**Author:** ![ghayne](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/ghayne/32/39_2.png) [@ghayne](https://discourse.nodered.org/u/ghayne)\
**Post date:** [22 April 2022 21:23 UTC](https://discourse.nodered.org/t/rasberry-pi-gpio-pins-not-switching/61658/12 "2022-04-22T21:23:37Z")

</div>

And when you inject 0?

---

<div class="post-metadata">

**Author:** ![Jsimon003](https://avatars.discourse-cdn.com/v4/letter/j/7ea924/32.png) [@Jsimon003](https://discourse.nodered.org/u/Jsimon003)\
**Post date:** [22 April 2022 21:46 UTC](https://discourse.nodered.org/t/rasberry-pi-gpio-pins-not-switching/61658/13 "2022-04-22T21:46:46Z")

</div>

so I did a little more testing with the multi meter. The GPIO pins do change when I inject the 0 and 1. It seems the issue is in the relay board somewhere. I had a ground wire running to the relay board from the pi ground and a wire running from GPIO pin 40 to a pin on the relay board. I removed the ground wire because that was wrong. Theres an LED on the relay board to tell me when its active or not. The LED is only half lit. When I had the ground attached it was fully lit. I think my problem is trying to find out where to put my ground wire.

---

<div class="post-metadata">

**Author:** ![Jsimon003](https://avatars.discourse-cdn.com/v4/letter/j/7ea924/32.png) [@Jsimon003](https://discourse.nodered.org/u/Jsimon003)\
**Post date:** [22 April 2022 22:00 UTC](https://discourse.nodered.org/t/rasberry-pi-gpio-pins-not-switching/61658/14 "2022-04-22T22:00:38Z")

</div>

so I hooked everything to a 5v relay using the 5v GPIO pin on the Rasberry pi and it worked

---

<div class="post-metadata">

**Author:** ![iiot2k](https://avatars.discourse-cdn.com/v4/letter/i/8baadc/32.png) [@iiot2k](https://discourse.nodered.org/u/iiot2k)\
**Post date:** [22 April 2022 22:31 UTC](https://discourse.nodered.org/t/rasberry-pi-gpio-pins-not-switching/61658/15 "2022-04-22T22:31:03Z")

</div>

Again, the max. current that the Rpi can drive is 50mA (on Rail)!  
Each pin can drive 16mA.  
You can also use only 3 output pins.  
More current damage the output driver.  
At moment to buy a Rpi isn't easy.

---

<div class="post-metadata">

**Author:** ![Sean-McG](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/sean-mcg/32/54677_2.png) [@Sean-McG](https://discourse.nodered.org/u/Sean-McG)\
**Post date:** [23 April 2022 08:03 UTC](https://discourse.nodered.org/t/rasberry-pi-gpio-pins-not-switching/61658/16 "2022-04-23T08:03:25Z")

</div>

Do you have a 12Volt power supply for the relay board ?  
Why was the ground wrong ?  
The ground pin on the 12V PSU, the Rpi and the relay board should all be connected together.

---

<div class="post-metadata">

**Author:** ![ghayne](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/ghayne/32/39_2.png) [@ghayne](https://discourse.nodered.org/u/ghayne)\
**Post date:** [23 April 2022 09:03 UTC](https://discourse.nodered.org/t/rasberry-pi-gpio-pins-not-switching/61658/17 "2022-04-23T09:03:13Z")

</div>

> [@Jsimon003](#):
>
> so I hooked everything to a 5v relay using the 5v GPIO pin on the Rasberry pi and it worked

The Rasperry Pi does not have 5V GPIO's:

[Raspberry Pi GPIO Pinout: What Each Pin Does on Pi 4, Earlier Models | Tom's Hardware](https://www.tomshardware.com/uk/reviews/raspberry-pi-gpio-pinout,6122.html#:~:text=The%20operating%20voltage%20of%20the,GPIO%20pin%2C%20via%20a%20resistor).

---

<div class="post-metadata">

**Author:** ![Sean-McG](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/sean-mcg/32/54677_2.png) [@Sean-McG](https://discourse.nodered.org/u/Sean-McG)\
**Post date:** [23 April 2022 14:56 UTC](https://discourse.nodered.org/t/rasberry-pi-gpio-pins-not-switching/61658/18 "2022-04-23T14:56:35Z")

</div>

I have a feeling that the OP means the 5V power pin - which will not be enough to drive the relays properly.

---

<div class="post-metadata">

**Author:** ![gerry](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/gerry/32/21604_2.png) [@gerry](https://discourse.nodered.org/u/gerry)\
**Post date:** [23 April 2022 15:34 UTC](https://discourse.nodered.org/t/rasberry-pi-gpio-pins-not-switching/61658/19 "2022-04-23T15:34:39Z")

</div>

I have a feeling that the OP means the 5V power pin - which will not be enough to drive the relays properly.  
Not sure about that statement, maybe I didn't read close enough but I didn't see board specs. I would be curious about the interconnects though. Besides current draw there might be ground loop issues. Sometimes plug and play - isn't. Half lit led's is an obvious problem.

---

<div class="post-metadata">

**Author:** ![Sean-McG](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/sean-mcg/32/54677_2.png) [@Sean-McG](https://discourse.nodered.org/u/Sean-McG)\
**Post date:** [24 April 2022 03:30 UTC](https://discourse.nodered.org/t/rasberry-pi-gpio-pins-not-switching/61658/20 "2022-04-24T03:30:53Z")

</div>

> [@Jsimon003](#):
>
> sainsmart 12volt relay

half lit LED not unexpected 🙂

[Next page](https://discourse.nodered.org/t/rasberry-pi-gpio-pins-not-switching/61658.md?page=2)
