Zalaban
Posts: 4
Joined: Mon May 25, 2015 3:27 pm

Reading mains status through GPIO

Mon May 25, 2015 4:28 pm

I was wondering if somebody here could help me. I currently live in a third world country where electricity is not always readily available. The setup we currently have at our compound is the following:
  • One mains line
    Two generators
What I'm trying to do is to be able to see when each of those one is "ON"
The setup I have thought about to be able to do so is the following: I have connected three straight connections to the devices (110V) What I want to do is connect those lines on the GPIO so I can see when the electricity is "ON" (HIGH) or "OFF" (LOW/0)
I don't think that I can directly connect the mains into the GPIO as it might blow up.
My solution for that is to buy a 3.3v dc adapter, strip it and connect the connection through the dc adapter into the gpio.
I have found different DC adapters (different amps) and have no idea which one to buy....
My question is the following: Is it possible for me to connect the mains line (through a 3.3v dc adapter) directly on the GPIO port and how many amps can the adapter have as a max?

drgeoff
Posts: 9595
Joined: Wed Jan 25, 2012 6:39 pm

Re: Reading mains status through GPIO

Mon May 25, 2015 8:55 pm

By the questions you are asking it is clear that you should not be working on this project without the on-hand guidance and supervision of someone qualified and experienced in dealing with mains electricity. I am not worried about the possible destruction of a RPi. I am concerned about injury and even death of you and others.

An easy and safe way would be to use conventional 'wall-wart' PSUs giving anything in the range 5 to 15 volts DC and feed via a series resistor to an opto-isolator. The other side of the opto-isolator can be connected to a RPi GPIO. The current required from the PSU is less than 0.05 amps. It is no issue if the PSU can provide much more than that.

Zalaban
Posts: 4
Joined: Mon May 25, 2015 3:27 pm

Re: Reading mains status through GPIO

Mon May 25, 2015 9:24 pm

drgeoff wrote:By the questions you are asking it is clear that you should not be working on this project without the on-hand guidance and supervision of someone qualified and experienced in dealing with mains electricity. I am not worried about the possible destruction of a RPi. I am concerned about injury and even death of you and others.

An easy and safe way would be to use conventional 'wall-wart' PSUs giving anything in the range 5 to 15 volts DC and feed via a series resistor to an opto-isolator. The other side of the opto-isolator can be connected to a RPi GPIO. The current required from the PSU is less than 0.05 amps. It is no issue if the PSU can provide much more than that.
Hey drgeoff,

First of all thanks for your concern. I understand that I shouldn't play with mains power and that's the reason why I'm working with a dc adapter :) The opto-isolator option you have offered looks like it will work for my use case! Thanks!

Do you think this one might work? http://www.amazon.com/Numato-Lab-Opto-I ... o+isolator

ame
Posts: 3172
Joined: Sat Aug 18, 2012 1:21 am
Location: Korea

Re: Reading mains status through GPIO

Mon May 25, 2015 11:49 pm

drgeoff wrote:By the questions you are asking it is clear that you should not be working on this project without the on-hand guidance and supervision of someone qualified and experienced in dealing with mains electricity. I am not worried about the possible destruction of a RPi. I am concerned about injury and even death of you and others.

An easy and safe way would be to use conventional 'wall-wart' PSUs giving anything in the range 5 to 15 volts DC and feed via a series resistor to an opto-isolator. The other side of the opto-isolator can be connected to a RPi GPIO. The current required from the PSU is less than 0.05 amps. It is no issue if the PSU can provide much more than that.
He already said he would be using a 3.3Vdc adapter. There is no problem hooking that up to the Pi directly, and it's perfectly safe as it is not necessary to tamper with the mains portion.

However, I would recommend 5V adapters and either a voltage divider (5V -> 3.3V) or an optoisolator for the simple reason that 5V adapters (USB power supplies) are ubiquitous these days, and 3.3V adapters aren't. An optoisolator is the best option as it will isolate the Pi from voltage spikes or other nastiness on the mains supply.

johndough
Posts: 254
Joined: Sun Jan 13, 2013 2:00 pm

Re: Reading mains status through GPIO

Tue May 26, 2015 10:30 am

Hi

Just a thought, this may help...

The idea is to connect a relay to each power supply, at it’s rated voltage (110v).

Then take a supply of 3V3 from the Pi through each relay and with a resistor return it to the Pi if wanted, Connection 4. When the first power supply is in use the 3V3.(select a suitable resistor) is switched to an LED to show it’s on, probably a Red one. It can also be returned to the Pi as an input. The same applies to the other two, with different colour LED’s.

The logic is that whichever LED is Illuminated is the first Power source in use. You can use a second contact on the relay to switch into the Pi as well, just in case 2 or more power supplies are running.
If nothing is running then 4 wont be any use unless there is a battery to keep the Pi alive.

Obviously this method workd without a Pi and could utilise any voltage lamps, EG: 12 or 110 volts.





The attachment Monitor.PNG is no longer available
Attachments
Monitor.PNG
Monitor.PNG (11.06 KiB) Viewed 1935 times

User avatar
pluggy
Posts: 3635
Joined: Thu May 31, 2012 3:52 pm
Location: Barnoldswick, Lancashire,UK
Contact: Website

Re: Reading mains status through GPIO

Tue May 26, 2015 10:38 am

If it were me, I'd find something with a fitted mains neon indicator and stick a phototransistor over it. No mains voltages required and simpler and more efficient than a dc power supply.
Don't judge Linux by the Pi.......
I must not tread on too many sacred cows......

ame
Posts: 3172
Joined: Sat Aug 18, 2012 1:21 am
Location: Korea

Re: Reading mains status through GPIO

Tue May 26, 2015 11:14 am

All right, if you want super safe with no connections at all you could build this:
http://www.edn.com/design/power-managem ... ains-lines

The input is literally a bit of wire placed next to the live cable.

Follow this circuit with a diode as a half-wave rectifier and a simple lowpass filter and you have a digital indication of mains presence.

There is an Arduino version of this which I can't find at the moment, but i did build one and it does work. No transformers, no bulbs, nothing connected to the mains at all.


boyoh
Posts: 1297
Joined: Fri Nov 23, 2012 3:30 pm
Location: Selby. North Yorkshire .UK

Re: Reading mains status through GPIO

Tue May 26, 2015 7:54 pm

Zalaban wrote:I was wondering if somebody here could help me. I currently live in a third world country where electricity is not always readily available. The setup we currently have at our compound is the following:
  • One mains line
    Two generators
What I'm trying to do is to be able to see when each of those one is "ON"
The setup I have thought about to be able to do so is the following: I have connected three straight connections to the devices (110V) What I want to do is connect those lines on the GPIO so I can see when the electricity is "ON" (HIGH) or "OFF" (LOW/0)
I don't think that I can directly connect the mains into the GPIO as it might blow up.
My solution for that is to buy a 3.3v dc adapter, strip it and connect the connection through the dc adapter into the gpio.
I have found different DC adapters (different amps) and have no idea which one to buy....
My question is the following: Is it possible for me to connect the mains line (through a 3.3v dc adapter) directly on the GPIO port and how many amps can the adapter have as a max?
Is this correct you have mains input from two generators
Are both generators running at the same time, If so they
are AC alternators synchronized, If one is standby,and
the other on line , they will still synchronize when changing
over . I don't think you will able to tell witch is on line or
witch is off line, Can you give more information on the
setup
BoyOh ( Selby, North Yorkshire.UK)
Some Times Right Some Times Wrong

Zalaban
Posts: 4
Joined: Mon May 25, 2015 3:27 pm

Re: Reading mains status through GPIO

Sat May 30, 2015 1:47 pm

boyoh wrote:
Zalaban wrote:I was wondering if somebody here could help me. I currently live in a third world country where electricity is not always readily available. The setup we currently have at our compound is the following:
  • One mains line
    Two generators
What I'm trying to do is to be able to see when each of those one is "ON"
The setup I have thought about to be able to do so is the following: I have connected three straight connections to the devices (110V) What I want to do is connect those lines on the GPIO so I can see when the electricity is "ON" (HIGH) or "OFF" (LOW/0)
I don't think that I can directly connect the mains into the GPIO as it might blow up.
My solution for that is to buy a 3.3v dc adapter, strip it and connect the connection through the dc adapter into the gpio.
I have found different DC adapters (different amps) and have no idea which one to buy....
My question is the following: Is it possible for me to connect the mains line (through a 3.3v dc adapter) directly on the GPIO port and how many amps can the adapter have as a max?
Is this correct you have mains input from two generators
Are both generators running at the same time, If so they
are AC alternators synchronized, If one is standby,and
the other on line , they will still synchronize when changing
over . I don't think you will able to tell witch is on line or
witch is off line, Can you give more information on the
setup
Hey Boyoh,

Thanks for your message.
I indeed have two generators with a transfer switch which make sure only one of them can give electricity to my house grid at the time. What I did to be able to tell which one is online is to run a cable straight to each part of my puzzle.

So I currently have the following design:

Outlet ---> Gen 1
Outlet ---> Gen 2
Outlet ---> Transfer switch of generator
Outlet ---> Government grid
Outlet --> General mains line (Tansfer switch Grid / Gen)

I personally think that ame's solution is the best with a optoisolator as you won't have any direct electrical contact with the pi :)

So I'm going to buy a dc adapter for each of the outlets and connect it through an optoisolator!

boyoh
Posts: 1297
Joined: Fri Nov 23, 2012 3:30 pm
Location: Selby. North Yorkshire .UK

Re: Reading mains status through GPIO

Sun May 31, 2015 3:58 pm

Zalaban wrote:
boyoh wrote:
Zalaban wrote:I was wondering if somebody here could help me. I currently live in a third world country where electricity is not always readily available. The setup we currently have at our compound is the following:
  • One mains line
    Two generators
What I'm trying to do is to be able to see when each of those one is "ON"
The setup I have thought about to be able to do so is the following: I have connected three straight connections to the devices (110V) What I want to do is connect those lines on the GPIO so I can see when the electricity is "ON" (HIGH) or "OFF" (LOW/0)
I don't think that I can directly connect the mains into the GPIO as it might blow up.
My solution for that is to buy a 3.3v dc adapter, strip it and connect the connection through the dc adapter into the gpio.
I have found different DC adapters (different amps) and have no idea which one to buy....
My question is the following: Is it possible for me to connect the mains line (through a 3.3v dc adapter) directly on the GPIO port and how many amps can the adapter have as a max?
Is this correct you have mains input from two generators
Are both generators running at the same time, If so they
are AC alternators synchronized, If one is standby,and
the other on line , they will still synchronize when changing
over . I don't think you will able to tell witch is on line or
witch is off line, Can you give more information on the
setup
Hey Boyoh,

Thanks for your message.
I indeed have two generators with a transfer switch which make sure only one of them can give electricity to my house grid at the time. What I did to be able to tell which one is online is to run a cable straight to each part of my puzzle.

So I currently have the following design:

Outlet ---> Gen 1
Outlet ---> Gen 2
Outlet ---> Transfer switch of generator
Outlet ---> Government grid
Outlet --> General mains line (Tansfer switch Grid / Gen)

I personally think that ame's solution is the best with a optoisolator as you won't have any direct electrical contact with the pi :)

So I'm going to buy a dc adapter for each of the outlets and connect it through an optoisolator!
This circuit might do the job, Power supply adapters
switching one common RPI IN/PUTS
Witch ever power adapter is on, will give a
Active 0( low) in/put to one of the Pi selected in/puts
Attachments
RPI - Copy (2).jpg
RPI - Copy (2).jpg (28.31 KiB) Viewed 1761 times
BoyOh ( Selby, North Yorkshire.UK)
Some Times Right Some Times Wrong

Zalaban
Posts: 4
Joined: Mon May 25, 2015 3:27 pm

Re: Reading mains status through GPIO

Mon Jun 01, 2015 7:03 pm

boyoh wrote: This circuit might do the job, Power supply adapters
switching one common RPI IN/PUTS
Witch ever power adapter is on, will give a
Active 0( low) in/put to one of the Pi selected in/puts

Hey Boyoh,

Am I correct when I see that you've incorporated an optoisolator into your design?
What do you think about ame's possible solution of directly connecting the 3.3v dc adapter into the GPIO pin?

boyoh
Posts: 1297
Joined: Fri Nov 23, 2012 3:30 pm
Location: Selby. North Yorkshire .UK

Re: Reading mains status through GPIO

Sat Jun 06, 2015 9:56 am

Zalaban wrote:
boyoh wrote: This circuit might do the job, Power supply adapters
switching one common RPI IN/PUTS
Witch ever power adapter is on, will give a
Active 0( low) in/put to one of the Pi selected in/puts

Hey Boyoh,

Am I correct when I see that you've incorporated an optoisolator into your design?
What do you think about ame's possible solution of directly connecting the 3.3v dc adapter into the GPIO pin?
BoyOh ( Selby, North Yorkshire.UK)
Some Times Right Some Times Wrong

boyoh
Posts: 1297
Joined: Fri Nov 23, 2012 3:30 pm
Location: Selby. North Yorkshire .UK

Re: Reading mains status through GPIO

Sat Jun 06, 2015 9:58 am

boyoh wrote:
Zalaban wrote:
boyoh wrote: This circuit might do the job, Power supply adapters
switching one common RPI IN/PUTS
Witch ever power adapter is on, will give a
Active 0( low) in/put to one of the Pi selected in/puts

Hey Boyoh,

Am I correct when I see that you've incorporated an optoisolator into your design?
What do you think about ame's possible solution of directly connecting the 3.3v dc adapter into the GPIO pin?
Attachments
Pi Circuit 1 001.jpg
Pi Circuit 1 001.jpg (54.92 KiB) Viewed 1662 times
BoyOh ( Selby, North Yorkshire.UK)
Some Times Right Some Times Wrong

Return to “Beginners”