Smart WiFi light switch. Design, principle of operation and connection of a Wi-Fi switch Wi fi light switch control via smartphone

I have long wanted to automate the process of drying the bathroom after bathing. I have had many reviews on the topic of humidity. By the way, in the winter we dry our clothes in the bathroom. But I haven’t decided yet what exactly to implement. I will describe another Chinese miracle to combat this evil.

In summer we dry clothes on the balcony, in winter - in the bathroom, just turn on the exhaust fan. But monitoring the fan is not always convenient. So I decided to install automation on this matter. The first implementation experience was unsuccessful. There was a review. But I didn’t give up... The second experience was more successful, I also did a review. But I didn’t manage to put it into practice. Frequent business trips take a lot of time.
But I did not expect such a gift at all. I saw a letter in a personal message with an offer to review a product by Itead Studio. It’s stupid to refuse a product for review if it’s interesting (let alone necessary) yourself. Immediately after, I looked through Muska. I found at least three reviews about Sonoff products. I’m not the first: (I can imagine how many votes there will be in the comments about the free cookie. But spitting in the back is the lot of the weak and losers. Therefore, this review is for those who consider themselves capable.
This is what the cart looks like with my selection:


But I made a small mistake, I didn’t pay attention to the text in the picture (on a red background). The switch came without a remote control: (This is an additional option, it must be purchased separately
The order came in a small box.


The TH16 module was without packaging.

The rest is in boxes. But there were no instructions. That's all I ordered.
I'm quite a lazy person. The only thing that can make me do something is an obligation to someone. They say that laziness is the engine of progress. My drive is a promise made to someone. Thus, I killed two birds with one stone: I wrote a review and figured out these magic switches/switches.
Let me remind you a little of my story.
When I moved into a new apartment, I almost immediately installed a fan with a check valve in the hood. A fan is necessary to dry the bathroom after bathing. A check valve is needed to prevent foreign odors from neighbors from entering the apartment (when the fan is silent). It happens. All the ventilation ducts are individual, but they apparently saved cement when laying them. The smell probably passes through the cracks.
I have different options for fans. There are simple ones, some with a timer (time interval adjustment), as in the photo.


This is exactly what I used to this day.
Since I live in an apartment “anthill”, the only place for drying clothes is the balcony. It may go dark in the bathroom. Drying requires either low humidity or air circulation. Fulfilling both conditions is the best option. A fan should have solved this problem. At first I did just that. The main thing is not to forget to turn it off. While the fan is operating, the window must be opened slightly. Don’t you need to remind me about the school problem with a swimming pool and two pipes? In order for the air to escape into the hood, it must enter the apartment from somewhere. Those who have wooden windows and not plastic will have no problems. Enough cracks. But with plastic ones, the apartment turns into a terrarium.
That’s when I started thinking about automating the process...
I have already shared my sad experience of implementing my idea. This is the module. It cannot work IN PRINCIPLE.


I also drew a diagram of the module.


The circuit is based on a comparator based on LM393. From the looks of it, everything should work. But there is one thing. The sensor is unusual. It changes its resistance with respect to frequency. To take readings, you need to apply a frequency to it (standard value 1 kHz). This is such sadness.
On one of the sites there were three comments from one user about this:

Strange, this is a standard sensor from Arduino peripherals - it should work.
There’s nothing to check yet - I’m not particularly interested in humidity, because I don’t have such a sensor yet. :)
I’ll order it when the opportunity arises and report back...
...I don’t have a single Arduino module that doesn’t work.
I’ll buy it for testing, maybe I’ll make a weather station for myself...
...do you think they would do this if they were not working?
A year has passed...
Apparently, I can’t wait.
I move on to the parcel.
The store page with the TH module looks like this:

On it you can select Sonoff TH modules depending on the relay current, as well as humidity and temperature modules. You can see exactly what I chose. I didn’t find the humidity module in a separate sale on the store page (maybe I didn’t look well). Therefore, when ordering, be careful...


There were no instructions either (already wrote).
The store has a help wiki page:

Everything is there, even the diagram:

Small in size.


Weighed, 79g.


I'm starting to analyze.
220V network wires are connected here.


The contactors are spring-loaded and very tight. But, for me, it’s more reliable with a screw.
The case is held on by latches.


Everything is in the mind. I have no comments.
Unscrewed 4 screws.


The Wi-Fi node is built on ESP8266 (who would doubt it). For aces there is a whole field for activity. The main thing is that the head works. The rest has already been done. There is no need to isolate a separate power supply for the module, and there is no need to look for a box either. Everything is assembled and working.




The board has been washed. There are no traces of flux. At the input there is a fuse and a 10D471K varistor against overvoltage (interpretation - diameter 10 mm, voltage 470 Volts).

I haven't seen this for a long time. I put everything back to its original state.
I turn to the humidity module. This one came in a box. You can read what is written on it (on the box). Photos allow you to do this.

The module is unusually large.

Connects via a connector similar to headphones.


It turns out this way.


Everything basic is written on the case.


The store has a wiki help page (already wrote):
- Temperature and humidity module
AM2301 Product Manual
There is also a manual for the temperature sensor:
- DS18B20 - Programmable Resolution 1-Wire® Digital Thermometer
I didn't order it. I'm not interested in him. Plus, AM2301 is more versatile. It has both a temperature sensor and a humidity sensor. Moreover, the TH10/16 housing has only one hole for the remote module.
I'm disassembling AM2301. Housing with four latches.


On one side of the module there is a temperature, humidity and quartz sensor.


The main diagram is on the reverse side.

I'm also building this module.
And finally, the Sonoff RF smart switch.



Also no instructions. Even smaller in size than Sonoff TH.


Weighed: 49g.



It's not of particular interest to me. But I'll show you what's inside.

The case is also latched. You can see the parsing sequence.
Screw contactors. For me, it's very convenient.


At the input there is a 10D471K varistor against overvoltage (interpretation - diameter 10 mm, voltage 470 Volts), as in the VT module.


Power supply unit with galvanic isolation from the network. They even made cuts in the board.
The board has been washed. There are no traces of flux.


Everything is in the mind. And I have no comments here.
And here the WiFi node is built on ESP8266.


Radio module in the form of a separate board.


I put everything back to its original state.
It's time to get down to business.
I'm putting together a training plan. I connect the Sonoff TH module to the network. The connection is not obvious to everyone. Therefore, look at the picture on the store page.

Few devices work in this way. Therefore, I put a red cross on the “extra” wires.
I hang a fan at the exit.
It's much easier with Sonoff RF. I connect an ordinary light bulb to the output for control.


All that remains is to connect the whole thing with the smartphone.
Smart switches support remote control via Wi-Fi, but only via the cloud :(
It's time to link them to the eWeLink control application. To do this, you must first download it :) Install, register...
The account has been created.
First I connect Sonoff TH. I launch the application and follow the instructions.
To add a device, click on the plus sign. Next, press the little white button and hold it for about 5 seconds. The blue LED should blink steadily. Exactly evenly! He may “go into a trance” :) and start giving strange signals. In this case, press and hold again.


The application asks you to enter your Wi-Fi password. Then it searches for devices.
You will need to enter a name for the new device.
See the photo for the sequence of pictures (from left to right, top to bottom).


The switch is “linked” to my account.
Same with Sonoff RF. After linking, the picture on the smartphone looks like this. You can turn the load on and off by pressing the buttons. Three pictures: off, on and not connected to 220V (offline)


In order to turn on the switch, you need to press a button on your virtual remote control from anywhere in the world where there is Internet and Wi-Fi.
When connected to a 220V network, the blue LED on the module lights up. When the load is turned on, the red LED additionally lights up.


But this is all manual mode. In order to enter automatic mode and get into setting the parameters for turning the switch on and off, you need to move the lever (Auto-Manual) to the auto position.


And in the settings I put what I need.
Let me explain the pictures. Now there is 55% humidity and the temperature is 18˚C (remote module on the windowsill). The switch is off. In this case, temperature and humidity are monitored online, regardless of what mode the switch is in (manual or auto).
Let me explain what I asked.
When the humidity reaches 65% the switch will turn on (fan). When the humidity reaches 60% it will turn off. You can do the opposite (for a humidifier).


This is for those who have very low humidity in winter.
When the humidity reaches 30%, the switch will turn on (humidifier mode). When the humidity reaches 40% it will turn off.
All settings are in accordance with GOST 30494-96 “Residential and public buildings”.


Pay attention to the optimal humidity in winter. This is not 60% as many people think! 60% is just acceptable, you can’t go higher, you have to fight. OPTIMAL 30-45%
You can control the switch using a timer. There are two options.


Temperature triggering can be configured. All settings are identical to the settings for humidity, only select the temperature.

A little about the Sonoff RF smart switch.
It differs from Sonoff TH in that it has a radio module (can be controlled using a remote control, which I don’t have). It also does not have the ability to work with a humidity and temperature sensor. The rest is the same: control via Wi-Fi with the ability to set a timer.
The virtual remote is a little different.


In automatic mode there are also two types of timers (like TN).


I repeat. It’s not of particular interest to me, but I’ll definitely find a use for it.
I will note the nuances of the operation of these switches. Without the Internet you will not get any control.
BUT there is one big plus. The automatic mode configured on the switches will continue to work regardless of the Internet!

When installing the application on several phones, you can control it from all of them, but only if you log in to eWeLink on each of them using the same username and password.
At the end I will summarize briefly.
Smart switches support remote control via Wi-Fi, but only via the cloud: (They need to be linked to the eWeLink control application. What if some good Uncle Liao wants to control your smart home? For those who don’t trust him, you’ll have to create your own MQTT server, and turn on/off the load according to your wishes and rules. For those who have programming skills, this is not difficult. For those who are calm about such a problem, just connect and use. For example, I don’t care when managing fan in the bathroom. But when the time comes to a full-fledged “Smart Home”, I will think about something.
That's all.
These modules are ideal for working with a fan, air conditioner, and humidifier. You can organize a smart watering system at your dacha. Even a gas boiler can be controlled by time and by a given room temperature.
Everyone decides for themselves how to properly use the information from my review. If something is unclear, ask questions. I hope it helped at least someone. Perhaps someone will want to help me. I'll be very grateful.

Good luck everyone!
Functional test and gutting:

The product was provided for writing a review by the store. The review was published in accordance with clause 18 of the Site Rules.

From the article you will learn why a wireless switch is needed, scope and types, device and principle of operation, advantages and disadvantages, selection criteria, how to connect it yourself, diagrams.

Wireless network switches radically change the idea of ​​controlling lighting devices, simplify our lives and make it more comfortable.

Until recently, such technologies were unavailable due to high prices and limited production.

At the present stage there is a tendency to reduce their prices. That is why radio switches and their other analogues are increasingly perceived as an alternative to classic switches.

What is a wireless switch for?

Remote systems that provide control of certain devices at a distance are becoming increasingly widespread. The wireless wall switch is no exception.

It was created to increase comfort, and for senior citizens and people with disabilities it is absolutely necessary.

Using such a device, you can easily control the lighting in your home, change the brightness, and turn lamps on and off.

In addition, thanks to the special design, there is no need to damage the walls or make large holes for installation.

Scope of application

Traditional switches are gradually becoming a thing of the past due to inconvenience of use, complexity of connection and installation, as well as a small resource. Wireless analogues have better qualities.

They have a stylish appearance and install within a few minutes.

The use of such products is relevant in the following cases:


Varieties

Wireless switches are not very diverse, but there is still a certain selection.

They are classified according to three main characteristics:

  • By type of control;
  • If possible, regulate the level of illumination;
  • By the number of lighting devices they control.

Taking into account the classification mentioned above, the following types of wireless switches can be distinguished:


Design and principle of operation of the main elements of the device

The wireless switch consists of the following elements:


Electrical wiring is only required for the light fixture and power supply to the product receiver. As noted above, the signal is transmitted using an infrared pulse or radio waves.

The second control option is more preferable, because control is possible at a great distance and even from another room.

The installation of the product is carried out according to a simple scheme, for the implementation of which you do not need to have deep knowledge in the field of electrical engineering.

The old switch can be left as an additional source of on/off when the battery in the control panel is low.

Light control is carried out in the following ways:

  • By touching a special touch panel;
  • By pressing a mechanical button;
  • By sending a signal from the remote control or phone.

When remotely controlled by a remote control, the signal is supplied at radio frequencies, which eliminates interference and increases the reliability of the device.

Walls, furniture and other interior elements will not interfere with the passage of the command to turn on or turn off the light source.

Using the remote control, you can simultaneously control a group of wireless switches (up to 8 pieces). Thanks to this, you don’t have to walk around your apartment or house to turn off the light somewhere in the toilet or bathroom.

The range of the remote control depends on many factors - the model of the product, the design features of the building, the materials used in the manufacture of partitions.

Most often, the signal is transmitted over a distance of twenty to twenty-five meters. The transmitter is powered by batteries.

The disadvantage of the control panel is that it is constantly lost and the lighting has to be controlled manually.

That is why wireless touch switches that respond to normal touch and are used in Smart Home systems are becoming increasingly popular.

Some radio switches are capable of not only turning the lamp on and off, but also adjusting the light level. In this case, the scheme is supplemented with one more element -.

The regulation process is carried out using a wireless switch. To change the light level, press and hold your finger on a button or key.

Advantages and disadvantages of wireless switches

Despite their ease of use, wireless load switches (in our case, lighting) have not only advantages, but also disadvantages. But about everything more similar.

  • Ease of installation. For installation and connection, you do not need to drill into walls or lay a separate “branch” of electrical wiring.
  • Possibility to control several light sources at once from the remote control or via a smartphone.
  • Large range of action. The control signal in an open area can reach the receiver at a distance of up to 30 meters. In this case, walls or pieces of furniture are not an obstacle.
  • Safety for adults and children. Even accidental damage to the structure does not pose a health risk. The operating current in wireless remote switches is minimal and not hazardous to health.
  • The cost of such products is higher than classic “wired” switches. Adherents of economy and conservatives prefer familiar products.
  • Inability to control due to low battery in the remote control or inability to control due to weak Wi-Fi connection.

Features and principle of operation of the remote light switch

Let's take a closer look at the wireless control system. It includes a set of equipment that is used to control the level of illumination in an apartment or house.

For control, not a standard switch is used, but a special remote control or telephone (this was partially mentioned above).

The control panel (depending on the model) can be designed for a different number of channels. It can affect one or a whole group of lamps (up to several dozen).

In the most advanced systems, switching is done using a motion sensor, which sends a signal to turn on the light if a person approaches the controlled area.

If you configure the motion sensor correctly, it will only respond to a person.

The remote switch is based on a radio transmitter. It is he who transmits the on/off signal to the lighting devices.

The range, as noted above, in most devices is up to 30 meters. But on sale you can find models capable of transmitting a signal over a distance of up to 300 meters.

The radio transmitter receives a signal from the remote control and then transmits it to light sources. The remote control usually has two channels, but there are also eight-channel models.

Control can also be carried out using a switch in which the transmitter is built.

Radar is often included with a wireless remote device. It is used to connect the remote control and sockets. With its help, control can be done via a mobile phone. Such devices are called GSM switches.

Management can be done in one of the following ways:


Characteristics you should pay attention to when choosing

When purchasing a wireless remote switch, you should pay attention to the following parameters:

  • The type of light bulbs the device controls;
  • Material, color and appearance of the case;
  • Operating voltage;
  • Number of channels;
  • Radius of action;
  • Dimensions;
  • Rated current;
  • Equipment.

It is also worth paying attention to the following criteria:

  • Operating frequency range;
  • Signal transmission method;
  • Availability of encoding;
  • Transmitter power type;
  • Estimated battery replacement time;
  • Fastening method;
  • Operating temperature range;
  • Price.

What does the market offer?

A wide range of wireless remote switches allows you to choose a product based on price, characteristics and appearance.

Below we consider just a few models that the market offers:

  • Fenon TM-75 is a switch with a remote control, made of plastic and designed for a voltage of 220 V. The features of the device include the presence of two channels, a 30-meter range, the presence of a remote control and a delay switch function.
    A group of lighting fixtures can be connected to each channel and controlled. The Fenon TM-75 wireless switch can be used with chandeliers, spotlights, LEDs, and other devices operating on 220 Volts.
  • Inted 220V is a wireless radio switch designed for wall mounting. It has one key and is installed in conjunction with the receiving unit. The operating voltage of the product is 220 Volts, and the range is 10-50 meters. The wireless light switch is attached using self-tapping screws or double-sided tape. The body is made of plastic.
  • INTED-1-CH - light switch with remote control. With this model you can control light sources remotely. The power of the lamps can be up to 900 W, and the operating voltage of the product is 220 V. Using a radio switch, you can control the equipment, turn on and off the lights or alarms. The product is based on a receiver and transmitter. The latter has the form of a key fob, which is small in size and transmits a signal over a distance of up to 100 m. The product body is not protected from moisture, so additional protection must be provided when installing outdoors.
  • Wireless touch switch controlled via remote control. The product is mounted on the wall, has small dimensions and is made of tempered glass and PVC. The operating voltage is from 110 to 220V, and the rated power is up to 300 W. The package includes a switch, remote control and bolts for attaching the accessory. The average life cycle is 1000 clicks.
  • Inted 220V 2 Receiver - Wireless Light Switch for Wall Mounting. Control is carried out using two keys. The body is made of plastic. The operating voltage is 220 V. The number of independent channels is 2.
  • BAS-IP SH-74 is a wireless radio switch with two independent channels. Control is carried out using a mobile phone on the Android operating system. To work, you must install the BAS application. The SH-74 model is used to control incandescent lamps with a power of up to 500 W, as well as fluorescent light bulbs (power limit - 200 W).
  • Feron TM72 is a wireless switch that controls lighting at a distance of up to 30 meters. The light sources are combined into a receiving unit, and switching on and off is done using the remote control. The TM72 model has two channels, each of which can be connected to a specific group of devices. The product has a large power reserve per channel (up to 1 kW), which allows you to connect different types of light sources. The big advantage of the model is the presence of a delay ranging from 10 to 60 seconds.
  • Wireless 3-channel switch 220V Smartbuy is designed for connecting light sources into three channels with a power limit of up to 280 W. The rated supply voltage is 220 V. Control is carried out from the remote control, which has a range of 30 meters.
  • Z-Wave CH-408 is a wall-type radio switch that allows you to program various scenarios for controlling lighting devices. If necessary, up to eight switches can be connected to it. Among the additional features, it is worth highlighting the management of Z-Wave devices (up to 80) and ease of configuration regardless of the main controller. The device is powered by two batteries, and when they are low, a corresponding signal is given. Firmware updates are performed via the Z-Wave network. The maximum distance to the controller should not exceed 75 meters. Protection class - IP-30.
  • Feron TM-76 is a wireless light switch that is controlled remotely using a radio signal. The receiver connects to light sources, and the remote control controls the receiving unit at a distance of up to 30 meters. The Feron TM-76 model has three independent channels, each of which can be connected to its own group of lighting fixtures. In this case, control will be carried out separately, using the remote control. The maximum power reserve is up to 1 kW, which allows you to connect various types of lamps (including incandescent). The operating voltage is 220 V.

How to connect a wireless remote switch with your own hands

Let's look at the procedure for connecting a wireless switch using the Zamel RZB-04 as an example.

The model is supplied with the following items:

  • 2-channel radio receiver of small size (type ROP-02);
  • 2-channel 4-mode radio switch (type RNK-04);
  • Fastening for installing the product (dowels with self-tapping screws, as well as foamed double-sided tape).

The receiver can operate in five different modes:

  • Inclusion. When the key is turned on, one or more lamps are ignited. You can set the activation to any of the key positions.
  • Shutdown. The principle is similar to that discussed above. The difference is that when you press the key, the light turns off.
  • Monostable. In this mode, the light will only be on while the button is pressed. After releasing it, the lamp turns off.
  • Bistable. In this case, each press leads to a change in state - turning on and off occurs cyclically.
  • Temporary. Here, after pressing the key, the light will remain on for a certain time. This option is useful when installing a wireless switch in a hallway, bedroom or long hallway. Upon entering, you can turn on the light, walk a certain distance (reach the bed), after which the light will turn off.

To correctly connect the receiver, carefully study the diagram. First, apply voltage (connect phase and neutral). Only a phase wire is laid to the switch, without a neutral, so it is installed in the place where the lamp (chandelier) is installed.

If you have a monolithic ceiling in which it is impossible to install the receiver, hide the product in a socket box. In other cases, the controller is installed at the base of the chandelier, which is considered the most convenient option.

To obtain a phase that will run continuously and constantly supply voltage to the receiving device, you need to turn on the switch or connect the wires directly.

The second option is preferred. Before performing this work, it is recommended to turn off the electrical power supply using the machine and check that there is no voltage.

Now you need to make an unbroken phase, for which the phase is connected to one of the wires going to the chandelier. To ensure maximum reliability, use VAGO terminal blocks.

When performing work, you should have a wiring diagram for the remote switch at hand.

It shows how to connect the device:

  • A phase wire must be connected to contact “L”. In this case, there is no need to run it through a switch - the product operates in constant mode.
  • Connect the neutral conductor, which is taken from the junction box, to the “N” terminal.
  • The phase that goes to a group or one lamp is connected to the “OUT1” contact. Here you will need the 0th conductor, which can be taken from the junction box or receiver (terminal N).
  • To “OUT2” connect the phase that goes to the second group or one lamp. As in the previous case, zero is taken from the junction box or from the receiver terminal block N.
  • Connect the pulse switch to “INT1”. The peculiarity is that when pressed, it only sends a short-term signal. After triggering, the operating mode of the 1st group of lamps changes. Thanks to this feature, the ROP-02 receiver can be controlled using a remote control or a stationary pulse switch.
  • A pulse switch (one or a group) must be connected to “INT2”. After clicking on it, the operating mode of the 2nd group will change. The principle here is the same as described above.

Now you need to combine the remote light switch with the receiving device, connect them to each other and decide on the operating mode. To do this, you first need to supply electricity.

Now select the appropriate operating mode for the switch. Most often, the standard option is suitable - when moving the switch up, it turns on, and down, it turns off.

To program this mode, do the following:


Reprogramming the second button is carried out according to a similar principle. The difference is that all manipulations will be performed with the second (unprogrammed) key.

Once the work is completed, proceed to install the product on the wall. For this purpose, the kit includes adhesive tape with a double-sided adhesive base, as well as dowels with self-tapping screws.

The easiest way is to use double-sided tape, because this does not require any tools. In addition, if necessary, you can change the position of the switch.

For ease of use, the double-sided tape is divided into four small squares, which are glued around the perimeter of the product; you must first remove the protective layer. All that remains is to place the switch in the chosen location according to the level.

The installation of the wireless remote switch is complete, and you can install a test lamp and then check the functionality of the system.

To do this, switch the key up - the light should light up, and down - it should go out. When the switch is activated, the indicator lights up.

Until recently, wireless remote switches were considered a new and unavailable technology. With the growth of production and competition, the price decreases, which makes the purchase accessible to everyone.

The main thing is to carefully approach the choice of product, understand the basic parameters and give preference to models from trusted manufacturers.

  • Internet of Things,
  • DIY or Do It Yourself
  • Good day, dear reader.

    A little lyrics at the beginning. The idea of ​​a “smart” light switch is not new at all and, probably, this is the first thing that comes to mind for those who have begun to get acquainted with the Arduino platform and IoT elements. And I am no exception to this. Having experimented with circuit elements, motors and LEDs, I want to make something more practical, which is in demand in everyday life and, most importantly, will be convenient to use, and will not remain a victim of experimentation for the sake of comfort.

    In this article I will tell you how I made a switch that will work like a regular switch (that is, one that is usually mounted on the wall) and at the same time allows you to control it via WiFi (or via the Internet, as is done in this case).

    So, let's make a list of what you will need to implement your plan. I’ll say right away that I intended not to spend a lot on components and chose the components based on reviews on the forums and the price-to-quality ratio. Therefore, some components may seem inappropriate here for experienced electrical enthusiasts, but please do not judge too harshly, because I'm just a beginner in electromechanics and would really appreciate comments from more experienced people.

    I also needed: a server with which the switch will be controlled via the Internet, an Arduino Uno with which I programmed the ESP, a router and consumables such as wires, terminals, etc., all this can vary depending on tastes and will not affect to the final result.

    Prices are taken from Ebay, where I bought them.

    And here is what the elements from the table look like:

    Now you can create a connection diagram:

    As you probably noticed, the scheme is very simple. Everything is assembled easily, quickly and without soldering. A kind of working prototype that you don’t need to tinker with for a long time. Everything is connected with wires and terminals. The only negative is that the relay did not fit into the switch socket. Yes, initially I planned to push it all into the wall behind the switch to make it look aesthetically pleasing. But to my regret, there was not enough space in the socket and the relay simply did not fit either lengthwise or across:

    Therefore, I temporarily moved the relay behind the socket until I found a suitable switch box with an outlet to hide the iron inside. But there is nothing more permanent than temporary, isn’t it? So it all looks like this now:

    Electrical tape will save you from electric shock... I hope.

    Now let's talk about the software part.

    And before we start analyzing the code and details, I will give a general scheme for implementing control of a light bulb.

    I hope that someday I will rewrite everything and the connection will be based on a faster protocol than HTTP, but for a start it will do. Remotely, the light bulb changes its state in approximately 1-1.5 seconds, and from the switch instantly, as befits a decent switch.

    Programming ESP8266-01

    The easiest way to do this is with Arduino. You can download the necessary libraries for the Arduino IDE from GitHub. All instructions for installation and configuration are there.

    Next we need to connect the ESP to the computer, for this you will need either a USB to Serial Adapter (such as FTDi , CH340 , FT232RL) or any Arduino platform (I had an Arduino Uno) with RX and TX outputs.

    It's worth noting that the ESP8266-01 is powered by 3.3 Volts, which means you should never connect it to an Arduino, which is (often) powered by 5 Volts, otherwise it will burn to hell. You can use a voltage reducer, which is shown in the table above.

    The connection diagram is simple: we connect TX, RX and GND of the ESP to RX, TX and GND of the adapter/Arduino, respectively. After this, the connection itself is ready for use. The microcontroller can be programmed using the Arduino IDE.

    A couple of nuances when using Arduino Uno:

    • The Uno has a 3.3V output, but it wasn't enough. When you connect an ESP to it, everything seems to work, the indicators are on, but communication with the COM port is lost. So I used a different 3.3V power supply for the ESP.
    • In addition, UNO did not have any problems communicating with ESP, given that UNO was powered by 5V, and ESP by 3V.
    After several experiments with the ESP8266-01, it turned out that the ESP is sensitive to the voltages connected to GPIO0 and GPIO2. At the moment of start, they should under no circumstances be grounded if you intend to start it in normal mode. More details about starting a microcontroller. I didn’t know this and I had to slightly change the scheme, because... in the ESP-01 version only these 2 pins are present and in my circuit both are used.

    And here is the program for ESP itself:

    Show code

    #include #include #include #include #include extern "C" ( // this part is required to access the function initVariant #include "user_interface.h" ) const char* ssid = "WIFISSID"; // WiFi name const char* password = "***************"; // WiFi password const String self_token = "xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx"; // token for minimal communication security const String serv_token = "xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx"; // token for minimal communication security const String name = "IOT_lamp"; // switch name, read light bulbs const String serverIP = "192.168.1.111"; // internal IP WEB server bool lamp_on = false; bool can_toggle = false; int button_state; ESP8266WebServer server(80); // web server HTTPClient http; // web client const int lamp = 2; // Control the relay via GPIO2 const int button = 0; // "Catch" the switch via GPIO0 // function for ping the light bulb void handleRoot() ( server.send(200, "text/plain", "Hello! I am " + name); ) // function for invalid requests void handleNotFound ()( String message = "not found"; server.send(404, "text/plain", message); ) // Let there be light void turnOnLamp())( digitalWrite(lamp, LOW); lamp_on = true; ) / / Let there be darkness void turnOffLamp())( digitalWrite(lamp, HIGH); lamp_on = false; ) // Send manual on/off events to the server. void sendServer(bool state)( http.begin("http://"+serverIP+"/iapi/setstate"); String post = "token="+self_token+"&state="+(state?"on":"off "); // Using the token, the server will determine what kind of device it is http.addHeader("Content-Type", "application/x-www-form-urlencoded"); int httpCode = http.POST(post); http.end (); ) // Change the state of the lamp void toggleLamp())( if(lamp_on == true) ( ​​turnOffLamp(); sendServer(false); ) else ( turnOnLamp(); sendServer(true); ) ) // Receive from the server enable command void handleOn())( String token = server.arg("token"); if(serv_token != token) ( String message = "access denied"; server.send(401, "text/plain", message); return; ) turnOnLamp(); String message = "success"; server.send(200, "text/plain", message); ) // Receive a command from the server to turn off void handleOff())( String token = server.arg(" token"); if(serv_token != token) ( String message = "access denied"; server.send(401, "text/plain", message); return; ) turnOffLamp(); String message = "success"; server.send(200, "text/plain", message); ) // Set the MAC to give the same IP void initVariant() ( uint8_t mac = (0x00, 0xA3, 0xA0, 0x1C, 0x8C, 0x45); wifi_set_macaddr(STATION_IF, &mac); ) void setup(void)( pinMode(lamp, OUTPUT ); pinMode(button, INPUT_PULLUP); // It is important to do INPUT_PULLUP turnOffLamp(); WiFi.hostname(name); WiFi.begin(ssid, password); // Wait until we connect to WiFi while (WiFi.status() ! = WL_CONNECTED) ( delay(500); ) // Assign functions to requests server.on("/", handleRoot); server.on("/on", HTTP_POST, handleOn); server.on("/off", HTTP_POST, handleOff); server.onNotFound(handleNotFound); // Start the server server.begin(); ) void loop(void)( server.handleClient(); // Check whether the switch is pressed button_state = digitalRead(button); if (button_state == HIGH && can_toggle) ( toggleLamp(); can_toggle = false; delay(500); ) else if(button_state == LOW)( can_toggle = true; ) )


    A couple of notes on the code:
    • It is very important to declare the GPIO0 pin as pinMode(button, INPUT_PULLUP), because In the circuit we do not use a resistor for this button. And ESP has its own “built-in” ones for these very purposes.
    • When catching the state of a button, it is advisable to set a delay when reading it to avoid false positives at the moment of pressing.

    WEB server programming

    Here you can give free rein to your imagination and use any available means to create a service that will process requests sent by the switch and send requests to turn it on/off.

    I used for these purposes

    In the modern world, the “smart home” system is becoming widespread. With its help, you can remotely control many elements and devices of our home. You can also remotely control the lighting in the room. Such inventions contribute to the comfort of a given room, and are also used where elderly people and people with disabilities live. This article will discuss how it works and why a Wi-Fi light switch is needed, which is gaining increasing popularity among the population.

    Strengths and weaknesses of the device

    Wi-fi light switch has the following advantages:

    1. There is no need to lay additional cable.
    2. It is possible to centrally control lighting devices, that is, from one command point. In order to control the wireless light switch, you can use a smartphone, tablet, computer, or remote control. For tablets and other electronic devices, you must install the necessary software. It can be downloaded from the Internet or installed from disk.
    3. Large signal coverage area. Despite the walls, the digital radio signal penetrates into the desired room.
    4. This system is very secure. Even if the structure of the device is damaged, this does not threaten the resident with a strong electric shock, because the Wi-fi switch has a very low current strength.
    5. The device works normally with all types of light bulbs (LED, incandescent, energy-saving).
    6. You can set different combinations, as well as operating modes of lighting fixtures.

    If we talk about the disadvantages of light switches, there are only a few. The main ones are that the price is much higher than conventional keyboard models and there is a certain risk of the batteries in the remote control being discharged or the Wi-Fi signal being poor.

    Design features

    The Wi-Fi switch kit includes a receiver and transmitter. The receiver is a control relay. You can control it via a smartphone with access to a Wi-Fi network, or using the remote control. When the relay receives a certain signal, it closes the electrical circuit. The relay is installed near or inside the lamp. This is possible due to the small dimensions of the device. The reason for installing the device near the lamp is so that it does not fall out of the radius in which the transmitter operates. If the room has spot lighting, the receiver can be placed in a distribution box or behind a suspended ceiling.

    The switch or transmitter has a small power generator that is capable of generating electricity when you press a button on the remote control or send a specific command from a smartphone via a Wi-Fi connection. In turn, the pulse is processed into a radio signal, which enters the device. Such radio-controlled light switches are quite expensive, and their analogue is control from a remote control that contains batteries.

    Types of switches and the best manufacturers

    At this time, the range of Wi-fi light switches is not very large. However, products are classified according to several criteria:

    1. The device can be adjusted with electronic or mechanical keys. In the first case we are talking about the touch screen of the device. The keys are on the remote control (remote control).
    2. There are also light switches with both and regular keypads. Using the first devices, you can adjust the brightness of the lighting, thereby changing its intensity. To adjust the brightness, either hold or scroll the corresponding button.
    3. This switch can provide full control of not only one, but also two or three groups of lighting devices. However, the price for a wireless device that can control entire groups is quite high.

    There are currently seven main manufacturers of wireless electrical accessories for lighting control:

    1. Legrand - country of origin: France. The company has a whole line of products called Celian.
    2. Vitrum is a country of origin: Italy. This company uses a technology called Z-Wave. It allows you to fully automate the control of lighting in the house.
    3. Delumo - products are manufactured by a Russian company, which in particular produces dimmers, switches and thermostats.
    4. Noolite – accessories are made by Belarusian manufacturers.
    5. Livolo is manufactured in China. This company produces specialized devices for automation. The product line also includes products for both single and double frames for switches.
    6. Broadlink (China). This manufacturer has a fairly large selection of products for lighting control.
    7. Kopou is the latest company that is also based in China. The manufacturer produces dimmers in the form of various key fobs.

    The video below provides an overview of another interesting model of Wi-fi light switch:

    Correct connection

    In order to properly mount the switch, you need to know its operating principle, what the device consists of, and how to connect the Wi-fi switch. The connection diagram for this wireless device is very simple.

    One of the advantages of a Wi-Fi light switch is its ease of use and connection. If you really want to, you can install the device yourself. It is important to strictly follow the instructions provided by the manufacturer. This installation takes only a few minutes.

    The connection process consists of only two stages:

    1. Installing a radio receiver.
    2. Installation of a light switch (control button).

    Basically, receivers have from two to four wires. They come out of the device body. To determine the input wire, you must read the instructions. The remaining wires will be output, for example, a double switch will have two outputs. To install the receiver, you must open the phase that supplies power to the lighting device and connect it to the circuit, while observing the sequence.

    In the case where it is necessary to connect more than one lighting group, proceed as follows:

    • zero is supplied to all lighting fixtures;
    • the phase is branched in the Wi-fi switch;
    • the phase should be supplied separately to each group of lamps.

    The control button is installed quite simply; first you need to make a hole in the wall using a hammer drill with a concrete cutter. A regular plastic socket box is inserted into the finished hole, and plaster can be used to secure it. The installation process is absolutely no different from the keyboard type. The only difference is that there is no need to lay wires, you just need to securely fasten the button in the socket.

    Like( 0 ) I do not like( 0 )