loading

In this instructable, I show you how to add enhanced accessibility, intelligence and connectivity to an ordinary wall outlet. This is done with a combination of microcontrollers, Arduino, various sensors, ESP8266 and a mix of software packages. As I have designed this project in a sort of a modular fashion, you can try to build the whole project as it is or parts of it or even extend this project with more functionality.

Features

Light On/Off

Fan On/Off

Fan Speed Regulator

IR Remote Control

Touchscreen Display

Smartphone App

Twitter Alerts

SMS Alerts

Mood Lighting

Log to Cloud Platforms

Smart Algorithms

This is the second instructable in the series of IoT related instructables that I am writing on automating my house.

The first instructable is:

An inexpensive IoT enabler using ESP8266

https://www.instructables.com/id/An-inexpensive-IoT...

Step 1: Design Considerations

This project was conceived when I felt the need to automatically reduce the speed of an AC ceiling fan in the bedroom as temperature drops through the night. In Bangalore, where I live, during winters, I like to switch on the fan when I go to sleep. But early mornings, when the temperature drops, the fan makes it even colder. Which disturbs my sleep and I don't want to or cant get up to reduce the speed or switch off the fan since the wall socket is not close to the bed. So I needed a way to automatically shutoff the fan or reduce its speed in the mornings and thought of building one myself since there aren't any commercial products already available in the market. I know, I know, there are bigger problems to solve in this world, but I guess this problem needs solving too, so what the heck :)

Along with this initial requirement, the following were also considered while designing the project.

  • Should automatically reduce the speed of the fan based on the time elapsed or temperature drop.
  • Should still be able to operate physical switches.
  • Should be able to remotely control light and fan. IR remote is a necessity. Smartphone app is perhaps an indulgence.
  • Should be able to function independently.
  • If the board breaks down for any reason, before it can be fixed or properly uninstalled, it should still be possible to use the physical switches to operate the light and the fan without any changes.
  • Need to be able to switch off the board, when the house is going to be empty for extended periods of time (say vacation), but when switched on again, should again function properly without needing any manual intervention.
  • The board should update the state of the devices controlled properly irrespective of the mode of control - IR remote, smartphone app or physical switches.
  • Should not look too ugly or messy.

Step 2: Basics

What is an Arduino?

Arduino is an open-source electronic prototyping platform to create interactive electronic objects.

http://www.arduino.cc/

What is ATMEGA1284P-PU?

This is the microcontroller IC used in this project.

http://www.atmel.com/devices/ATMEGA1284P.aspx

What is ESP8266?

ESP8266 is a highly integrated chip designed for the needs of a new connected world. It offers a complete and self-contained Wi-Fi networking solution, allowing it to either host the application or to offload all Wi-Fi networking functions from another application processor.

https://espressif.com/en/products/esp8266/

http://mcuoneclipse.com/2014/10/15/cheap-and-simpl...

https://scargill.wordpress.com/?s=esp8266

What is MQTT?

MQTT is a machine-to-machine (M2M)/"Internet of Things" connectivity protocol. It was designed as an extremely lightweight publish/subscribe messaging transport. It is useful for connections with remote locations where a small code footprint is required and/or network bandwidth is at a premium. For example, it has been used in sensors communicating to a broker via satellite link, over occasional dial-up connections with healthcare providers, and in a range of home automation and small device scenarios.

http://mqtt.org/

http://en.wikipedia.org/wiki/MQTT

What is node-red?

Node-RED is a tool for wiring together hardware devices, APIs and online services in new and interesting ways.

http://nodered.org/

What is NetIO?

NetIO is a multi platform smartphone application, a generic remote controller for almost everything. It simply sends and reads strings over a network socket. You can easily communicate with microcontrollers or PCs connected to your LAN!

http://netio.davideickhoff.de/en/

What is Thingspeak?

ThingSpeak is an open source “Internet of Things” application and API to store and retrieve data from things using HTTP over the Internet or via a Local Area Network. With ThingSpeak, you can create sensor logging applications, location tracking applications, and a social network of things with status updates.

https://thingspeak.com/

Step 3: Proof of Concept

There is hardly any information on the web regarding how to control the speed of an AC fan electronically. One of the links I found, copied below, shows an image of a ceiling fan remote control circuit, but it does not contain an actual circuit diagram. It uses triacs to select the capacitor or combination of capacitors. Based on how much capacitance is in the circuit, the speed of the fan can be varied. For max speed, the input is directly connected to the fan.

http://leoricksimon.blogspot.in/2011/07/troublesho...

Then I bought a regular off-the-shelf fan regulator and took it apart. Found that it also uses capacitors to control the speed of a fan and the principle of operation is similar to the one in the link above.

