Tips on designing project in IoT

Hi everyone!

I am designing my first project in IoT, however I have some experience in electronics.

My design is a typical scenario, a board reading a sensors and publishing data in a MQTT broker by WiFi, but with some special restrictions:

  • The project is powered by batteries
  • The sensors are two CWT TH-S (Soil moisture and Temperature) which has a power range of 4.5v-30v

My thoughts:

  1. Choose an appropriate board.
    I have investigated about what SoC will be appropriate for this project, Arduino, ESP32, ESP8266, ESP8285, RP2040 (Raspberry Pi Pico)... and as far as I know the best for low consumption is ESP8266. Correct me if I am wrong. Now I need to choose a board with that SoC. The most recommended are NodeMCU, Wemos D1 and Espressif ESP8266-DevKit. One of the key differences is if 3.3v input is connected or not to the voltage regulator, to avoid an unnecessary draw. Also ESP12E board is a good option, as it is said to have very low power consumption in deep sleep mode compared with the rest (it is a bare chip, with no FTDI). Obviously the board will read the sensor and then deep sleep. Selecting a board will depend on the next factors.

  2. The batteries
    Here my initial objective is to get the project powered only with batteries, it could be AAA batteries, Lithium CR123, Lithium rechargeable batteries... I don't really mind. I want it to last for about 3/6 months. I know it will be difficult. One sensor read every 30 minutes will be ok, and then deep sleep. As I know this could be difficult to achieve I am thinking of adding a small solar panel as a second option.

  3. Power the sensors
    I think this will condition the full design, as SoC needs 3.3v and the sensor needs at least 4.5v, so I think I can not power by a GPIO pin. My first thought is using something around a 5v battery to power the board and the sensor, taking the power from Vin or VU, but... will the sensor consume power when the SoC is on deep sleep? Perhaps I need a more advanced circuit to cut off the power to the sensors too (a MOSFET acting as a switch controlled by GPIO?).

  4. RS485 adapter
    To communicate with the sensor I also need a RS485 board. I think the MAX485 RS485 is a good option (it uses 5v) but I don't know if someone will advise me of a different option.

I have read some tips about reducing the consumption of the board, like removing leds or replacing the LDO by one with minor quiescent current, or selecting a board with minimum components, with no FTDI, etc.

So at the moment I need your experience about similar projects powered by batteries:

a. Do you think solar panel is mandatory or I could get 3-6 months only with batteries?

b. How could I power the sensors and the RS485 and cut that power when the SoC is in deep sleep? or is this unnecessary because that consumption is not appreciable?

c. Should I use a SoC different from ES8266?

PD: Now that I write it... I think it should be easier going solar...

1 Like

MAX3485 is for 3V3 if needed.

1 Like

Thanks! One problem solved.

Read this manuall for correct RS485 wiring.

Finally I have decided to add a solar panel to the project. What I have lernt is that if you want your project run in batteries yo should forget about devolopment boards and start with a bare ESP8622, avoiding unnecesary consumtions (low quality LDO, FTDI, etc.)

I will open a new post with the details and the doubts

Thanks all!

1 Like

You can use a IO pin to switch the probe on/off through a FET, solves the voltage diff.

Great! How I decide what kind of FET do I need?

My idea is powering a step up booster from the output of a TP4056 (2.4 - 5v), which will power the sensors. So, the FET should be between the TP4056 and the step booster, and should be controlled by an ESP8266 GPIO pin, which should cut the line when in deep sleep

Hm, can you upload a schematic over the circuit, to enable us to better understand?

The FET would have to be a N-chan Logic level, with Vgs(th) lower than 3.3 V so the ESP properly can switch the FET on. Max voltage, if you would calculate with that being 15 V, double that and you're up to 30 V. You then have a safety margin, perhaps you wanna do another project after this and needs a FET again. The same goes for current, this sensor uses ... was it 20 mA? Get a FET rated for 5 A, and once again, you can use it for future project. After this checklist it's a matter of your preferences, SMD if you are confident in soldering, otherwise THT.

What I have selected at the moment:

  • A solar panel: 5V 230mA

  • A battery charger: TP4056 with dual protection (4.5v-5.5v 1A)

  • A NCR18650B battery 3.7v 3400mAh

  • A Lolin Wemos D1 Mini Pro v2.0.0 ESP8266EX

  • A Lolin Wemos battery shiled v1.3.0

  • A MT3608 Boost module DC-DC Step up converter (input 2-24v, output 5v)

  • A MaX3485 TTL to RS485 module 3.3v

  • Two CWT TH-S soil moisture and temperature sensors RS485 (4.5-30v) (max 0.5W@24V DC)

My doubts are:

  1. I am using a TP4056 to charge the Lithium18650 through the solar panel and power the D1 Mini Pro, but the version v2.0.0 of the D1 Mini Pro has its own Litio Charger built in (a TP4050). However I have not seen any project using the D1 Mini Pro charger fed by a solar panel. I can not find any information about over/under discharge protection of the battery. Could I remove the TP4056 and connect the solar panel directly to the built-in Lithium charger of the D1 Mini Pro v2.0.0 ?

  2. As you can see I have added an unnecessary Lolin Wemos battery shield but this is because it could be used for two purposes. Battery voltage monitor and step up booster (to 5V) to power the sensors. As the D1 Mini Pro has its own battery charger I think I could monitor the battery voltage directly in the D1 Mini Pro (using SJ1 by the analog read pin). If I use the external TP4056 charger module, can I connect the 18650 battery directly to the D1 Mini Pro too? The D1 Mini Pro will be powered by two channels, from the TP4056 output and from the Lithium battery connector.

  3. Concerning the feed of 5v sensors, I could use the Wemos Battery Shield, which has a voltage booster, or I could use a MT3608 external module which has an adjustable resistor. Which of them will be a better option? Anyway this module should be unpowered when ESP8266 goes deep sleep, as @ledsyn says probably using a FET.

Keep in mind that 5V 230 mA is the max you get from the panel, under perfect conditions. Also the charger is a regular one, it doesn't come with MPPT (squeezes most out of solar panels).

I don't see it would kill something, and if you can simplify and perhaps shrink power usage, why not.

Perhaps builtin charger also comes with the benefit of a interface to the battery management?

No idea.

Good schematic there. What is the turquoise wires function?

The thing is I don´t know if the built in charger of the D1 Mini Pro has under voltage protection or not. I can´t find that information. However I have read into a forum that it has it, and there is someone using it with solar panel. So I will remove the external charger module.

From battery shield A0 to D1 mini Pro A0 is to read the battery voltage. Now that I am going to avoid the external battery charger and connect the 18650 directly to the D1 mini Pro I will not need that wire, because I will read the voltage battery from the D1 mini Pro. However I still will need the Battry shield to get the "5v step up booster" to power the sensors (or use a different module for that function)

If the setup isn't located far away, you have the option to experiment

You should put a N-chan FET on the return (black) wire between the booster and battery, and program the ESP to shut off the booster and then enter sleep. Word of advice: A sensor can be 'tired' when it's been powered up. Usually the datasheet will tell you this, or you can check how long before the readings have stabilized and use that + extra time to read proper data.

That's exactly what I need, some way to shut off the booster. Can you tell me some reference number or some link to some project which use it?

Perhaps an AO3400?

Seems like an excellent choice, and since you suggested that model I take it you're familiar with SMD.

Here's another FET, available as both THT and SMD, slightly more RDSon than your suggested.

https://www.mouser.com/c/semiconductors/discrete-semiconductors/transistors/mosfet/?series=IRLZ&instock=y

Absolutely not :joy:. I am not comfortable with SMD but I don't find it in THT.

Thanks for the suggestion.
What does "more RDSon" means?

Google it :slight_smile: It's an important characteristics of a MOSFET, and while at it, look up Vgs too. When reading DiY projects etc, you might think a MOSFET is a simple silicone switch, but there's a lot more to them.

What's your idea of the setup, how long will it sleep in between readings?

I want it running as much as posible. I think once every 10 minutes is ok.

With the solar panel I think it will be posible, because I live in Murcia (Spain) where we have lot of sunny hours every day and almost any cloud. So I think the battery will be charged every day. Even I think it will be a problem, because Lithium batteries does not like to be at 100% most of the time.

Anyway, once per hour will be an acceptable frecuency. I will try to dinamically set the sleep frecuency based on battery voltage

Should be ok, you will have to experiment with it. Best for you would be if it will be installed nearby so that you can oversee the setup, or at least that you can test run it before it's deployed.

Anyway, good luck and if you care to, keep us up to date with the project!

Hi again! I have built the circuit and it is working like this:

All works, Wemos D1 reads the sensors and publish to my MQTT broker, and the solar panel charges the battery. But I have a big problem: When ESP8266 goes to deep sleep sensors drain the battery. They consume about 50mA (+2mA of the booster) all the time. So, I have to switch them of. Even better, switch off the step up (which powers the sensors).

AFAIK this could be two ways: low side switch or high side switch. The easy way is low side switch.

Low side switch could be done three ways:

  1. With a BJT NPN transistor
  2. With a MOSFET N channel
  3. With a BJT NPN driving a MOSFET N channel

I have found a MOSFET in my draw (a K3567) and I have test option 2, but there is a problem: this MOSFET requieres 5v at gate, and ESP8266 provides it 3.3v (through a GPIO). So I need another MOSFET (perhaps IRL540 or IRLZ44N) or... using a BJT transistor as a driver of the Mosfet (option 3).

I have found some NPN transistors SS8050 in the same draw, but I am not sure if I could use this NPN transistor to drive the K3567 MOSFET. This is I want to do:

npn_driver

But I do not feel confident enough to calculate the value of the resistors, or to decide if that NPN is right or not.

At the end, I will buy a MOSFET which gate works on 3.3v GPIO, but is not easy to get electric components in my city, so I would like to try with the PNP driver + 5v gate MOSFET.

PD: What about option 1? Could I switch on/off the booster using only de PNP (whitout any MOSFET)?

With options 1 and 2 I could switch off the step up booster (and therefore the sensors), but with option 3 I only could switch off the sensors (not the booster) because I need the 5v of the booster into the gate of the Mosfet. Correct me if I wrong.

I want to know your opinions, even if you think that I must use an high side switch

Lot of thanks

Hi there!

Sweet, you got it all connected, now all that's left is that 50 mA drain to take care of.

Getting hold of components locally is pretty hard nowadays imho, you're better off to order online. I have fetched a lot of stuff from Farnell (AFAIK they only deal with companies) and Mouser, but you can shop at lower prices from Amazon, Alibaba etc.

How much current do the whole sensor package draw?