Saturday, May 23, 2015

AC Light Dimming and Fan Control with Raspberry Pi

I found this little handy ac dimmer module and wanted to test it out on a couple home automation projects I had.  Link Here $20-ish or best offer. First it didn't work with my LED lighting but worked great with the incandescent bulbs (up to 12A) and AC fans (up to 100w).  I really liked it because it has two options for an interface UART 9600 baud or 8 Digital input pins. 


So this opened up a couple projects that I had in mind besides just lighting.... I've been wanting to control a couple ceiling fans and implement a couple inline ducting fans to get some circulation flowing without using too much energy.
My brother is going to implement a bathroom fan controller based off of humidity and/or possible methane levels ;-P.  Also controlling the heat lamp of a reptile habitat is something I'm planning too.  That may be better with an esp8266. I wan't to hook up a mister for humidity control as well.
Now since there are a couple ways to control this you could make them smart by connecting them to a Raspberry Pi or Arduino. Or even just a UART to Wifi module (esp8266, usr232-t are a couple examples). The cheapest option is the esp wifi module ~$2 each. They have a couple I/O pins you can connect a temperature/humidty sensor giving it it's own smarts and to and pass on the serial message via wifi if you want some other device to get it going.  
Here's the explanation video of the current setup:


Here's the class I wrote in python to comunicate with the wifi module.  Since It's UDP it doesn't care for a response and doesn't take anytime to do the TCP handshake. I import this into my websocket webapp on my lightswitch pi

     class Dimmer():
	def __init__(self,ip,port=8080):
		self.dimmer = socket.socket(socket.AF_INET,socket.SOCK_DGRAM)
		self.min=0
		self.max=250
		self.current=0
		self.con=(ip,port)
		self.tempMax=255
	def setPercent(self,value):
		v = float(value)/100
		number = (self.max-self.min)*v+self.min
		print number
		self.dimmer.sendto(chr(int(number)),self.con)
		self.current = int(number)
	def getPercent(self):
		return self.current
Photos:
webApp served on the Rpi
Fan at 0%, 0 watts
Fan at 10%, 11 watts
Fan at 100%, 43.2 Watts

No comments:

Post a Comment