Tag Archives: ESP8266

ULTRASONIC WATER LEVEL SENSOR

#106 AJ-SR04M ultrasonic distance sensor for water

looks like a STM8S003F3 MCU, unmarked crystal and unmarked TTL IC
Underside has a 2 pin socket and is quite dirty…

Recently I have had an old mildly annoying problem snowball into a new serious problem…

Every few months the clean water supply from uThukela Water (Pty) Ltd has been switched off for multiple reasons… striking, damaged electric motors due to Eskom, sabotage and other issues to name a few very serious reasons.

So two large 2500L water tanks were installed in series as a backup which worked well for small water issues that would last maybe a week or two.

However recently There has been no water from uThukela for over a month, and this is very serious.

This event triggered me to investigate water related problems and solutions specifically for my use case.

Order of importance:

  1. I need readily available clean drinking water
  2. Store this water for longer (get extra tanks)
  3. Keep water safely in the tank (no contaminates)
  4. Add sensors to monitor (water level sensor in this case)

For this article will be focusing on the 4th order of importance since this is a tutorial website mainly about electronics.

Therefore I will start by saying I searched for a suitable water level sensor and came across the JSN-SR04T and clones.

This sensor looks very promising and easy to use with 6 available sensor modes (adding increased diversity).

N.B the copy does not have 6 extra modes which was disappointing considering their price point…

2.2m wire with the sensor at the end.

The copy has 3 modes and is similar to the JSN-SR04T-2.0

Now my goal is to use the JSN-SR04T with an ESP8266 connected via WiFi to send readings to my server every 30s, this unit will be completely powered by solar.

The ESP8266 will also have a LAN dashboard to view the readings in real time connected to WiFi but with a connection to the internet not needed, just in case the internet goes down I can still read the water level values.

unfortunately finding a commonly available original JSN-SR04T Ultrasonic Distance Sensor has been quite difficult in South Africa.

I have only been able to find the AJ-SR04M (functions like the JSN-SR04T-2.0) which is a clone but works just like the original, however I see the price is equivalent and sometimes even more than the original which is quite strange. An of course the extra modes are missing…

The waterproof sensor
The sensor is epoxied and completely sealed looks easy enough to install

Mode 1: R27 = is open.

The sensor returns an analogue signal. The formula to calculate the distance from the data is:

Test distance = (high time * speed of sound (340M / s)) / 2;

Mode 2: R27 = A 47K resistor is soldered.

Every 100ms serial data will be sent in mm.

Serial baud rate: 9600, n, 8,1.

The frame format is: 0XFF + H_DATA + L_DATA + SUM
1.0XFF: for a frame to start the data, used to judge;
2.H_DATA: the upper 8 bits of the distance data;
3.L_DATA: the lower 8 bits of the distance data;
4.SUM: data and, for the effect of its 0XFF + H_DATA + L_DATA = SUM (only low 8)

Mode 3: R27 = A 120K resistor is soldered.

Good for low power applications.

After the module is powered on, the module enters standby mode.

If the module receives 0X55 it will send data over serial.

Serial baud rate: 9600, n, 8,1.

Datasheet for the stm8s003f3

CUSTOM MOSFET PCB

#99 Custom WiFi Mosfet PCB with battery backup

Version 1.0 of the protoboard not as appetizing as the schematic…
Reverse side with thicker black wires for the MosFets.

Creating a a custom 4ch Mosfet switch PCB with a built in backup 12v battery changeover circuit takes some careful planning. Since I had experience working with mechanical relay versions the task was not too difficult however it did come with a few extra challenges.
Mosfets require more parts to work reliably they also have significantly different ratings when compared to relays. In this case I was using an esp8266 with 3.3v logic. I had to create an amplifying circuit out of two transistors in order to get around 6.6V to allow the Mosfets to turn on completely thus allowing me to utilize their max current ratings.

The beginning of prototyping always looks so clean…
Bread Board prototyping is always a good idea before soldering.

On my 4ch PCB I used 3x IRL520N and 1x IRLZ44N N channel Mosfets. The IRLZ44N is the best rated for logic level and also the most expensive and rare here at least at this time. I also needed a large amount of amps for the LED strips it was going to switch on and off. The other three IRL520N Mosfets will be used with applications using under 5A of current. Technically I could have just used TIP120 NPN transistors but I wanted to keep the entire PCB Mosfet compatible in case I wanted to swap out any chips.

Drawing block diagrams by hand help the though process.
Creating a clean schematic in KiCad makes building the board easy.

For more info on the project check it out on Github

DIY BATTERY + WIFI 4CH RELAY PCB

#88 A DIY battery + WiFi relay solution

With the ever growing pains of load-shedding looming over South Africans people have been desperately looking for viable alternative energy and battery powered devices. In my case I needed my remote pepper spray devices to be operational in my laboratory even during extended load-shedding times 4h off with 2h charge times.

I could have purchased added a battery and charging circuit to my existing factory made Sonoff board however that could make the PCB larger and I wanted to build a custom solution instead.

My requirements were WiFi capability, at least 4 relays, li-ion battery powered, battery charger with all the standard protection features and for the device to be powered by 5v from a standard phone charger.

The device must be plugged into the 5v phone charger 24/7, when the electricity goes off the device must continue to operate uninterrupted, when the power comes back on the device must change to the charge state uninterrupted.

The device does not have to send a notification when using battery but it must protect from overcurrent and over-discharge.