Now I needed a triac circuit to mimic the turn of the knob on the off-the-shelf fan regulator. Found this link that talks about a simple way to turn on/off AC appliances using triacs:

https://www.instructables.com/id/Small-Triac-Switch...

Based on the above details, created a circuit that uses MOC3041 optocouplers to trigger BT136 triacs. Salvaged the capacitors from the off-the-shelf regulator and used them in this circuit. Based on which triacs are triggered, the amount of capacitance in the circuit can be varied thereby controlling the speed of the fan. In this proof of concept, I just added a IR receiver and a LM35 temperature sensor. It worked well. But there is no IoT connectivity and it was not ready for proper installation.

Please note that this is the first proof of concept board that I made. The rest of this instructable does not contain information about this, rather, it contains the details of the prototype that I made that also has IoT connectivity as well as many other features.

Step 4: Parts

ATMEGA1284P-PU microcontroller chip

ESP8266 ESP-01 module

ILI9341 TFT Touch SPI LCD screen

0.96" OLED i2c LCD screen

DHT11 or DHT22 sensor

5v relays

WS2812B LED strip

IR receiver

Active buzzer

BTA136 triacs

MOC3041 triacs

4N25 zero cross detectors

Bridge rectifier

DIP switches

Resistors

Capacitors

Breakaway male and female headers

PCBs

Enclosures

220v AC to 5v DC 2 Amps power supply module

Current transformer

LM1117 3.3v LDO voltage regulator

FTDI USB to TTL adapter cable

In addition to the above, another Arduino board (any model should be fine) is needed to install the bootloader on the ATMEGA1284P chip.

Step 5: Circuit

The circuit is split into two major parts:

1. First is the main microcontroller circuit. Only DC here.

2. Second is for all the AC components. Mix of AC and DC here.

This is a combination of various circuits I have found on the web. The only part of the circuit that I had to struggle with, as explained earlier, is the one for controlling the speed of a AC fan. Although I found a few variations of this circuit, I did not get a proper schematic. Hence, this part of the circuit needs a little explanation.

The basic idea is that the speed of the AC fan can be varied by using 250v AC capacitors in parallel. Depending on how much capacitance is in the circuit, the speed of the fan could be increased. Actually, it is the impedance or the capacitive reactance or some such thing that actually does the trick, but since I have little knowledge about that, I will refrain from even making an attempt to explain it here. In my circuit, you can notice that there are four MOC3041/BTA136 triacs. Each of the first three triacs is connected to capacitors of 1uF, 2uF and 3uF capacitors and then to the fan. The last is directly connected to the fan.

With this circuit, its possible to have 7 different speeds by triggering the triacs as needed.

  • Speed 0: None of the MOC3041 triacs are triggered.
  • Speed 1: Only the MOC3041 connected to 1uF is triggered.
  • Speed 2: Only the MOC3041 connected to 2uF is triggered.
  • Speed 3: Only the MOC3041 connected to 3uF is triggered.
  • Speed 4: MOC3041s connected to 1uF and 3uF are triggered.
  • Speed 5: MOC3041s connected to 2uF and 3uF are triggered.
  • Speed 6: MOC3041s connected to 1uF, 2uF and 3uF are triggered.
  • Speed 7: Only the MOC3041 directly connected to the fan is triggered.

Another thing about this circuit are the two zero cross detectors - one for the light and the the other for the fan. These are needed to check if the light or fan is actually switched on or off. Note that there are two physical 2-way switches on the wall socket that can still be used. When the state of the light or the fan is changed by/through the infrared remote or the smartphone app or the physical switches, it is the the zero cross detector circuits that actually detects whether the light or the fan is actually in the on or the off state.

The Kicad files of the circuits are available at https://github.com/tangophi/iot_wall_socket/tree/m...

Step 6: Wiring

Original Wiring

There was a 2-way switch for the light on this board as well as a 2-way switch on another wall socket near the door. The fan had only a 1-way switch and a fan speed regulator.

New Wiring

In the new scheme, the 2-way switch for the light near the door has been retained as it was. But the other 2-way switch for the light has been moved for fan's use. And the 1-way switch that was previously used for the fan is now used to control power to the IoT board.

Step 7: Code

The Arduino sketch for the ATMEGA1284P microcontroller and the source code for the firmware of the ESP8266 module is available at

https://github.com/tangophi/iot_wall_socket

The node-red code is available at

https://github.com/tangophi/iot_house

In addition to the above, the NetIO based smarphone app also needs to be build. But not sure how to share that code here. It is pretty easy to build the app. See the section on the smartphone app for more details.

Step 8: DIP Switch Settings

There are three DIP switches on the board. These need to be set correctly for various modes of operation:

Normal Operation

SW1: 1100

SW2: 1100

SW3: 01

