 << Continuation of Part 2

Let’s start assembling the board that will control the state of the washing machine cycle. Four things are needed: the microcontroller, its power supply (the microcontroller works at 3.3 volts, and the power adapter we’re using works at 5v), the door lock detector and the actuation over the “start washing cycle” button.

As stated above, the ESP-01 needs 3.3 volts to work, a ground connection and needs to have pulled high (using a resistor, like a 10kohm one for example) the GPIO0 and GPIO2 pins in order to boot correctly. Apart from that, an output pin will actuate the start button and an input pin will detect the door lock state.

The 3.3 volts power can be obtained using, for example, an LM317T, a famous classic voltage regulator that, using a couple of resistors allows us to get a specific voltage. Using one of the many online calculators, we can calculate which resistors we need. In my case, I used this one.

This was the configuration I kept, because I had 220 ohm and 120 ohm resistors laying around (I could use three 120 ohm resistors to get a 360 ohm resistor).

About detecting the door lock state, let’s remember the homemade light-sensing component I told you about in the last post. At one end of this component, the 230v of the doorlock will turn on the pilot light. At the opposite end, the photoresistor will sense that light and adjust its resistance: when the pilot light is on, the resistance will be low, when the pilot light is off, the resistance will be high. How high and how low? Let’s check using a multimeter:

Okay, now, how do we convert the resistance value into an input signal for our microcontroller?. If we were using an arduino, with its analog inputs, it could be used just powering a pin through the photoresistor, but our small ESP-01 doesn’t have any analog pins. What should we do then?

We can use a voltage divider for this. The idea is to put another resistor with a specific value in series with the photoresistor, and connect them between 3.3 volts and ground (we cannot use 5 volts, since the input pins of the ESP-01 are not 5v tolerant). The intermediate point of resistor and photoresistor must then have a sufficient voltage to be interpreted as HIGH (normally 75% of the working voltage, so about 2.47 volt in this case). For this to be this way, we need to calculate the second resistor to use. There are also online calculators for this, like this one, which I used.

Using a 39 kohm resistor, which I also have in my repertoire, we would have 2.57 volts, enough to be interpreted as a HIGH signal.

The actuator of the start cycle button is next. The idea is to bridge the terminals of the button. As stated in the last post, we will be using a relay for this. To assure that the current needed to energize the relay’s coil and thus phisically move the contact of the relay does not surpass the current that a pin of our ESP-01 can provide, we will be using a transistor to actuate the relay. I had several 2N2222 laying around, so I used one of them. The transistor will receive the activation signal on the base pin, and will let then pass current between emitter and collector, powering the relay. Also, it is a good idea to add a diode paralell to the relay’s coil, because when the coil is de-energize, its magnetic field returns a pulse in the opposite direction, and can destroy our transistor or microcontroller. I had some 1N4148 diodes, so I used one.

This is all we need for the hardware. I mounted everything in a perfboard, leaving phisical separations between the high voltage 230 volts part and the low voltage 3.3/5 volt parts, to avoid problems. The result was: