danro
Posts: 3
Joined: Tue Feb 07, 2017 9:54 am
Location: Southampton, England

GPIO pins seem to be dying one by one

Thu May 11, 2017 6:40 am

Hi all
I have an early raspberry pi. It is fab as it is currently monitoring the temperature of my office and manages door access via web page, relay and 12v electronic door latch.
It is this door latch I'm having issues with.
I have it wired as shown
Image
Nice and simple, I'm hooked onto pin 23 with a 5v feed and ground.
I'm running a web server with this code

Code: Select all

  <?php
         if(isset($_GET['open'])){
                 $btn = exec('gpio -g write 23 1');
                 usleep(250000);
                 $btn = exec('gpio -g write 23 0');
                // echo "Door is open<br />";
		 header("Location:index.php");
                } 

?> 


 <head>
 <meta name="viewport" content="width=device-width" />
 <title>Dans Den Door Control</title>
 <style>
.btn {
  background: #3498db;
  background-image: -webkit-linear-gradient(top, #3498db, #2980b9);
  background-image: -moz-linear-gradient(top, #3498db, #2980b9);
  background-image: -ms-linear-gradient(top, #3498db, #2980b9);
  background-image: -o-linear-gradient(top, #3498db, #2980b9);
  background-image: linear-gradient(to bottom, #3498db, #2980b9);
  -webkit-border-radius: 28;
  -moz-border-radius: 28;
  border-radius: 28px;
  font-family: Arial;
  color: #ffffff;
  font-size: 48px;
  padding: 10px 20px 10px 20px;
  text-decoration: none;
}

.btn:hover {
  background: #3cb0fd;
  background-image: -webkit-linear-gradient(top, #3cb0fd, #3498db);
  background-image: -moz-linear-gradient(top, #3cb0fd, #3498db);
  background-image: -ms-linear-gradient(top, #3cb0fd, #3498db);
  background-image: -o-linear-gradient(top, #3cb0fd, #3498db);
  background-image: linear-gradient(to bottom, #3cb0fd, #3498db);
  text-decoration: none;
}
 </style>
 </head>
         <body>
         <form method="get" action="index.php">
                <!--input type="submit" value="ON" name="on">
                <input type="submit" value="OFF" name="off"-->
                <input type=submit class=btn name="open" value="Open Door">
         </form>
   </body>
</html>
I go to this page on my phone and I'm presented with a button that when pressed releases the latch for a short time, opening the door.
Which works..... for a while.
Then the pin seems to die.
I've replaced the relays and no change
Changed the pin number and it works... for a while.

I can only assume I got something wrong and I'm killing the board one pin at a time - I'm on my third pin!
..or I have a duff board - it was bought 2nd hand so has an unknown past.
Any help or advice greatly received :)

Many thanks
Danny

User avatar
DougieLawson
Posts: 38883
Joined: Sun Jun 16, 2013 11:19 pm
Location: A small cave in deepest darkest Basingstoke, UK
Contact: Website Twitter

Re: GPIO pins seem to be dying one by one

Thu May 11, 2017 8:39 am

Does that relay have opto-isolation? If not then you're risking sending 5V into a 3V3 GPIO and that will slowly let the magic blue smoke out one GPIO pin at a time until your RPi dies a sad and untimely death.

You need opto-isolation or a NPN transistor or a MOSFET between your RPi and your relay and a reversed diode across the relay coil. The GPIO switches that intermediate hardware, the output side of that switches the relay. The diode blocks the back emf when the relay coil is de-energised.
Note: Any requirement to use a crystal ball or mind reading will result in me ignoring your question.

Criticising any questions is banned on this forum.

Any DMs sent on Twitter will be answered next month.
All non-medical doctors are on my foes list.

YCN-
Posts: 246
Joined: Fri Jun 10, 2016 3:18 pm

Re: GPIO pins seem to be dying one by one

Thu May 11, 2017 8:42 am

You should grab a mutimetter and measure voltage and current, and compare them to what the rpi is supposed to handle. Normaly you shouldn't see any thing wrong but who knows?
How did you plugged the relay with your GPIO ?

YCN-

pcmanbob
Posts: 9298
Joined: Fri May 31, 2013 9:28 pm
Location: Mansfield UK

Re: GPIO pins seem to be dying one by one

Thu May 11, 2017 10:07 am

Hi.

looking at the relay board ( from what I can see ) I very much doubt it has an opto-isolator on the control input, so you are applying 5v to the gpio pin which is why they are failing.
If you want to protect your gpio/Pi and keep using this relay then you need to use a transistor to act as an interface between the gpio and relay board.
Here's the circuit you need to build.
Image
We want information… information… information........................no information no help
The use of crystal balls & mind reading are not supported

User avatar
DougieLawson
Posts: 38883
Joined: Sun Jun 16, 2013 11:19 pm
Location: A small cave in deepest darkest Basingstoke, UK
Contact: Website Twitter

Re: GPIO pins seem to be dying one by one

Thu May 11, 2017 10:18 am

pcmanbob wrote: Image
Is there any specific reason you're using an NPN transistor rather than a MOSFET?

This video https://www.youtube.com/watch?v=9Qumu2h8FjY&t=95s explains lots of stuff for the OP, it's 53 minutes that won't be wasted.
Note: Any requirement to use a crystal ball or mind reading will result in me ignoring your question.

Criticising any questions is banned on this forum.

Any DMs sent on Twitter will be answered next month.
All non-medical doctors are on my foes list.

danro
Posts: 3
Joined: Tue Feb 07, 2017 9:54 am
Location: Southampton, England

Re: GPIO pins seem to be dying one by one

Thu May 11, 2017 11:17 am

Thanks for you prompt responses.
@Dougie
The relay in the pic, that I have been using does not. this is the first I have heard about opto-isolation (I'm still very much learning!).
However, I do have some that seem to have the isolation chips - I think? Heres a pic.
Image

If I were to use this do I need to wire it differently?
I have a jumper over the JD-VCC and VCC and a GND, then there is another bank of pins that I would use GND, IN1, IN2 VCC

@YCN
When I put a meter between the GND and signal pins and open the door I get 3.17v momentarily, then 0v.

danro
Posts: 3
Joined: Tue Feb 07, 2017 9:54 am
Location: Southampton, England

Re: GPIO pins seem to be dying one by one

Thu May 11, 2017 1:04 pm

Thanks Dougie for the link to the video.
I have invested my time watching it and will go over it again and there was so much to take in - it has been bookmarked.

Regards
Danny

User avatar
DougieLawson
Posts: 38883
Joined: Sun Jun 16, 2013 11:19 pm
Location: A small cave in deepest darkest Basingstoke, UK
Contact: Website Twitter

Re: GPIO pins seem to be dying one by one

Thu May 11, 2017 1:07 pm

danro wrote:Thanks for you prompt responses.
@Dougie
The relay in the pic, that I have been using does not. this is the first I have heard about opto-isolation (I'm still very much learning!).
However, I do have some that seem to have the isolation chips - I think? Heres a pic.
Image
This is the circuit diagram for that relay board.
Image

The important thing is not to jumper JD-VCC to VCC or you negate the opto-isolation.
Note: Any requirement to use a crystal ball or mind reading will result in me ignoring your question.

Criticising any questions is banned on this forum.

Any DMs sent on Twitter will be answered next month.
All non-medical doctors are on my foes list.

gregeric
Posts: 1509
Joined: Mon Nov 28, 2011 10:08 am

Re: GPIO pins seem to be dying one by one

Thu May 11, 2017 1:10 pm

If your original board is the same as this one, which it appears to be, then I suspect the reason your GPIO goes pop eventually is more likely because you're drawing too much current, not because somehow 5V is magically finding its way back to the GPIO. Looking closely at the picture, it looks like there's an LED & 150R resistor in series with the base of an NPN transistor switching the relay coil. The listing states 15-20mA to turn it on, confirmed by the resistor value when driven from TTL logic: 5V less 0.65V for the base-emitter junction's Vf, less 1.8V for red LED's Vf, equals 2.55V; divide that by 150R gives you 17mA.

If you configure the Pi's GPIO pin drive strength to the full 16mA you may find it's OK.

I don't think pcmanbob's circuit will work, as the 10k resistor will limit the current into the base of the relay board's transistor to a mere 250uA.

Either re-configure bob's 2N2222 to form a Darlington pair when wired to the board for more current gain, or use a PNP transistor or p-channel MOSFET as high-side switches feeding the relay board's base current.

Yes, those four-pin devices appear to be opto-isolators. That'll be fine: less demanding on the GPIO as you only have to provide enough current to illuminate a small LED inside the package. Plus protection by virtue of electrical isolation.

pcmanbob
Posts: 9298
Joined: Fri May 31, 2013 9:28 pm
Location: Mansfield UK

Re: GPIO pins seem to be dying one by one

Thu May 11, 2017 4:02 pm

DougieLawson wrote:
pcmanbob wrote: Image
Is there any specific reason you're using an NPN transistor rather than a MOSFET?

This video https://www.youtube.com/watch?v=9Qumu2h8FjY&t=95s explains lots of stuff for the OP, it's 53 minutes that won't be wasted.
Relay board only needs a small current probably less that 15mA so 2n2222 is easy capable of providing the 5v at the low current to the relay so protecting the GPIO from 5v.
2n2222 is readily available and cheap.
We want information… information… information........................no information no help
The use of crystal balls & mind reading are not supported

User avatar
davidcoton
Posts: 4909
Joined: Mon Sep 01, 2014 2:37 pm
Location: Cambridge, UK
Contact: Website

Re: GPIO pins seem to be dying one by one

Thu May 11, 2017 5:10 pm

It depends whether the relay input is active high (15mA source required) or active low (15mA sink required). While a small NPN transistor will sink 15mA for an active low relay board, the 10K resistor will not source more than 0.5mA at 5V for an active high input.

Use the opto-isolated board, separate the two supplies, use 5V on JD-Vcc, and check that a 3.3V supply to Vcc is adequate to switch it when the input is low. If not, reduce R1 on the relay board, or short IN1 (which will then not illuminate, of course). Don't try both mods at the same time!
Signature retired

gregeric
Posts: 1509
Joined: Mon Nov 28, 2011 10:08 am

Re: GPIO pins seem to be dying one by one

Thu May 11, 2017 5:15 pm

davidcoton wrote:If not, reduce R1 on the relay board, or short IN1 (which will then not illuminate, of course). Don't try both mods at the same time!
Or leave unmodded & use pcmanbib's circuit on that 2xrelay board :)

User avatar
gordon@drogon.net
Posts: 2020
Joined: Tue Feb 07, 2012 2:14 pm
Location: Devon, UK
Contact: Website

Re: GPIO pins seem to be dying one by one

Thu May 11, 2017 5:53 pm

Are you remembering to set the pin to output mode first? Pins default to input mode by default. I didn't see any mode changes in your script...
-Gordon
--
Gordons projects: https://projects.drogon.net/

User avatar
davidcoton
Posts: 4909
Joined: Mon Sep 01, 2014 2:37 pm
Location: Cambridge, UK
Contact: Website

Re: GPIO pins seem to be dying one by one

Thu May 11, 2017 6:44 pm

gregeric wrote:
davidcoton wrote:If not, reduce R1 on the relay board, or short IN1 (which will then not illuminate, of course). Don't try both mods at the same time!
Or leave unmodded & use pcmanbib's circuit on that 2xrelay board :)
I was trying to avoid having to solve the problem twice. :evil:
gordon@drogon.net wrote:Are you remembering to set the pin to output mode first? Pins default to input mode by default. I didn't see any mode changes in your script...
-Gordon
That would account for 5V getting to the pin and killing it, but not for the system having worked at some point. Worth checking, though.
Signature retired

User avatar
gordon@drogon.net
Posts: 2020
Joined: Tue Feb 07, 2012 2:14 pm
Location: Devon, UK
Contact: Website

Re: GPIO pins seem to be dying one by one

Thu May 11, 2017 6:55 pm

Incidentally...

(Not aimed at the OP, just in-general)

Some of these relay boards are rubbish. Really rubbish. Crap, terrible, and many many expletives deleted terrible.

Most are designed for 5v system (ie. Arduino). Some may end up putting 5v directly onto the Pi's GPIO pins. Some drive the Pi's GPIO pins so strongly, then when they're set to output and you write '1' to them, it doesn't turn the relay off (the ones that have negative logic), but instead raise the 3.3v line by a bit... These ones can be bludgeoned to made work by setting the pin output, and writing 0 to it, then to switch the relay, you set the pin to input mode....

There is a lot of cheap tat off ebay or directly via some magic carpet site from China. Almost ALL vendors LIE about the relays they sell. They mention 5v deeper in the description, but will happily use the word "Raspberry Pi" in the description while not actually saying its compatible.

I've seen far too many people stung by buying crap like this.

There are several GOOD and properly Pi Compatible relay boards out there, you just have to pay a bit more, but at least you get something designed for the Pi.

-Gordon
--
Gordons projects: https://projects.drogon.net/

Return to “Troubleshooting”