Uploading sketch to Arduino

SW1: 0011

SW2: 0000

SW3: 01

Uploading firmware to ESP8266

SW1: 0000

SW2: 0011

SW3: 10

Step 9: Flashing the Firmware

Make sure the DIP switches are set properly and use Arduino IDE to upload the sketch to the ATMEGA1284p. And use ESP8266 SDK to flash the firmware to the ESP8266 module.

Instructions for both of these are available widely on the net and hence have not included them here.

Step 10: Node-red

node-red running on a Raspberry Pi acts as a coordinator and manages various IoT boards in the house. It does this by getting/sending MQTT messages from/to various boards as well as socket messages from a NetIO based smartphone app. It also acts as an interface to send data to thingspeak.com and to send tweet alerts.

The node-red flow in the repo contains nodes related to the IoT wall socket as well as nodes of other projects. The IoT wall socket related entities are labeled as socket1 in the node-red flow.

If a Raspberry Pi is not available to run node-red, a cloud platform such as IBM Bluemix can be used to host node-red. One advantage of using a cloud platform is that the IoT boards can be controlled from anywhere in the world easily.

Step 11: Smartphone App

The smartphone app is built using the NetIO Design Editor at http://netio.davideickhoff.de/editor

Once the app is designed, the NetIO app should be downloaded to your smartphone. Note that this is a paid app, but it does not cost much.

Whenever a button/switch/slider is pressed in the app, it will send a message through sockets to the Rpi box that is running node-red. The node-red application will process the messages and then send MQTT messages to the wall socket board.

For the smartphone app to work it should be in the same network as the IoT wall socket board.

It is possible to use the smartphone app from outside the local network. If the ISP allows incoming connections, it is just a simple matter of forwarding the socket port on the router. If the ISP does not allow incoming connections, then VPN can be used as a workaround.

Step 12: How It Works

This diagram shows a high level overview of this project.

Infrared remote

When the infrared remote is used, the IR signals generated by it are detected by the IR receiver in the board. And depending on the command, relays are either turned on or off to switch on/off the light or the fan. Also, various triacs are triggered to set the speed of the fan.

Smartphone app

The NetIo based app talks to node-red on the Raspberry Pi through sockets. Based on the command sent by the app, node-red triggers MQTT messages. Which are processed by the broker and sent to the ESP8266 module. Which in turn send the command through the serial port to the Arduino as json formatted strings.

Data logging

Data such as temperature, humidity and light/fan states are sent by the Arduino to the ESP8266 module as json strings. The ESP8266 modules makes MQTT messages out of this data and sends them to node-red via the broker. For temperature and humidity readings, node-red collates them and sends one set of readings per a predetermined interval to thingspeak.com via http.

Twitter Alerts

When the security alarm goes off, node-red sends an alert to Twitter and the account holder as well as all those who are following him will get a tweet.

SMS Alerts

If SMS notifications is enabled in Twitter account settings, then whenever a alert is sent, a SMS alert is also sent to the registered mobile number.

Step 13: Operations

The board can be operated in any of the following ways. Some functionality that is available in one method may not be available in others.

1. Touch screen operation

  • The light or the fan can be switched on/off just by touching the relevant image on the screen.
  • The speed of the fan can be increased or decreased by touching the Fast or Slow images.
  • Time alarm can be set by pressing the clock display on the screen for more than 2 seconds.
  • Light and Fan options can be accessed by pressing the relevant image for more than 2 seconds.
  • Security alarm can be activated by pressing the Alarm logo for more than 2 seconds.
  • Led strip can be switched on/off by pressing the LED logo. But its mode cannot be changed.
  • Debug messages can be enabled by pressing the bottom edge of the screen for more than 2 seconds.

2. IR Remote Control

  • Light/Fan/Led canbe switched on/off by pressing the relevant key.
  • Fan speed can be set directly by pressing keys 1 to 7 or by pressing the increase or decrease keys.
  • LED mode can be changed.
  • Big clock display can be activated.
  • Needs line of sight to work - similar to how normal TV remote works.

3. Smartphone App

  • Light/Fan/Led canbe switched on/off by sliding the relevant switches
  • Fan speed can be set directly by using the slider.
  • LED mode can be changed.
  • LED color can be set
  • Can be used from anywhere in the network or even from outside the network - possibly from anywhere in the world.

4. Physical switches

  • Light and Fan can be switched on/off using the 2-way switches in the wall socket.
  • The board itself can be switched off using the switch on the wall socket.
  • If the board is switched off, the physical fan regulator can be used to change the fan speed.
  • If the board is switched on, the physical fan regulator should be set to max speed. The actual fan speed will be controlled by the board.

Step 14: Monitoring

The board logs temperature, humidity and power consumption readings once every 10 minutes to thingspeak.com. It also logs state of the light and the state and speed of the fan whenever they are changed.

https://thingspeak.com/channels/32932

Presently only Thingspeak.com is configured. If needed, nodes for other cloud services can also be added.

The following links have information on how to add nodes for various IoT cloud services:

http://logic.sysbiol.cam.ac.uk/?p=1473
http://logic.sysbiol.cam.ac.uk/teaching/Node-RED_...

Step 15: Smart Algorithms

1. Automatic Fan Speed Control

Various options to set the fan speed are available

  • Decrease fan speed by 1 step for every 1 degree drop in temperature.
  • Decrease fan speed by 2 steps for every 1 degree drop in temperature.
  • Decrease fan speed by 1 step every 90 minutes.
  • Decrease fan speed by 2 steps every 90 minutes.
  • Stop fan if temperature falls below the specified temperature.

2. Time alarm options

When the clock arm goes off, along with the buzzer, the following options can be set.

  • Switch on light.
  • Switch off fan.
  • Switch on fan and set it to maximum speed.

3. Automatic full screen clock display

During nights (when the fan is switched on and the light is switched off), if a movement is detected after 10 minutes of idleness, show the current time in full screen so that it is visible clearly from the bed.

Step 16: Security Alarm

The PIR motion detector can be used as a security alarm. The alarm can be "armed" when going out. And when the alarm is armed, and if motion is detected, the screen will show a keypad so that the security code can be entered. If the correct security code is entered within a minuted then the alarm is disarmed. But if the correct code is not entered within a minute, a tweet is sent along with activating the buzzer.

Also, a SMS message will be sent to the mobile number associated with the twitter account. This is achieved by enabling SMS notifications in Twitter account settings.

Step 17: Clock/Alarm

There is no RTC module on the board to provide current time. Instead, an event is triggered every minute that will send the current timestamp as a MQTT message to the board. And we extract the required info from the timestamp and use it to update time.

Features

  • Normally the clock is displayed in small font at the top right of the display. But to see the time from a distance, a key can be pressed on the IR remote to show just the current time in big font.
  • A clock alarm with options like switch on/off fan/light when it goes off can be configured by long press of the time window.
  • At nights, when the fan is on and the light is off, if movement is detected after an 10 minutes without detecting motion, the board will automatically display the clock in big font. So that it is readable from the bed.

Step 18: Mood Lighting

There is a strip of WS282b LEDS around the enclosure. These can be turned on to create various colors or patterns.

This mood lighting can be controlled through the following means:

1. Smartphone app can be used to turn on/off the LEDs, change pattern as well as changing the color.

2. IR remote can be used to turn on/off the LEDs and change the pattern.

3. Touchscreen can be used to just turn on/off the LEDS.

Step 19: Issues

Most of the functionality works fine. There are a couple of issues however:

1. A couple of BTA136 triacs used in this project have gone bad twice over the last couple of months. I replaced just those triacs and everything seems to be fine. However, I have not been able to determine what exactly caused these triacs to short out or if there is something inherently wrong with my circuit.

2. Power Consumption readings are mostly wrong. I guess there is too much noise in the circuit, since there are three relays and no opto-isolation for them. Guess the current transformer circuit needs to be isolated to prevent noise from other parts of the circuit interfering with the readings.

3. The PIR motion sensor is sometimes erratic. Even when there is no-one in the room, it detects motion. Probably due to the fact that its next to the window and the window shades. Tried tuning the sensor, but so far no luck.

Any help/suggestions on the above would be highly appreciated.

Step 20: Future Ideas

This is the second IoT project that I have done. The first one is a simple ESP8266 board with a relay and a temperature sensor. Details of the first project are available at

https://www.instructables.com/id/An-inexpensive-IoT...

I have also created a mood lighting project for my living room. Also modified two power strips by combining them with Arduino/ESP8266 and relays so that individual outlets can be remotely switched on or off. Photos of these two projects are included here. I will write instructables for them in the near future.

Further, I am also planning to automate the main wall socket in the living room similar to how i have done in this instructable for the bed room. In addition to all the existing features, I am going to add a IR transmitters as well more environmental sensors to that project. Later on, probably add some flame/gas sensors in the kitchen.

When all the hardware components are in place, several new algorithms/functionalities can be added. Such as:

1. At night, when the fan is switched on and the light is switched off in the bed room (meaning you are going to sleep), all appliances in other rooms should be automatically switched off.

2. When the security alarm is activated (when you are leaving the house), switch off all the appliances. Also, when the security alarm is deactivated (when you come back), turn on the appliances which normally would be turned on (bit of machine learning here).

3. Monitor sleep pattern by analyzing the data logged to the cloud. For example the time between the fan switched on in the night and it being switched off in the morning can be roughly counted as the sleep time.

4. Appliances like TV, cable, sound system and media player all need their own remote control (mostly IR based) and its cumbersome to deal with them. Instead write a smartphone app and map the keys of all the remotes by reading the code emitted by them. Then when a button is pressed in the app, it will send a message to the IR transmitter in the Arduino board to send the relevant code as IR signals to the appliances. One app to rule them all :)

5. Include footage from a security camera inside the house when sending intruder alarm alerts instead of just a plain text message.

Step 21: Conclusion

If you find this instructable useful in implementing any of your projects, it would be great if you could post some details as well as photos of them as comments.

If you have any questions/doubts, please kindly post them as a comments instead of sending a mail to my inbox. If its posted as a comment, it will be useful to all and I can reply as a comment as well.

Suggestions to improve this project as well as ideas for new features/functionalities are always welcome.

Cheers!

<p>Hi gopinath. I would like to include a circuit breaker so if a certain <br>current is exceeded, it breaks. Any ideas on how to include this?</p>
I am not an expert with electrical installations. But from what I understand, at a basic level, a circuit breaker works like a switch. That is if there is a short in the circuit, the circuit breaker will &quot;break&quot; the circuit just like an ordinary fuse does.<br><br>If thats the case, the circuit breaker should be installed on the &quot;lines&quot; wire before your 'project'. Hence if something goes wrong, then the circuit breaker can handle it.<br><br>But I would recommend you to talk to an expert in this field and review other online materials before you install a circuit breaker. Working with mains AC could be quite dangerous and unforgiving. And hence all precautions should be taken before you attempt to do it. If you are unsure about anything, I would strongly suggest you not to do it.
<p>Hello,</p><p>I fail to understand how you detect whether the light is presently on or off using a zero-crossing detection? Can you please elaborate the idea?</p>
There is a relay and a physical two way switch combination, one for the light and the other for the fan.<br><br>If we just use the relay to turn the light or fan on/off, we can be sure which state it is in. But if we also use the physical two way switch, then we cannot be sure. Because the relay may be turned ON, but the 2-way switch may be off. You really need to understand how 2-way switches work to understand this.<br><br>Anyway, that is the reason at the output of the relay/2-way switch, i use a zero cross detector to detect if current is actually flowing to the light or the fan. If it is, then it means the light or the fan is in a ON condition.
<p>hello can u share a clear circuit diagram i really wanted to implement it so i can clealry see the values and labels it would be kind of u sir </p>
<p>Which part of the circuit is not clear? When I posted this instructable, I had tried to get a circuit diagram which is readable. And I thought I had done that.</p><p>I am not sure how else I can improve it...</p>
humm ok brother .just cant see the resistor valeus tats y i asked any ways amazing work u hve done<br>
<p>I have uploaded the Kicad files for the circuits at <a href="https://github.com/tangophi/iot_wall_socket/tree/master/wall_socket_kicad" rel="nofollow">https://github.com/tangophi/iot_wall_socket/tree/m...</a></p><p>Check it out...</p>
<p>Hello Experts,</p><p>I have started working on ESP8266 and right now trying to run blink example using Ardunio IDE but we<br> have been struggling to execute application on ESP8266 and <br>our esp8266-01 is resetting again &amp; again with watchdog reset error<br>wdt reset<br>load 0x4010f000, len 1264, room 16<br>tail 0<br>chksum 0x42<br>csum 0x42<br>~ld<br> Setup don start<br><br>We have been using below schematic for the connection and here is the part number.<br><br><strong>ESP8266 01 wifi transceiver </strong></p>D-SUN &quot;USB to TTL&quot; (Blue)<p></p><p>Please advice how to proceed further. </p><p>On another ESP8266-01 I don't see output of AT command too .</p>
<p>I have never tried Arduino IDE way of programming ESP8266. I prefer the SDK method instead and thats the method I used in this instructable.</p><p>There are several Facebook groups, (ESP8266 for example) on which you can post this query. someone who has tried Arduino IDE may be able to help you out.</p>
<p>looks great.<br>I have the feeling that an ESP8266 and an arduino Mega and a raspberry might be a bit much just tto switch a light and afan, but I am sure there is more to come :-)</p>
<p>Thanks!</p><p>I agree that a Mega, ESP8266 and a Rpi is a bit too much to control just a light and a fan. I had initially started off with just an Arduino Pro Mini and a simple 7 segment display. Then I added a LCD screen. The project worked as expected.</p><p>But then I thought why not bling it up :)... Added a touch screen LCD, but found out that there is not enought flash memory available to support the display/touchscreen code as well do something useful .. hence moved to ATMEGA1284P... then added the ESP8266 module for connectivity.. And when i was exploring the easiest smartphone app to control this, i stumbled onto NetIO and node-red... Which needed a Rpi... The Rpi used in this project was already running as a file server, so didn't have to buy one exclusively for this... </p><p>I admit that I dont have a grand plan of things, just building various projects such as this one by one... And I hope the amalgamation of all of them might eventually will lead to something useful and unique..</p><p>Anyway, one of your instructables has been very helpful in designing the Fan speed control circuit and I have mentioned it in Step 3: proof of concept. In your instructable, you have used TIC206 triac. Since those triacs are not easily available here, I used BTA136 triac. And as mentioned in your instructable, I adjusted the resistor values accordingly.</p><p>Now the thing is, the circuit works fine as expected. But every few weeks or so, one or two of these triacs (please kindly see the circuit I have used in step 5) goes bad. That is, they become shorted and those triacs are always &quot;ON&quot;, does not matter whether it is triggered or not. I replaced just those triacs and everything works fine. But after a few weeks, one or two again goes bad and i have to replace them again. This has already happened 3 or 4 times.</p><p>My knowledge in this area is very limited and I hope you can provide me some insights in resolving this issue. Hence, I would really appreciate if you could help me with the following:</p><p>1. Are heat sinks necessary for BTA136, if it is used in a ceiling fan circuit? I think the current would not be that much given that this is a 220v circuit and the wattage of the fan is around 70-80 watts only. I have not really seen the triacs getting hot (or even warm for that matter), so i am not sure.</p><p>2. Are the resistor values used in the circuit, especially around the MOC3041 and BTA136 acceptable? I couldn't get the exact resistors, so have to make do with resistors that are near to the ones that you have recommended in your instructable.</p><p>3. I have just one common snubber for all the four triacs? Is this okay or should i need to have a common snubber for each one of them?</p><p>4. Can a BTA16, instead of BTA136, alleviate these issues?</p><p>5. I think BTA16 is scrubberless? If I use them, should i have to remove the scrubber from my circuit?</p><p>Thanks</p><p>Gopi</p>
<p>BTA136 can handle 4 amps. That should be ample for an 80 watt fan and it seems they should be able to handle that without getting hot. Yet a heatsink is always a good idea.<br>Your Triacs really shouldnt continue to blow. sadly though I have no idea how yoouy control your fan speed as I didnt see any circuit in yr ibble that shows that, other than a block diagram that doesnt tell me anything. From yr link, at best I understood you are using the triacs to short out capacitors.</p><p>with regard to the transistor values, i might have missed something in your ibble, but I cant really see what values you are using<br><br>If you have one common snubber for all triacs, I presume you have a snubber not for the triacs but for your motor.<br>I doubt if BTA16 would alleviate all yr problems as long as it is unclear what is causing your problem.<br><br>Could you perhaps expand a bit on how you regulate your fan? a citrcuit would be nice. If I overlooked it in your ibble can you please direct me to it. Same goes for the 'resistors around the MOC3041 and BTA'</p>
<p>Thanks for your response.</p><p>The detailed circuit diagram of the circuit is available in step 5 - there are two circuit diagrams here - one for the uc and its sensors and the other is for the relays and the fan speed control circuit.</p><p>Have also attached here for your reference. The basic idea is to use capacitors of various values in parallel. And depending on which of these capacitors are actually triggered (using triac), the speed of the fan can be controlled. something to do with capactive reactance or impedance or some thing like that.</p>
<p>I think it is not really necessary to have two zero detection circuits.</p><p>also, <br> you have the RC networks in series with the TRIAC. I am not sure if <br>that will work. Fans are notoriously difficult for triacs, but it can be <br> done. However, with an TC network in series I really do not know what <br>the behaviour is.<br><br>Also, apart from the fact that you do not need <br>two zero detection circuits... why would you do zero detection at all <br>for the fan? You are using the MOC3041. that has zero detection built <br>in, so you are just making it difficult on yourself.<br><br>You only <br>need to use your own zero detection if you want to dim a certain device <br>like an incandescent lamp. You just want to switch a TRIAC on or OFF so <br>you only need to write a 1 or a 0 to the entrance of yr circuit.<br>I <br>see you have an LED in series with your MOC3041. I had that in my <br>original design, and it works, but there is a chance for problems if u use a non red led. <br>The voltage drop over the LED might be too big then.</p><p>Also, <br> I get the distinct impression your circuit is not correct. I can't see <br>the TRIACS being fully in serial with anything, sure, they are <br>connected to the RC newtwork and that goes to the bridge rectifier, but <br> that's it</p>
<p>The zero cross detection circuits are not meant for dimming or even turning on/off the light or the fan.</p><p>The sole purpose of the two zero detection circuits (one for light and the other for fan) is to know if either the light or the fan are actually on or off. There are various ways to turn on/off the light or the fan. There are relays that are used along with the physical switches. So for example, if the light is turned on using the IR remote, the light relay is toggled on. But now, if the light is turned off using the physical switch on the wall outlet, I needed a way for the uc to update the state of the light. This is where the zero cross detectors come on. The state of the light or the fan inside the uc is solely based on the output of the zero cross detectors. </p><p>Anyway, again one of the BTA136 has gone bad. will try to see if I can get a BTA16 and use it instead. If that does not solve the issue in the long term, then I need to think of using more relays (maybe even SSR) to trigger the capacitors to change the speed of the fan.</p><p>I had actually drawn the circuit diagram much later after I had actually made the circuit, so it may not be 100% accurate. </p><p>Just to be clear, the MOC3041 are used only the fan speed control circuit. Depending on which of them are triggered, the corresponding TRIACs are triggered and this will add/remove capacitance (in parallel) in the line going to the fan. Thereby the speed of the fan can be varied.</p><p>There are also 3 relays. One works in tandem with a physical 2-way switch on the wall outlet to toggle on/off the light. Similarly the second relay works in tandem with a physical 2-way switch on the wall outlet for the fan. The third relay is to enable the fan speed control circuit. </p>
<p>Thanx for sharing the Idea.Good Work.<br>What is the final solution that you came up with for problem with BT136?<br>-Replace<br> with BTA16 ? OR snubber for each Triac (as when you trigger multiple <br>MOC3041s in your circuit only a single snubber shields for all the <br>Triacs which may be inadequate)? OR anything else.</p>
<p>A couple of months back, two of the BTA136 triacs shorted out. I replaced them with BTA16 and they have been fine. So I think BTA16 is probably the one we need to use here, with everything else in the circuit being the same.</p><p>Btw, are you planning to make something similar?</p>
<p>Thank you so much for such a quick response.I will go with BTA16.</p><p>I am planning something which will require a number of parts of this project. </p>
<p>I see. Obviously quite an intricate circuit. I hope the BTA16 will settle your problems</p>
<p>BTW,How much it cost you to come with this solution ?</p>
Its not much, but I didnt keep a tally :)
my assumption is below 5 K ?
<p>If you exclude the cost of the raspberry pi, I am sure the rest would be less than 5K Indian Rupees.</p>
<p>Thanks !</p><p>I have gone through your pdf content but still have a doubt regarding ATMEGA1284P-PU microcontroller chip. why i need this controller ? I believe that on Main Controller side Raspberry and on Board switch side ESP8266 is sufficient enough for communication among these 2 board.Please elobrate need of this controller. </p>
<p>Frankly, this is a question you need to ask yourselves and not me. Because it all depends on what you actually want to do. In my case, I needed an Arduino along with the ESP8266 as the ESP8266 by itself does not have that input/output pins that I required as well as the memory.</p>
<p>is Arduino is the ATMEGA1284P-PU micro-controller chip ? in my case I have Raspberry2 and now I don't need ATMEGA1284P-PU micro-controller chip for my use case ?</p>
<p>Hi gopinath,</p><p>In my design, I don't want to use ATMEGA1284P-PU micro-controller chip. At switch side wanted to use ESP8266, which will receive signal from Main controller and operate relay to switch ON/OFF the appliances. I am hoping this can be achieved by using GPIO pin of ESP8266. </p><p>Please let me know so that I can finalize my design.</p><p>TIA !</p>
<p>Please have a look at my other blog where I have just used an ESP8266 (ESP-01) module to control a light bulb.</p><p><a href="https://www.instructables.com/id/An-inexpensive-IoT-enabler-using-ESP8266/" rel="nofollow">https://www.instructables.com/id/An-inexpensive-IoT...</a></p><p>The reason i have used a ATMEGA1284 chip in this project was because I needed the extra GPIO pins for the various components such as LCD display used here. If you just need to operate a few relays, you dont need this chip and can use only the ESP8266 module. If you use ESP-01, you get just two GPIO pins. If you need more GPIO pins, you can also check out ESP-12.</p><p>Hope this helps.</p>
<p>Hi gopinath,</p><p>In my design, I don't want to use ATMEGA1284P-PU micro-controller chip. At switch side wanted to use ESP8266, which will receive signal from Main controller and operate relay to switch ON/OFF the appliances. I am hoping this can be achieved by using GPIO pin of ESP8266. </p><p>Please let me know so that I can finalize my design.</p><p>TIA !</p>
Amazing
Thanks!
<p>Hello gopinath,</p><p>I am not able to download the content.please suggest how i can do that.</p>
<p>Which content are you referring to?</p>
<p>I was referring to pdf attached. But I can now able to download.</p><p>TIA !</p>
<p>Hello,</p><p>I have similar concept but I wanted to use Raspberry pi 2 as main controller and ESP8266 module as switch module.Here is my concept.</p><p>I want to build a full home automation system with many <br>modules communicating together and with a central node.For example a <br>Board switch which connect to the electric board and perform on/off of <br>load like A.C,bulb,geyser,fan etc.This could be more than 1 in an house <br>which will interact with Main Board which is connected to wifi router.<br><br>Everything<br> should be control from an remote application and instruction should go <br>to Board switch from Main Board(controller). For example if I want to ON<br> Fan from an remote application then this should go to Main Board and <br>then from main Board it should reach to Board switch on which Fan is <br>being controlled.<br><br>For this I should have 2 device 1)Main <br>Board 2) Board switch which will communicate over some wireless <br>technology. Please suggest which platform can be used to suit this <br>requirement and also platform should be flexible enough to controlled <br>more use cases in future. </p>
I believe the design you are planning is more or less the same as the one that i have in this instructable. In my setup, the RPi2 act as the main board and the ESP8266 based board act as the interface for each socket.<br><br>hence, I am not sure what else you are looking for...
<p>Thanks gopinath,</p><p>On Controller side I am comfortable enough but on Board switch side I have concern regarding connectivity. For example I have 3-4 Board switch at home. Main controller would Broadcast some signal to all the Board switch present in House but specific signal should be catch by Board switch.I have read through various post and found that this can be achieved by <strong>ZigBee/Zwave </strong>mesh network.</p><p>Does your ESP8266 based board used ZigBee/Zwave ? If not,then How we will achieve this using ESP8266 based board.which version of ESP8266 based board you are using ?</p><p>TIA !</p>
<p>ESP8266 uses wifi protocol unlike ZigBee/Zwave. And of course, the ESP8266 modules in the various board switches are individually addressed.</p><p>In my project, I have also used MQTT protocol. With this protocol, each board switch can subscribe/publish to its MQTT topics. That was even if the IP address of the ESP8266 modules change, there will not be any issue. </p><p>To summarize, yes, with ESP8266 and MQTT, it is easy to access specific board switches and commands can be sent to individual board switches.</p>
<p>Thanks gopinath,</p><p>Let me look into your project as an reference . now I am confident enough to build this Prototype. </p><p>In addition to that I would like to download your content pdf but I am not able to do so .How I can download ?</p><p>Looks like all these are open source component and there wouldn't be any license/legal issue if someone will come-up with own product using this protocl and software. please advice ?</p>
<p>Amazing!<br>I can't seem to find the proper Adafruit_GFX_AS.h , each time I try compiling the code after importing the file, from Github, it gives me a compiling error, can you please help me?</p>
If you can post me the actual error messages, I might be able to help you out. But yes, I also had lots of issues using this library initially.<br><br>If you can afford to spend more money, check out displays by Nextion. It is very easy to use and has a lot more features. I just bought one recently and am planning to use it in my next project.
<p>How about the safety of the AC line ?</p><p>What happens when your circuit shorts out or something ?</p>
<p>I do have a fuse before the 5v power supply in the circuit. Otherwise, the circuit breakers in the main electricity panel in the house should trip if there is a short in the IoT Wall Outlet circuit.</p><p>I certainly appreciate your concern and I hope anyone trying something similar also is aware of all potential issues. I think I may have made the circuit un-necessarily complex and that may put off many who want to replicate this project :( </p><p>I am working on a improved version of this project where I am going to replace the optocouplers/TRIACs with just electromechanical relays and generally make the circuit as simple as possible. And I am going to use 5v relay modules and not solder them myself. I think in the end I should have a lot more safer and easier to make circuit than the one in this instructable.</p><p>Stay tuned :)</p>
This is wonderful. Good work.
<p>Thanks!</p>
<p>Nice... update for you.. <a href="https://scargill.wordpress.com/?s=esp8266" rel="nofollow">https://scargill.wordpress.com/?s=esp8266</a> that is now <a href="http://tech.scargill.net" rel="nofollow"> http://tech.scargill.net</a></p>
<p>Thanks Peter! Your blog is amazing and has been really helpful for me to explore various aspects of ESP8266 as well as to learn about other things such as node-red and NetIO.</p>
Excellent. Be sure to keep looking in - I've just been playing with websockets and I've an update to go up there perhaps later today.
<p>Excellent. I hope you are sleeping well! </p><p>Which library did you use for the touch display?</p>

About This Instructable

26,437views

226favorites

License:

More by gopinath.marappan:IoT Power Strip IoT Mood Lighting IoT Wall Outlet with Arduino and ESP8266 
Add instructable to: