Power supply control

Discuss development of drivers for external hardware and components, such as LCD screens, sensors, motor drivers, etc.
Target audience: Users and developers of drivers.
Dyr-El
Posts: 1
Joined: Mon Oct 26, 2015 8:44 am

Power supply control

Post by Dyr-El » Mon Oct 26, 2015 8:56 am

Hi!

New to the forum, but I skimmed through it in search of anyone trying to control power supply for appliances (in my case fridge and low effect heater).

The project is a temperature controller for a fermentation station of my home brewery. (Yes I could do it manually but what would be the fun?). I have seen some contibuted temperature sensor drivers, but I want to be able to control the temperature inside a fridge. The normal way to do this is just by setting it to minimum temperature and then controlling the power supply. Then I would like to add a small heater (heat lamp from a terrarium is probably enough since the fridge is insulated).

But what I need is to control the power outlet with two channels, anone done anything similar?

User avatar
dhylands
Posts: 2494
Joined: Mon Jan 06, 2014 6:08 pm
Location: Shuswap, BC, Canada
Contact:

Re: Power supply control

Post by dhylands » Mon Oct 26, 2015 4:51 pm

Just turning something on or off can be done with a relay or a SSR (Solid state relay).

You can get ready-made relays for controlling 120v AC: https://www.sparkfun.com/products/10747

Or you can use an SSR dierctly: https://www.sparkfun.com/products/13015

When you use a real mechanical relay, you generally need a diode across the coils, and you use a GPIO to control a transistor/MOSFET which is the thing which actually controls the relay.

User avatar
ernitron
Posts: 84
Joined: Fri Jun 03, 2016 5:53 pm
Location: The Netherlands

Re: Power supply control

Post by ernitron » Sun Jul 10, 2016 1:38 pm

Hi. I just start contributing to the forum so forgive me if I am late and your project has already done.

First an assumption: I am always looking for the most simple, reliable and cost effective way to solve problems. My mantra is: if something can be done simpler and with less components just do it (other would say Keep It Simple Stupid ;)

In this case I just would use:
- ESP8266 (of course ;) I use a WeMos as it is very reliable and fits with serial drivers in Ubuntu very easily . Aliexpress WeMos ;)
- Relay : I use this http://www.aliexpress.com/item/1PCS-fre ... 65e5e97b45
- Temperature sensor DS18B20: I use this http://www.aliexpress.com/item/Free-Shi ... 15885.html (don't forget the 4.7kohm resistor)

Some other spare components like
- usb charger + short usb cable
- electric plug
-

Electrically you should connect:
ESP GND - RELAY -
ESP 5V - RELAY +
ESP D4 - RELAY S
ESP 3.3V - DS18b20 +
ESP D4 - DS18b20 data
ESP GND - DS18b20 -

Total BoM cost is around 10US$.

Besides that there is the software which is very fun. Basically it will be a loop like

while True:
... get temperature
... if temperature < THRESHOLD:
... do something
... else:
... do something else
... DEEP SLEEP for sometime

Result is this (my assembly) https://www.dropbox.com/s/6jpklux5ua2i6 ... 4.jpg?dl=0

User avatar
deshipu
Posts: 1219
Joined: Thu May 28, 2015 5:54 pm

Re: Power supply control

Post by deshipu » Sun Jul 10, 2016 10:11 pm

You shouldn't connect a relay to ESP8266's pins directly. Not only the coil draws much more current than the pins can safely provide, but it also feeds back a powerful back-current spike when it works, which can damage your board even easier. The solution to that is to connect the coil through a transistor (NPN or a mosfet), there are lots of examples of that on the Internet, and even some ready relay modules that already include the transistor.

User avatar
pythoncoder
Posts: 1962
Joined: Fri Jul 18, 2014 8:01 am

Re: Power supply control

Post by pythoncoder » Mon Jul 11, 2016 7:23 am

Looking at the link for the relay it appears to have some kind of driver on the PCB so perhaps it is suitable for the job. Technical details are somewhat scarce though, unless I'm missing something.
Peter Hinch

User avatar
Roberthh
Posts: 761
Joined: Sat May 09, 2015 4:13 pm
Location: Rhineland, Europe

Re: Power supply control

Post by Roberthh » Mon Jul 11, 2016 9:15 am

A better description and a (wrong) schematic is here: http://tinkbox.ph/sites/tinkbox.ph/file ... KY-019.pdf
It shows an NPN transistor (collector/emitter drawn wrong) switching the relay coil including the recovery diode.

User avatar
pythoncoder
Posts: 1962
Joined: Fri Jul 18, 2014 8:01 am

Re: Power supply control

Post by pythoncoder » Tue Jul 12, 2016 7:09 am

Oh dear, that's very topsy-turvy ;) Assuming the transistor is correctly wired it should work with the Pyboard: the one caveat is that it's specified for a 5V minimum control voltage. Whether it will work with the Pyboard's 3.3V output levels will depend on the transistor's gain. A quick and dirty fix might be to short out the LED which would give the transistor about 16mA of drive.
Peter Hinch

EasyRider
Posts: 73
Joined: Wed Dec 30, 2015 8:17 am

Re: Power supply control

Post by EasyRider » Tue Jul 12, 2016 8:32 am

Some of those relay modules use PNP transistors that need switching down from supply voltage, in which case GPIO high state (relay OFF) must be at supply voltage (5v).

NPN should be OK.

User avatar
Roberthh
Posts: 761
Joined: Sat May 09, 2015 4:13 pm
Location: Rhineland, Europe

Re: Power supply control

Post by Roberthh » Tue Jul 12, 2016 9:46 am

I was thinking whether it was designed as an emitter-follower, trying to save the costs for two resistors. For a 5 V signal that would work, even if not really well, but not if driven from a 3.3 V device. The voltage at the relay would be like 2.6 V, which might be too low for operation.

User avatar
pythoncoder
Posts: 1962
Joined: Fri Jul 18, 2014 8:01 am

Re: Power supply control

Post by pythoncoder » Tue Jul 12, 2016 9:52 am

With an incorrect schematic everything is up for grabs. However two things point to an NPN transistor incorrectly drawn. The (Chinglish) spec says that a logic 1 is required to actuate the relay, and the polarity of the LED confirms this.

Confucius he say: "To make the coil of relay energized you must need to have an input of 1 in the signal pin."
Peter Hinch

Post Reply