Here I am with a new project and this time it is not yet another more or less digital watch. Some time ago ravanando on YouTube in search of some news to propose, I found the finished and finished project of a power strip controlled via Bluetooth. I wondered then if I could reproduce it in some way adapting it to my needs. I started to study what I had seen on condition of using only components already in possession and therefore at costs I do not say ridiculous but almost.
Starting from the base I cannibalized a slipper a 6 places with single switches that had some problem with the switches. They are not exactly the best and after some time they break down. The power strip in question is the one in the photo below:
Each switch has an indicator light consisting of a small pea bulb (remember the ones that were once used to illuminate the Christmas tree ?) with a drop resistance. But they are fragile and by dint of maneuvering them sooner or later they break.
So let's proceed with the project: the base is there. Then hand to the screwdriver and open the slipper. We disconnect all the switches and remove them from the housing. Each switch can be easily dismantled leaving only a usable and sufficiently large empty rectangular housing.
Let's move on: Each of them is connected in parallel to a branch of the input voltage while the other branch is connected to a switch connected to the other branch of the voltage. So let's isolate 5 of the six leaders so you have 5 single wires (one for each socket). Because five and you're not ?. Why did I leave the first outlet connected to 220 in order to use it out of context.
But more than words are worth facts and in the photo below you can see what it has become:
We can see: each switch housing was filled with a high brightness red LED and incorporated (with its drop resistance) in a wax casting (that of candles to be clear). Although in this photo they are not seen on the left side of the slipper they have been practiced 2 holes: one for passing the single voltage wire of each socket and the "master" wire for closing each individual contact. The second hole for passing the wires of each LED and the common ground wire for all the LEDs. Note the hole that housed the switch of the first socket. In the photo you can see that the second and sixth pinch are under tension 220 and the related LED light is on. This photo refers to the first functional tests before the production of the actual hardware.
As I said, the whole project must cost very little as long as you only use components you already have or at most buy only the necessary ones.
First idea: use a WEB page with which to individually control each of the on and / or off sockets.
Second idea: use a BlueTooth device to do the same.
Which is the simplest ? : it depends on the degree of experience that each of us hobbyists, amateur or professional, has relative to the programming of the two systems. Personally I am an unpretentious hobbyist and I think I get enough in both systems. So for each mode we see complications and facilitations:
WEB idea: Perhaps it is the most complicated as it requires resources and knowledge of a certain level. Resources can be: Arduino board and Ethernet shield but the experiences made by myself a few years ago have not satisfied me and the shield itself NONmanages the WIFI. So it was discarded. If we want to do something more "modern" and use WIFI (so much today is in fashion !) forms can be used ESP_8266 than in a size of 25mm for 12,5 they collect a complete programmable microprocessor via Arduino and specifically to make WIFI connections using WEB_SERVER and other systems.
What is the complication of this choice ?: A good programming experience "C", customization of the Arduino environment to manage this module, knowledge of the pages HTML and their programming. All this may not be within everyone's reach. I personally did a little’ of experience both in recent times and in remote times at least as regards HTML pages. But I believe that even if you are not an "expert" there is a lot of ON_LINE material that helps you program these ESP modules by providing more or less complex examples. The only disadvantage many times is the language: many sites are English-speaking.
Idea BlueTooth: This is perhaps the simplest: the BlueTooth module does not connect in WIFI but precisely via protocol Bluetooth available on all tablets and mobiles. It can be used by connecting it in serial mode to an arduino micro, or use some APP (or program it for those who are capable) produced for the purpose. In this case, it can be used in serial mode with the Arduino "Serial_Software" library. The sketch must be programmed in order to receive the serial characters that the APP sends via the serial port. There are several APPs that manage this module in a serial way. So the only complication is the programming of the sketch.
After analyzing the two ideas I decided to use the ESP_8266 modules for a number of reasons. Some time ago I had bought well 5 of the model ESP_01to have experiences. I had only used one to produce an ON_LINE digital clock or taking time from the internet by viewing it on an LCD (full date and time). Why then let them age in the drawer ?.
The use of this micro involves a series of "complications" and "adjustments" in the Arduino IDE environment. It is not difficult to follow the instructions found on the WEB to update the IDE both in terms of "cards" that must be managed and in terms of usable "libraries". In fact, both the "tabs" and the "libraries" are many, but first you need to insert the following definition in the settings of the Arduino IDE:
Additional urls for the card manager: http//arduino.esp8266.com/stable/package_esp8266com_index,json
Then if it doesn't run automatically, from the "tools" menu select "Card management" and let the IDE search for the "cards" to be added. You will then have to choose from the proposed list as shown: (in my ide are already installed).
If all goes well in selecting the cards to use, you will find a list of ESP cards that can be used: in this case, simply select the item "Generic ESP8266 module".
ESP8266_01 presents (despite its size) ben 8 pin:
• VCC (3,3V mandatory !) e GND. • Two pins defined GPIO_0 and GPIO_2. They are pins that can be viewed as INPUT / OUTPUT of logic signals (Bit “0” Bit “1”) always with respect to the 3V level. . • RST to reset the micro to ground to reset it otherwise to logic "1". • It pin EN (enable) which enables the micro if set to logic "1". • Two TX / RX pins that can be used to receive and transmit serial data, remembering that the signal level is based on the 3V power supply. TX and TX are also defined as GPIO_1 and GPIO_3 as they could be used as I / O pins but carefully.
The complication on the use of this micro lies in programming if an adequate system is not used. The GPIO_0 pin is also called GPIO_0FLASH because if placed on the ground it allows writing the sketch in the flash memory of the micro.
It is not as easy as it seems: there is a specific sequence of operations to be done to bring said micro in the condition to accept the upload: turn it off, bring GPIO_0 to ground then turn it back on or always reset with GPIO_0 to ground. But it wasn't easy. I had the foresight (without knowing it) to buy a "debugger" module with which I solved it without knowing it (at first) just this loading problem.
Here are the two modules: On the left an ESP_01 module and on the right the Debugger module. It is very useful: it is seen as a serial port (WITH), has a button for resetting the micro and the male connector is the exact copy of the 8 micro pin and therefore perfectly usable. No problem for loading the sketch as it automatically performs the operation described in previous paragraph. After loading, you can test the sketch without removing it from the adapter. I found this module on Futura_Shop at approx 6 euro. Be wary of other adapters because they don't have these features.
Another complication in the use of this micro is in the power supply: he just wants 3,3 V and requires a power supply system that supplies 3V with at least 1A of current. And it doesn't end there: the GPIO_0 levels, GPIO_2 are also at level 3V. Now if they are to be used to interface other devices working at 5V level a level converter is needed (or voltage dividers which I do not recommend) as an interface between the pins of the micro and the pins of other devices. Almost all devices with the I2C protocol require the correct 5V levels at the SDA / SCL pins. Incidentally in my internet watch with I2C LCD I used these converters between GPIO_0 and GPIO_2 of the micro.
Here's how they look: On the left the power supply with 3V output and on the right the level converter module with 4 channels. These converters have a 5V and a 3V input called HV and LV. The outputs are bidirectional: what goes into 5V goes out to 3 and viceversa.
(Images copied from the EBMSTORE.it site)
IMPORTANT NOTE that I almost forgot: when they leave the factory (Chinese) all ESPs are equipped with software to manage the "AT" commands to be understood those that were used once on old telephone modems. With these commands you can check, among others, also the WIFI connection to your router and also check how many are within the range of the chip even if limited. To try these commands, even without the need for specific sketches, a serial connection is required (baud rate 115200) using the Arduino serial monitor or the Windows Hyper Terminal. You then need an RS232 / USB converter to connect to a USB port on the PC. Below one of the feasible connections. In the RS232 FTDI converter, the jumper must be moved from 5V to 3V to make the signals compatible.
CAUTION: the first time any sketch is loaded on the ESP, this "AT" software is lost and a special "FLASH" application must be downloaded from the web to reload it.
The project begins to take shape: we have the micro, the correct power supply and the logic level adapter. Now we need to study how to turn on / off individually 5 took a 220 of the slipper. I have tested two systems:
1. Driving a triac via photo coupler with logic signal "1". I had already experimented with these devices with different circuits but they have always proven to be unreliable and are not suitable for energy saving lamps. This is one of the circuits.
2. Driving a relay with photo coupler or via transistor also driven by a logic signal "1". The following two diagrams do not present specific problems except for the one with photo coupler working only with 12V relays.
The choice fell on the 5V relay interface also because I had almost available 10 printed circuit relays with double exchange which can also be used to switch 220V voltages. These relays are quite old and I don't remember where I cannibalized them. This is the model:
Made a prototype I tested the functionality and then I decided to prepare the whole interface to manage five of these relays using the interface with transistors.
Only one last problem remains: relays are 5, micro ESP has am 2 pins usable without problems. A device is therefore needed to increase these pins. Also in this case my past experience with PCF8574 type devices like the one in the figure helps me:
This device interfaces with I2C protocol addressable on 7 different addresses (see jumpers in the figure). It can be inserted in cascade with other similar devices or other I2C type LCDs except for the correct address. The only problem with these devices is the size and inserting them in a PCB can cause some problems. It would be preferable to use the single chip as it does not require particular circuits: 5V for power supply even if it supports 3V, a couple of pull_up resistors to the SDA / SCL pins, a few bridges to assign the address and nothing else. The 8 pin (plus one defined INT as an interrupt) they can be Input only or Output only or mixed. Reading or writing on these pins is done simply with the WIRE library (Wire.write o Wire.read).
But there are problems: not for the pins defined at the input, but for those defined in the output it is necessary to verify well how they should be used. The maximum current (vedi i datasheet) it is too little even to drive a single LED. Several ON_LINE forums demonstrate how any LEDs or devices that by their nature absorb currents higher than that supplied by the device must be connected.
This figure is one of the working examples for the ignition of 8 led: their connection can be seen: Anodo a VCC, cathode with R towards the pins. By making suitable tests I was able to notice the excellent brightness of a classic green LED. It is important, however, to know that when the system is turned on, all the pins of the chip are set to "1" logic: therefore while for the previous scheme there are no anomalies (the LEDs light up only if the relevant pin is grounded), in my case it can give problems because all the relays are triggered with the logic "1" signal. It is however surmountable as in the sketch the first operation to do would be to bring all the pins to "0" logic. Ma, there is always a "but", there is a time that as far as it is in terms of thousandths is to be kept in mind: the micro starts after a few seconds and this could cause problems. Let's not forget that 220V voltage will pass through the relays.
Given these premises, to avoid surprises, I try to do some tests with flying cables and minimal sketches, I connect the PCF to arduino (WIRE protocol) and a pin at the input of the relay ignition prototype (Trigger with logical "1"). Perfect: turns on and off but if repeated even at intervals of a few seconds it DOES NOT WORK !, proving unreliable.
I therefore believe that the lack of current availability is the cause of this unreliability: after a few turns ON_LINE I decide to change the trigger method: instead of carrying a logical "1", the pin takes it to ground. But this involves a change to the trigger circuit for which, to not have to change everything, I interpose a reverse circuit between the PCF pins and the inputs. At first glance a 74Ls04 might be fine, however I preferred to use an ULN2003A which is a "SEVEN DARLIGTON ARRAY" which provides a current of 500ma. Seven inputs and as many outputs, however, all "Open_Collector" so an R from is required 4,7 ohm (or higher) in pull_up towards 5V for each pin. It also acts as an inverser whereby an input at "1" is inverted at an output at "0" and vice versa. Excellent for what I need: I will simply have to change the ignition method in the sketch: from “1” to “0” for each relay. And I won't have to worry if the pins on the chip all go to "1". In the figure the arrangement of the pins.
STARTING THE PROJECT:
I believe, at this point, to have everything available to start producing PCBs and implement some sketches with ESP_01. Let's do the "shopping list" to find out if we actually have everything we need and that is:
• N.1 ESP8266 model 01 • N.1 5V / 3V level converter • N.1 3V power supply (Input da 5 a 9V max) • N. 1 PCF8574 • N. 1 ULN2003A • N. 5 Relais Finder model 30.22 • N. 5 transistor BC547 • N. 5 diodes 1N4007 • N. 5 LED AL. (any color) • N. 10 resistances values according to the scheme • Various connectors and sockets for assembly. • Micro Reset button • Led (any color) as an ON_LINE system spy
Not having more or less professional instrumentation and not even a suitable environment I have to content myself with producing only small PCBs. Therefore this project consists of two PCBs: MAIN PCB to house the heart of the system and RELAIS PCB to house the relays.
I did not draw a circuit from which to derive this pcb but it was drawn freehand trying to avoid jumpers and better compact the components.
You can see: the connectors on the top left to power the same board and others; the four-pin connector for inserting the PCF8574. At the bottom left in the red rectangle is the 3V power supply. In the middle the level converter on the right the female connector for the insertion of the ESP_01. The inverted yellow L-shaped rectangle serves as a guide for cutting the excess part of the PCB. Here is the photo of the PCB produced. The cut was used to insert the PCF card.
This pcb is the most complex and for the design I started from another prototype pcb produced for testing by making the necessary corrections and making a copy / paste in practice. The wiring diagram is that of the previous figures. At the top of the pcb we can see i 6 connectors related to: 5 for the 5 sockets and the sixth for the second branch of the voltage at 220. Bottom left the 5V power pins that will be connected to the main PCB. In the center i 5 input pin for relay triggering signals. The diodes after each input are 1n4148.
Here in the photo what the completed relay card looks like.
You won't believe it but after all the PCB production (design and production) I realize that I have forgotten to insert a fundamental component: the interface driver between the outputs of the PCF8574 and the inputs of the relay PCB. I certainly could not blow up what was done and I had to content myself with making an additional pcb to house the driver to be interposed. And I produced the following:
The resistances of PULL_UP are from 4,7K.
At the end in this photo the completed project:
In the middle between the PCB_Main and the PCB_Relais the driver card. The three white connectors on the right of the relay board are used to connect the voltage cables of the 5 He took. The sixth the other voltage cable of the 220. Even if you don't notice well in the lower right there is the red button that resets the micro ESP and next to it a LED that lights up when the whole system is ON_LINE as I will explain in the software chapter.
Have mercy on building the stand: as bricolage they are a real landslide: the dimensions of the container are 10×20 cm !! in plexiglass.
In the following photo the complete and functional project.
Unfortunately, the power strip is unable to accommodate anything given the size of the devices.
THE MANAGEMENT SOFTWARE:
And here we are at the most interesting and fundamental part of the whole project. As I said at the beginning, the choice fell on the use of a WEB interface via an HTML page that can be managed via WIFI from any PC, Tablet, or mobile phone. I state that the realization of the sketches are not all flour of my bag, but through the WEB I was able to download various examples of management of a WEB_SERVER to turn LEDs on and off and from these examples I started to implement the sketches by completing them with the management of the PCF8574. A bit’ of experience in the implementation of HTML pages I had done it years ago but it was a long time ago that I had to refresh my memory.
The sketches created produce the following HTML page:
In the first line the status of the relays to indicate which are "ON" and which "OFF". In the second and row 5 buttons to bring “ON” each relay, in the third row others 5 buttons to turn each relay “OFF”. Each time the relative button is pressed, the first row is updated accordingly. Finally in the 4 row two buttons "ALL_ON" and "ALL_OFF" turn on or off all relays in one go.
This below is the HTML page of a further sketch: Incidentally, the button design was carried out with the WYSIWYG software that produces HTML pages visually.
The procedure is similar but with a diversity: The first line always highlights the status of the relays. The buttons below have a dual function: when they are “red” it means that the relative relay is off. Each press the relative button turns blue and the wording changes from ON to OFF and so for all the others, as well as the "ALL_ON" button which becomes blue "ALL_OFF". And the first line always highlights the status of the relays.
STRUCTURE AND LOGIC OF SKETCHES:
I have implemented two sketches called Ciabatta_Web and Ciabatta_Web3. The programming logic is substantially the same, only the management method of the PCF8574 changes with respect to the switching on / off of the relays and the writing of the lines that make up the web page.
To manage HTML pages ON_LINE with the support of ESP_01 and other models, there are various methods for a correct approach: I do not dwell here on which and how many they are as each has its specific characteristics and a different management method. I will only describe the one used in the two sketches.
To access a WIFI_Server system you need:
The bookstore “ESP8266WiFi”. That a_tantum must have been loaded when the Arduino IDE for the ESP boards was updated.
The definition of the parameters to access your home router: “ssid”Which is the name assigned to the router, and your password. Two simple definitions like these: The names can be of your choice.
Finally the assignment of the port to the WiFiServer with this definition: WiFiServer server (80); (the server "listens" on the door 80)
Of course, library definition is also needed WIRE which is used to manage the PCF8574.
In both sketches the possibility of debugging has been inserted by inserting the classic Serial.print() in more or less critical points of the sketch through the Arduino serial monitor or (that I recommend) l’Hyper Terminal di Windows. Unfortunately on Windows 10 this APP is not provided, so you need to search it on the Web and download the free version.
The serial port with baud a is then enabled 115200 for ESP (it doesn't seem to work at lower speeds) but a procedure is also inserted whereby if you do not press any key within 3 seconds the writing on the serial monitor of the appropriately programmed debug signals is inhibited. But this is my personal choice. After all, there are no other interactive debugging methods, this is the best solution to avoid being in the dark when the sketch for some reason does not respond.
NOTE: to debug the monitor it is necessary that the ESP is connected to a serial converter type FTDI232 or to the "debugger" module that I have previously described in order to assign a COM port.
We then proceed to initialize the Wifi with the command: WiFi.start(ssid, pwd) and checking through a "while" loop that the WiFi.status be ok: or testing the parameter WL_CONNECTED until it is OK. Since the router's response may be longer than normal, it is a good idea to insert a timer of a few seconds to avoid an infinite loop. The router may not respond if the parameters are incorrect or for other reasons.
Carrying out the WiFI.start(ssid, pwd) by default when the router answers and the connection is made, an IP address in the classic form is assigned to the ESP 192.168.1.XXX where XXX is the actual address assigned. It therefore becomes necessary to know which address has been assigned (DHCP enabled on the router) to ESP to be able to connect and launch the HTML page from the browser. This address will never change when it is associated with the ESP MAC Address.
But how do we know which address has been assigned ?: The debugging system on the serial monitor comes in handy: after the connection is ok, the address assigned with the phrase is sent through the classic Serial.print: Serial.print(WiFi.localIP()).
There is another system to remedy this possible inconvenience: assign a static address with the following definitions:
IPAddress ip (192.168.1.XXX) to define the address you want in parameter XXX. IPAddress gateway (192.168.1.1) gateway address of the router IPAddress subnet (255.255.255.0) address mask.
So after the WiFi.begin add the phrase WiFi.config(ip,gateway,subnet). To access, simply enter the assigned address to connect to access. The names are to your liking.
At the end of these operations you are successful with the phrase "server.begin()”Starts the server ready to listen to requests coming from the browser.
At this point and only this point through the PCF8574 (which has already been initialized) a byte is sent with the configuration 0111 111: or the bit 7 on which a LED is connected it lights up but all the power strip relays remain off. The lighting of this LED verifies that all the operations performed are ok and that the "server" system is on_line. This led system is a personal choice.
In the "setup" there is nothing else to add except for any operations for the setting of other devices that in the case of the project there are.
In the "loop" the lion's share comes from the management of the "client" or the system that must interact with the server and receive the commands sent from the WEB page. The first thing is to instruct the "client" to check if the server is available: a loop after the sentence " WiFiClient client = server.available()”Allows you to check when the server is available. If it answers positively, we check with a loop that the client is available . If everything proceeds OK we can proceed with reading when it is sent from the browser, storing it in a string, and consequently send the client the instructions that make up the HTML page. The client.print or client.println instruction works as a Serial.print and therefore the HTML sentences are defined in brackets. The string we have stored contains what has been defined in the parameters, ie which button has been pressed. A special routine analyzes this string and prepares the one that must be displayed on the WEB page to indicate which relay is ON or OFF.
But more than words, facts are needed: here is what is issued (debug the active sketch) since when we connect with the browser:
Serial port output for connection verification:
WEB power strip 3 Connecting to TPLINK_8968 >>>>> ROUTER CONNECTION …………. >>>>>> WAITING FOR CONNECTION WiFi connected. IP address: 192.168.1.113 >>>>>>> ASSOCIATED IP CONNECTED SERVER
CONNECTION TO THE ADDRESS IS MADE FROM THE BROWSER 192.168.1.113 AND THE PROGRAMMED HTML PAGE IS ISSUED
Client disconnected. >>>>>>> DISCONNECTION OF THE CLIENT FROM THE SKETCH >>>>>>>> NO OPERATION REQUIRED
FROM HERE FORWARD FOR EVERY OPERATION CARRIED OUT ON THE BROWSER PAGE THE FOLLOWING PHRASES WILL BE EMITTED WHEN A BUTTON IS PRESSED
Host: 192.168.1.113 User-Agent: Mozilla/5.0 (Windows NT 10.0; Win64; x64; rv:78.0) Gecko/20100101 Firefox/78.0 Accept: text/html,application/xhtml+xml,application/xml;q=0.9,image/webp,*/*;q=0.8 Accept-Language: it-IT,it;q = 0.8, en-US;q = 0.5, in;q=0.3 Accept-Encoding: gzip, deflate Connection: keep-alive Referer: http://192.168.1.113/6/ON >>>>>>>> HERE IS WHAT THE BROWSER SENDS AFTER PRESSING A BUTTON: IN THIS CASE THE SIXTH BUTTON
I state that everything that has been created and completed is only and exclusively produced by myself. It can certainly be improved and thought of in a different and more professional way. Circuit choices can also be subject to change and certainly a different approach could give better results. But I'm not a professional and my experience in electronics is limited.
https://www.elettroamici.org/wp-content/uploads/2020/07/Proto_Ciabatta.jpg247315gvsofthttp://www.elettroamici.org/wp-content/uploads/2017/08/FAVICON-1-300x271.pnggvsoft2020-07-17 14:58:102020-07-17 21:09:54Electronic power strip