While looking for components I came across the ESP8266 PSB 04 module which is basically just the MCU WiFi controller used to switch 4 channels by itself

This was perfect for my application because I am already very familiar with Sonoff devices and in this case I do not mind using the firmware on the esp8266 and the Sonoff application + API software for my automation tasks.

Building around the module was a breeze all I needed was the appropriate relay circuits and a decent charging module.

I ended up creating two prototypes because hey there’s always improvements to be made…

Drill holes for terminals and relays
ESP8266 board with buttons, led and 3.3v regulator
Headers to mount LiPo and ESP8266 boards

The components I used on my final version 1.1 are as follows:

  • 4x Songle 10A relays here
  • 4x BC547 transistors here
  • 4x screw terminals here
  • 4x 1N4148 diodes here
  • 4x red led 3mm here
  • 1x yellow led 5mm here
  • 1x LiPo charger MH-CD42 (IP5306 chip on mine) here
  • 1x USB-A male cable here
  • 1x ESP8266 PSB-B04-CN Module 4-Channel Switch here
  • 1x AMS1117 3.3 800mA regulator here
  • 2x 10uf 25v caps here
  • 2x 100nf 25v caps here
  • 1x 18650 battery holder here
  • 1x old laptop battery 18650 (LGABD11865)
  • 9x 1k resistors here
  • 2x small cable ties
  • Various male and female headers

I tried to make the design as modular as practically possible

There are 3 main parts in the design consisting of a main PCB which contains the battery and relays = complementary components then the WiFi module with buttons and 3.3v regulator is located on a small green PCB and finally the LiPo MH-CD42 module can be secured on the main board via headers.

While constructing I had to use a 1.6mm drill bit for the battery holes and a 1.5mm drill bit for the relay holes. I soldered the SMD AMS1117 reg onto 3 a pin male header for easy through hole placement. The relays and the screw terminals required more attention during drilling and placement of the holes due to their pin layout. I also coated all exposed wires with nail varnish as a make shift solder mask.

I had to add an extra 1000uF capacitor between GND and 5v out of the LiPo module because it would briefly lose power when transferring from USB to battery power

Version 1.0 with lots of hot glue and test points
Version 1.1 board layout

ESP8266 DEV BOARD

#65 ESP8266 DEV BOARD

Board

This is an ESP8266 equipped with 32M of flash memory. It is compatible for NodeMCU board (Lua based ESP8266). The additional memory this unit has allows for bigger projects with complicated and large libraries. It features an onboard USB-TTL Serial converter (CH340G chip) and a Micro-USB female connector. It comes with two sets of 15 pins headers to give you the freedom of choosing whether soldering directly onto the pin holes for a more compact approach.

  • Capable of WIFI networking (IOT): Access-Point, station or Web Server etc.
  • Uses simple LUA based programming language
  • Supports Arduino IDE
  • Event-driven API for network applications
  • 9 GPIO pins D0 – D8 featuring PWM functionality, I2C and SPI communication
  • Operating Voltage: 4.9 – 9 VDC
  • Dimensions: 49 x 26 x 5mm
  • Weight: 10g
Pin out.
Useful links can be found here

ESP01 + RELAY MODULE

#63 ESP01 + RELAY MODULE

ESP01 + v4 relay module.

While looking for a cheap wireles relay solution I found the ESP01 + relay module package.

This ESP-01 Relay Module based on AI-Thinker ESP-01/01S WIFI module. It is designed for smart home, internet of thing and others DIY project. With this smart relay, you will easy to DIY your smart switch to control any device by your phone anywhere using the popular ESP01.

The board is surprisingly small and has a thin PCB.

Relay module bottom.
Relay module top.
Close up.
Pin out
ESP01 pin out
ESP board types

FREE HA SERVER SETUP

#61 FREE HOME ASSISTANT SETUP

Since I have been using a ton of ESP8266 and ESP32 devices in my projects I decided to look for a suitable server with a good track record. During my research I singled out Home Assistant coupled with the ESPHOME Add-on as my go to software.

The ESPHOME Add-on is perfect for my projects since it does not require a MQTT broker and supports both the ESP8266 and the ESP32 development chips.

Step 1: Install Home Assistant on a suitable device to act as the server ( in my case it was on a Raspberry Pi 4 B) Link to install instructions here.

Step 2: Setup Port Forwarding/Virtual Server for port 8123 and DMZ Settings + uPnP.

On my D-Link router I had to setup a virtual server for port 8123 using internal static IP 10.0.0.9

I setup 10.0.0.9 to my DMZ host address and enabled it.

I enabled uPnP for my router.

Step 3: Setup Duck DNS for your Home Assistant server.

Go to Duck DNS create an account and setup your domain name then copy your token to paste in HA.

On your HA panel install the DuckDNS Add-on and go to configuration. There paste your token and domain name. Also change the accept_terms to: true.

Using the file editor navigate to /config/configuration.yaml and insert your certificate and key paths.

Step 4: Restart Home assistant.

Go to configuration-> server controls->restart to restart HA.

If you are using LTE with Telkom ( like me in South Africa ) be sure to set your APN to unrestricted …. link to tutorial here.

Once your server is up and running and using HTTPS instead of HTTP you can download the HA APP to your mobile device and insert your DuckDNS domain name into the Home Assistant URL field.

Tap on Enter Address Manually.

Enter your URL.