Difference between revisions of "Basics: Taming false positives"

From Let's Control It
Jump to navigation Jump to search
 
(11 intermediate revisions by 2 users not shown)
Line 1: Line 1:
{{WorkInProgress}}
 
 
 
= Introduction =
 
= Introduction =
  
It happens now and then.  
+
It happens now and then. Your brand new PIR sensor "flickers" it gives signals even if nothing moves. Or your temperature sensor value fluctuates now and then without an obvious reason. We will cover some measurements, hints and tips here. Additional suggestions and solutions are welcome (PM '''Shardan''' at the forum).
Your brand new PIR sensor "flickers" it gives signals even if nothing moves.
 
Or your temperature sensor value fluctuates now and then without an obvious reason.
 
 
 
We will cover some measurements, hints and tips here.
 
 
 
Additional suggestions and solutions are welcome (PM Shardan at the forum)
 
 
 
  
 
=Reasons=
 
=Reasons=
  
There are a lot of reasons why these quirks show up.
+
There are a lot of reasons why these quirks show up. Two things happen more often:
Two things happen more often:
 
  
First is the power supply. Even the best power supply generates some noise.
+
*First is the '''power supply'''. Even the best power supply generates some noise. Some factors will increase this.
Some factors will increase this.
 
  
Another reason: The ESP8266 is a high frequency transmitter. High frequencies  
+
*Another reason: The ESP8266 is a '''high frequency''' transmitter. High frequencies are well known for influencing other electronics. Always remember that high frequency's behavior is somewhat uncalculable and breaks the usual rules you may know from other circuits.
are well known for influencing other electronics. Always remember that high  
 
frequency's behaviour is somewhat uncalculatable and breaks the usual rules
 
you may know from other circuits.
 
 
 
A well known point too are weak voltage levels at the GPIO's
 
 
 
And last but not least - the false positives are no false positives. Just something
 
triggers the sensor which was not calculated into the build.
 
  
 +
*A well known problem are '''weak voltage levels at the GPIO''''s.
  
 +
*And last but not least - the false positives are '''not false positives'''. Just something triggers the sensor which was not calculated into the build.
  
 
==Power Supply==
 
==Power Supply==
  
It can't be mentioned enough: First rule: Keep off from cheap power supplies.
+
It can't be mentioned enough, keep off from cheap power supply units. Pay a bit more and get good quality. It definitely pays.
Pay a bit more and get good quality. It definitely pays.
 
  
But even a good PS has some limits.
+
But even a good PSU has some limits. Some example, you have a sensor outside and a wall plug PSU inside with a long cable between them. What will happen?
Some example: You have a sensor outside and a wall plug PS inside with a long
 
cable between them. What will happen?
 
  
The ESP takes some 50 mA if silent - if transmitting it increases to 150...200 mA.
+
The ESP takes some 50 mA if silent - if transmitting it increases to 150...200 mA. The cable you use has a resistance. Due to Ohm's law the changing current creates a voltage loss on the cable. It's not much, yes, but it might be enough to confuse a sensitive sensor.
The cable you use has a resistance. Due to Ohm's law the changing current creates
 
a voltage loss on the cable. It's not much, yes. But it might be enough to
 
confuse a sensitive sensor.
 
  
Besides that a bad fluorescent tube int he neighbouthood might generate spikes
+
Besides that a bad fluorescent tube in the neighborhood might generate spikes when starting or when switched off, same with a fridge or motors like pumps or similar machines. All this can travel through power supplies to your ESP and sensor causing wrong values and false positives.
when starting or when switched off, same with a fridge or motors like pumps or similiar.
 
 
 
All this can travel through power supplies to your ESP and sensor causing wrong values
 
and false positives.
 
  
 
==Filtering Voltage and High Frequency==
 
==Filtering Voltage and High Frequency==
  
What can be done?
+
What can be done? A good way to get rid of voltage spikes is a regulator directly at the ESP8266. Use a AM1117-3,3 or a LF-33 and place it as near as possible to the ESP. Then you may use a power supply that gives 5..8V output, all floating will be taken off by the regulator even with long power cabling.
  
A good way to get rid of voltage spikes is a regulator directly at the ESP8266.
+
But what if the spikes come from the ESP8266 itself? Nowadays sensors do not consume much current so filtering is easily possible. Some manufacturers recommend a filtering in their datasheets.
Use a AM1117-3,3 or a LF-33 and place it as near as possible to the ESP.
 
Then you may use a power supply that gives 5..8 Volt output, all floating will
 
be taken off by the regulator even with long power cabling.
 
 
 
But what if the spikes come from the ESP8266 itself?
 
 
 
Nowadays sensors do not consume much current so filtering is easily possible.
 
Some manufacturers recommend a filtering in their datasheets.
 
  
 
[[File:Filter_Types.jpg|600px]]
 
[[File:Filter_Types.jpg|600px]]
  
The schematics show three common types of power supply filters for different purposes.
+
The schematics show three common types of power supply filters for different purposes. Please don't take the values for given, they are determined just by "rule of thumb" as values for a start. You will have to test and optimize them if no values are given by the manufacturer.
Please don't take the values for given, they are determined just by "rule of thumb"
 
as values for a start. You will have to test and optimize them if no values are given
 
by the manufacturer.
 
  
Usually a bigger capacitor does not hurt, a bigger resistor might bring the sensor to fail.
+
Usually a bigger capacitor does not hurt, a bigger resistor might bring the sensor to fail. These filters all work as a so called "low pass" filter. The filter effect gets stronger the faster voltage changes occur or technically the higher the frequency is.
 
 
These filters all work as a so called "low pass" filter. The filter effect gets stronger  
 
the faster voltage changes occur or technically the higher the frequency is.
 
  
 
==Filter type 1==
 
==Filter type 1==
A very simple filter just to get rid of power fluctuiations, for example caused by the
+
A very simple filter just to get rid of power fluctuations, for example caused by the ESP when transmitting. Please note: This filter uses just an electrolytic capacitor. These are known for being slow so they can't filter high frequencies!
ESP when transmitting.  
 
Please note: This filter uses just an electrolytic capacitor. These are known for being slow
 
so they can't filter high frequencies!
 
  
One example for this is the TSOP 4843 IR receiver.
+
One example for this is the TSOP 4843 IR receiver. The TSOP is somewhat sensitive against power ripples and spikes. So the manufacturer recommends to use a simple type 1 filter: A 100 Ohm resistor and a electrolytic capacitor of at least 0,1µF.
The TSOP is somewhat sensitive against power ripples and spikes.  
 
So the manufacturer recommends to use a simple type 1 filter:  
 
A 100 Ohm resistor and a electrolytic capacitor of at least 0,1µF.
 
  
 
==Filter type 2==
 
==Filter type 2==
If you assume there might some high frequency traveling along the power wires
+
If you assume there might some high frequency traveling along the power wires this filter is your choice. But why two capacitors? That needs some explanation. The electrolytic capacitor type is able to buffer some energy. The bigger the capacitor the more energy it is able to store. This is helpful to equalize voltage spikes or drops. But due to their internal structure they are "slow", they can't follow fast changes as given by high frequencies. The type 2 filter adds a small ceramic type capacitor. This type is usually not available with high capacities but ceramic capacitors are very fast - they can
this filter is your choice. But why two capacitors? That needs some explanation.
+
catch high frequencies. So we use an electrolytic capacitor for voltage buffering and add a ceramic capacitor for high frequencies in this filter.
The electrolytic capacitor type is able to buffer some energy. The bigger the capacitor  
 
the more energy it is able to store. This is helpfull to equalize voltage spikes
 
or drops. But due to their internal structure they are "slow", they can't follow  
 
fast changes as given by high frequencies.
 
The type 2 filter adds a small ceramic type capacitor. This type is usually not  
 
availlable with high capacities but ceramic capacitors are very fast - they can
 
catch high frequencies. So we use an electrolytic capacitor for voltage buffering
 
and add a ceramic capacitor for high frequencies in this filter.
 
  
 
==Filter type 3 - So called π-filter [Pi-filter]==
 
==Filter type 3 - So called π-filter [Pi-filter]==
If you use a sensor that uses high frequencies (microwave movement sensor for example),
+
If you use a sensor that uses high frequencies (microwave movement sensor for example), it might be necessary to filter both sides, the ESP and the sensor, to get rid of high frequencies from the ESP and the sensor. This filter type does the job.
it might be necessary to filter both sides, the ESP and the sensor, to get rid
 
of high frequencies from the ESP and the sensor.
 
This filter type does the job.
 
  
 +
==Some hints for choosing capacitors:==
 +
There are a lot of types in the market. The electrolytic types do not really matter for ESP purposes, just grab one with an according voltage. For ESP's with 3.3V the capacitor should have 5V or higher. At the 5V sensors it should have 10V or higher. For experimenting with a breadboard just grab some 16V or 25V types. That will meet all your needs.
  
==Some hints for chosing capacitors:==
+
For the small capacitors definitely get a ceramic type, do not use film capacitors! Usual film capacitors are types like MKP, MKT or styroflex types for example. Film capacitors do not work well for high frequencies. Search for "ceramic capacitor" or for "X5R" or "X7R" capacitors. They are tested to work well and are availlable as wired and SMD types.
There are a lot of types in the market. The electrolytic types do not really matter
 
for ESP purposes, just grab one.
 
For the small capacitors definitely get a ceramic type, do not use film capacitors!
 
(Usual film capacitors are types like MKP, MKT or styroflex types)
 
Film capacitors do not work well for high frequencies.
 
Search for "ceramic capacitor" or for "X5R" or "X7R" capacitors.
 
They are tested to work well and are availlable as wired and SMD types.
 
  
==Rules of thumb for filters:==
+
==Rules of thumb for filters==
  
The bigger the capacitor, the better the filter works.
+
*The bigger the '''capacitor''', the better the filter works.
The bigger the resistor, the better the filter works.
+
*The bigger the '''resistor''', the better the filter works.
But remember: The bigger the resitor, the bigger the voltage loss for the sensor!
+
*But remember: The bigger the resistor, the bigger the '''voltage loss''' for the sensor!
  
 
+
==A hint for a special capacitor type==
==A hint for a special capacitor type:==
+
There are some rare capacitors with 6V and 47 / 100 / 220 µF in a X5R manufacturing at some dealers. Rare and somewhat expensife (up to 1€/piece).
There are some rare capacitors with 6V and 47 / 100 / 220 µF in a X5R manufacturing
+
One of these can be used instead of ceramic and electrolytic type together. This makes things easier....
at some dealers. Rare and somewhat expensife (up to 1€/piece).
 
One of these can be used instead of ceramic and electrolytic type together.
 
This makes things easier....
 
  
 
==Hints for placing filters==
 
==Hints for placing filters==
 
+
Just filtering power supply is easy, just place the capacitors and the resistor in a block to the power wire near the sensor. High frequency filtering is on a completely other note. Place the filter circuit as short as possible to the sensor. If you use a self created PCB, avoid thin ground tracks - use areas, ground planes instead. The picture shows an example of such a PCB.
Just filtering power supply is easy, just place the capacitors and the resistor in a block
 
to the power wire near the sensor.
 
 
 
High frequency filtering is on a completely other note.
 
Place the filter circuit as short as possible to the sensor.
 
 
 
If you use a self created PCB, do not use ground leads - use areas, ground planes.
 
The Picture shows an example of such a PSB.
 
  
 
[[File:PCB-Example.jpg|600px]]
 
[[File:PCB-Example.jpg|600px]]
  
 
+
Keep wires as short as possible. If possible use SMD types for the ceramic capacitors. Always remember: A ceramic capacitor of 100...220 nF must be placed at your ESP as short wired as possible between 3.3V and ground!
Keep wires as short as possible. If possible use SMD types for the ceramic capacitors.
 
 
 
Always remember: A ceramic capacitor of 100...220 nF must be placed at your ESP
 
as short wired as possible between 3,3V and ground!
 
  
 
=Weak Voltage at GPIO's=
 
=Weak Voltage at GPIO's=
Line 153: Line 75:
 
GPIO's are digital inputs. They have  well defined levels for
 
GPIO's are digital inputs. They have  well defined levels for
  
"LOW" <= 0,8 V
+
"'''LOW'''" 0.8V (less than 0.8V)
  
 
and
 
and
  
"HIGH" >=2,8 V
+
"'''HIGH'''" 2.8V (more than 2.8V)
 
 
in general (might vary slightly by chip and manufacturer).
 
  
If the voltage at the GPIO does not cover these levels fully
+
in general (might vary slightly by chip and manufacturer). If the voltage at the GPIO does not cover these levels fully the state is "undefined" - the result might be unpredictable.
the state is "undefined" - the result might be unpredictable.
 
  
First solution is a resistor connected to the GPIO with one side, the other
+
First solution is a resistor connected to the GPIO with one side, the other side connected to 3.3V (pull-up) or GND (pull-down) depending on circuit. Some plugins allow to activate the pull-up inside the ESP-chip. This may work, give it a try. But remember, these internal pull-ups are "weak". An external pull-up might work better for your circuit.
side connected to 3,3V (pull-up) or Gnd (pull-down) depending on circuit.
 
 
 
Some plug-ins allow to activate the pull-up inside the ESP-chip.
 
This may work, give it a try. But remember, these internal pull-ups
 
are "weak". An external pull-up might work better for your circuit.
 
  
 
==How to dimension?==
 
==How to dimension?==
This depends heavily on the sensors you use. Many
+
This depends heavily on the sensors you use. Many breakout boards with IR detectors e.g. for water/gas/electricity counters use a LM393 or similar, a ''comparator'' with an "open Collector" output. It can easily take a 1KOhm resistor. A sensor like the DS18B20 cannot take such loads, a higher resistor
breakout boards with IR detectors e.g. for water/gas/electricity counters
+
value (4K7...10K) should be used. Even I²C-lines from the ESP should use pull-ups depending on the length of the PCB leads or wires. for short leads and oen or two sensors the internal pull-ups will do. If you exceed two devices or about 10 cm wires or leads you should add external pull-ups of 10 KOhm down to 2.2 KOhm.  
use a LM393 or similiar, a comparator with an "open Collector" output.
 
It can easily take a 1KOhm resistor.
 
A seonsor like the DS18B20 cannot take such loads, a higher resistor
 
value (4K7...10K) should be used.
 
Even I²C-lines from the ESP should use pull-ups depending on the
 
lenght of the PCB leads or wires. for short leads and oen or two sensors
 
the internal pull-ups will do. If you exceed two devices or about 10 cm
 
wires or leads you should add external pull-ups of 10 KOhm down to 2,2 KOhm.
 
As a rule of thumb you may say: the longer the wires and the more I²C items
 
you use the lower should be the resistors.
 
Do not use less then 2,2 KOhm on I²C to avoid overloading the I²C-Chips.
 
(see i²C-Basics in the Wiki [Link])
 
  
 +
As a rule of thumb you may say: the longer the wires and the more I²C items you use the lower should be the resistors. Do not use less then 2.2 KOhm on I²C to avoid overloading the I²C-Chips. (see i²C-Basics in the Wiki [Link])
  
 
==Wich one? Pull-Up? Pull-Down?==
 
==Wich one? Pull-Up? Pull-Down?==
  
 
Good question, let me first say thank you to all my voters....
 
Good question, let me first say thank you to all my voters....
The answer: There is no general answer sadly.
 
It depends on your sensors and circuit.
 
Usually a pull-up is necessary, in rare cases a pull-down.
 
A rough rule might be: If your sensor has an output that works
 
against ground, a transistor pulling down voltage for example,
 
a pull-up resistor is your choice and vice versa.
 
  
Just test it on a breadboard first. With a 10 KOhm resistor
+
The answer: There is no general answer sadly. It depends on your sensors and circuit. Usually a pull-up is necessary, in rare cases a pull-down. A rough rule might be: If your sensor has an output that works against ground, a transistor pulling down voltage for example, a pull-up resistor is your choice and vice versa. Just test it on a breadboard first. With a 10 KOhm resistor it will just not work in worst case.
it will just not work in worst case.
 
  
Please keep in mind that some GPIO's must use pull-ups (GPIO 2, GPIO 0)
+
Please keep in mind that some GPIO's must use pull-ups (GPIO 2, GPIO 0) or pull-down (GPIO 15) to make the ESP boot correctly. Using a pull-down resistor on GPIO's 2 or 0 or a pull-up on GPIO 15 might lead to unwanted results. Use one of the other GPIO's (12,13,14) for testing first. If that works, try to move
or pull-down (GPIO 15) to make the ESP boot correctly.
 
Using a pull-down resistor on GPIO's 2 or 0 or a pull-up on GPIO 15
 
might lead to unwanted results.  
 
Use one of the other GPIO's (12,13,14) for testing first. If that works, try to move
 
 
to other GPIO's and test again if necessary.
 
to other GPIO's and test again if necessary.
  
 +
==Non-false positives==
  
==Non-false positives:==
+
You may run into a problem: You get false positives from a PIR or microwave sensors and you can't get it filtered, no matter what you try. We have seen several cases where these false positives are caused by a reason. The false positives are no real false, just caused by another reason just not considered
 
 
You may run into a problem: You get false positives from a PIR or microwave  
 
sensors and you can't get it filtered, no matter what you try.
 
 
 
We have seen several cases where these false positives are caused by a reason.
 
The false positives are no real falses, just caused by another reason just not considered
 
 
correctly with planning or placing the sensor.
 
correctly with planning or placing the sensor.
  
PIR sensors are a good example:
+
'''PIR sensors''' are a good example. Avoid exposing them to direct sunlight. The sun moves, even sun rays on the floor. Shadows cause warmer and colder areas. As the sun move the borders between warm and cold move - that's what the PIR sensor detects - and triggers just by sun.
Avoid exposing them to direct sunlight. The sun moves, even sunrays on the floor.
 
Shadows cause warmer and colder areas. As the sun move the borders between
 
warm and cold move - that's what the PIR sensor detects - and triggers just by sun.
 
 
 
Microwave movement sensors have some very own rules.
 
Depending on type thes detect in a radius of 5 ... 10 meters usually.
 
The detection area is a sphere with this radius - possibly detecting even through walls!
 
A dog moving in the floor above or a tree shaked by the wind outside next wall can
 
trigger such a "radar" sensor. No false positive, just badly placed sensor.
 
It is possible to "shield" a microwave sensor with aluminium foil in the case
 
or to use a case partly made of metal. The sensor will detect only to the directions
 
where no foil or metal resides.
 
Keep at least 3...5 centimeters of distance between shielding and sensor.
 
  
 +
'''Microwave movement sensors''' have some very own rules. Depending on type thes detect in a radius of 5 ... 10 meters usually. The detection area is a sphere with this radius - possibly detecting even through walls! A dog moving in the floor above or a tree shaked by the wind outside next wall can
 +
trigger such a "radar" sensor. No false positive, just badly placed sensor. It is possible to "shield" a microwave sensor with aluminium foil in the case
 +
or to use a case partly made of metal. The sensor will detect only to the directions where no foil or metal resides. Keep at least 3...5 centimeters of distance between shielding and sensor.
  
=Other reasons for strange behaviour=
+
=Other reasons for strange behavior=
  
A well known problem: Breadboards and breadborad cables
+
A well known problem: Breadboards and breadboard cables. Breadboards cause problems often. The contacts inside the board wear out from using, especially if you plug in pin headers from a WeMos or nodemCU often. Another problem are the breadboard cables. As usual you get what you pay for. Good breadboard cables are somewhat expensive. If you buy cheap cables from AliExpress, Banggood or similar sources, remember they might bring troubles to you. Contact problems occur now and then. Slack joints or no contact at all might come up. Change cables if you run into those problems. A digital multi-meter helps to find contact failures. (A cheap multi-meter will do in this case. A better one is recommended as it might help in other cases. Nothing is worse than bad tools.....)
Breadboards cause problems often. The contacts inside the board
 
wear out from using, especially if you plug in pinheaders from a  
 
WeMos or nodemCU often.
 
Another problem are the breadboard cables. As usual, you get what you pay for.
 
Good breadboard cables are somewhat expensive. If you buy cheap cables
 
from AliExpress, Banggood or similiar sources, remember they might bring troubles to you.
 
Contact problems occur now and then. Slack joints or no contact at all might come up.
 
Change cables if you run into those problems. A digital multimeter helps to find contact failures.
 
(A cheap multimeter will do in this case. A better one is recommended as it might help in other
 
cases. Nothing is worse then bad tools.....)
 

Latest revision as of 22:31, 22 August 2017

Introduction

It happens now and then. Your brand new PIR sensor "flickers" it gives signals even if nothing moves. Or your temperature sensor value fluctuates now and then without an obvious reason. We will cover some measurements, hints and tips here. Additional suggestions and solutions are welcome (PM Shardan at the forum).

Reasons

There are a lot of reasons why these quirks show up. Two things happen more often:

  • First is the power supply. Even the best power supply generates some noise. Some factors will increase this.
  • Another reason: The ESP8266 is a high frequency transmitter. High frequencies are well known for influencing other electronics. Always remember that high frequency's behavior is somewhat uncalculable and breaks the usual rules you may know from other circuits.
  • A well known problem are weak voltage levels at the GPIO's.
  • And last but not least - the false positives are not false positives. Just something triggers the sensor which was not calculated into the build.

Power Supply

It can't be mentioned enough, keep off from cheap power supply units. Pay a bit more and get good quality. It definitely pays.

But even a good PSU has some limits. Some example, you have a sensor outside and a wall plug PSU inside with a long cable between them. What will happen?

The ESP takes some 50 mA if silent - if transmitting it increases to 150...200 mA. The cable you use has a resistance. Due to Ohm's law the changing current creates a voltage loss on the cable. It's not much, yes, but it might be enough to confuse a sensitive sensor.

Besides that a bad fluorescent tube in the neighborhood might generate spikes when starting or when switched off, same with a fridge or motors like pumps or similar machines. All this can travel through power supplies to your ESP and sensor causing wrong values and false positives.

Filtering Voltage and High Frequency

What can be done? A good way to get rid of voltage spikes is a regulator directly at the ESP8266. Use a AM1117-3,3 or a LF-33 and place it as near as possible to the ESP. Then you may use a power supply that gives 5..8V output, all floating will be taken off by the regulator even with long power cabling.

But what if the spikes come from the ESP8266 itself? Nowadays sensors do not consume much current so filtering is easily possible. Some manufacturers recommend a filtering in their datasheets.

Filter Types.jpg

The schematics show three common types of power supply filters for different purposes. Please don't take the values for given, they are determined just by "rule of thumb" as values for a start. You will have to test and optimize them if no values are given by the manufacturer.

Usually a bigger capacitor does not hurt, a bigger resistor might bring the sensor to fail. These filters all work as a so called "low pass" filter. The filter effect gets stronger the faster voltage changes occur or technically the higher the frequency is.

Filter type 1

A very simple filter just to get rid of power fluctuations, for example caused by the ESP when transmitting. Please note: This filter uses just an electrolytic capacitor. These are known for being slow so they can't filter high frequencies!

One example for this is the TSOP 4843 IR receiver. The TSOP is somewhat sensitive against power ripples and spikes. So the manufacturer recommends to use a simple type 1 filter: A 100 Ohm resistor and a electrolytic capacitor of at least 0,1µF.

Filter type 2

If you assume there might some high frequency traveling along the power wires this filter is your choice. But why two capacitors? That needs some explanation. The electrolytic capacitor type is able to buffer some energy. The bigger the capacitor the more energy it is able to store. This is helpful to equalize voltage spikes or drops. But due to their internal structure they are "slow", they can't follow fast changes as given by high frequencies. The type 2 filter adds a small ceramic type capacitor. This type is usually not available with high capacities but ceramic capacitors are very fast - they can catch high frequencies. So we use an electrolytic capacitor for voltage buffering and add a ceramic capacitor for high frequencies in this filter.

Filter type 3 - So called π-filter [Pi-filter]

If you use a sensor that uses high frequencies (microwave movement sensor for example), it might be necessary to filter both sides, the ESP and the sensor, to get rid of high frequencies from the ESP and the sensor. This filter type does the job.

Some hints for choosing capacitors:

There are a lot of types in the market. The electrolytic types do not really matter for ESP purposes, just grab one with an according voltage. For ESP's with 3.3V the capacitor should have 5V or higher. At the 5V sensors it should have 10V or higher. For experimenting with a breadboard just grab some 16V or 25V types. That will meet all your needs.

For the small capacitors definitely get a ceramic type, do not use film capacitors! Usual film capacitors are types like MKP, MKT or styroflex types for example. Film capacitors do not work well for high frequencies. Search for "ceramic capacitor" or for "X5R" or "X7R" capacitors. They are tested to work well and are availlable as wired and SMD types.

Rules of thumb for filters

  • The bigger the capacitor, the better the filter works.
  • The bigger the resistor, the better the filter works.
  • But remember: The bigger the resistor, the bigger the voltage loss for the sensor!

A hint for a special capacitor type

There are some rare capacitors with 6V and 47 / 100 / 220 µF in a X5R manufacturing at some dealers. Rare and somewhat expensife (up to 1€/piece). One of these can be used instead of ceramic and electrolytic type together. This makes things easier....

Hints for placing filters

Just filtering power supply is easy, just place the capacitors and the resistor in a block to the power wire near the sensor. High frequency filtering is on a completely other note. Place the filter circuit as short as possible to the sensor. If you use a self created PCB, avoid thin ground tracks - use areas, ground planes instead. The picture shows an example of such a PCB.

PCB-Example.jpg

Keep wires as short as possible. If possible use SMD types for the ceramic capacitors. Always remember: A ceramic capacitor of 100...220 nF must be placed at your ESP as short wired as possible between 3.3V and ground!

Weak Voltage at GPIO's

GPIO's are digital inputs. They have well defined levels for

"LOW" ≤ 0.8V (less than 0.8V)

and

"HIGH" ≥ 2.8V (more than 2.8V)

in general (might vary slightly by chip and manufacturer). If the voltage at the GPIO does not cover these levels fully the state is "undefined" - the result might be unpredictable.

First solution is a resistor connected to the GPIO with one side, the other side connected to 3.3V (pull-up) or GND (pull-down) depending on circuit. Some plugins allow to activate the pull-up inside the ESP-chip. This may work, give it a try. But remember, these internal pull-ups are "weak". An external pull-up might work better for your circuit.

How to dimension?

This depends heavily on the sensors you use. Many breakout boards with IR detectors e.g. for water/gas/electricity counters use a LM393 or similar, a comparator with an "open Collector" output. It can easily take a 1KOhm resistor. A sensor like the DS18B20 cannot take such loads, a higher resistor value (4K7...10K) should be used. Even I²C-lines from the ESP should use pull-ups depending on the length of the PCB leads or wires. for short leads and oen or two sensors the internal pull-ups will do. If you exceed two devices or about 10 cm wires or leads you should add external pull-ups of 10 KOhm down to 2.2 KOhm.

As a rule of thumb you may say: the longer the wires and the more I²C items you use the lower should be the resistors. Do not use less then 2.2 KOhm on I²C to avoid overloading the I²C-Chips. (see i²C-Basics in the Wiki [Link])

Wich one? Pull-Up? Pull-Down?

Good question, let me first say thank you to all my voters....

The answer: There is no general answer sadly. It depends on your sensors and circuit. Usually a pull-up is necessary, in rare cases a pull-down. A rough rule might be: If your sensor has an output that works against ground, a transistor pulling down voltage for example, a pull-up resistor is your choice and vice versa. Just test it on a breadboard first. With a 10 KOhm resistor it will just not work in worst case.

Please keep in mind that some GPIO's must use pull-ups (GPIO 2, GPIO 0) or pull-down (GPIO 15) to make the ESP boot correctly. Using a pull-down resistor on GPIO's 2 or 0 or a pull-up on GPIO 15 might lead to unwanted results. Use one of the other GPIO's (12,13,14) for testing first. If that works, try to move to other GPIO's and test again if necessary.

Non-false positives

You may run into a problem: You get false positives from a PIR or microwave sensors and you can't get it filtered, no matter what you try. We have seen several cases where these false positives are caused by a reason. The false positives are no real false, just caused by another reason just not considered correctly with planning or placing the sensor.

PIR sensors are a good example. Avoid exposing them to direct sunlight. The sun moves, even sun rays on the floor. Shadows cause warmer and colder areas. As the sun move the borders between warm and cold move - that's what the PIR sensor detects - and triggers just by sun.

Microwave movement sensors have some very own rules. Depending on type thes detect in a radius of 5 ... 10 meters usually. The detection area is a sphere with this radius - possibly detecting even through walls! A dog moving in the floor above or a tree shaked by the wind outside next wall can trigger such a "radar" sensor. No false positive, just badly placed sensor. It is possible to "shield" a microwave sensor with aluminium foil in the case or to use a case partly made of metal. The sensor will detect only to the directions where no foil or metal resides. Keep at least 3...5 centimeters of distance between shielding and sensor.

Other reasons for strange behavior

A well known problem: Breadboards and breadboard cables. Breadboards cause problems often. The contacts inside the board wear out from using, especially if you plug in pin headers from a WeMos or nodemCU often. Another problem are the breadboard cables. As usual you get what you pay for. Good breadboard cables are somewhat expensive. If you buy cheap cables from AliExpress, Banggood or similar sources, remember they might bring troubles to you. Contact problems occur now and then. Slack joints or no contact at all might come up. Change cables if you run into those problems. A digital multi-meter helps to find contact failures. (A cheap multi-meter will do in this case. A better one is recommended as it might help in other cases. Nothing is worse than bad tools.....)