Professional Documents
Culture Documents
Since I am not the King and as a result of that you’re not the Queen, I would use my kitchen scale to
solve this riddle. Put a Coke glass on it, the one with the 0.4l volume marker, pour some air into it
and look at the display to see how much weight I added to the empty glass.
Stefan setzen sechs. So at home I took an air pump, a closed cylinder with water included and started
the pump.
104,8 ml * 1,293 g
______________ = 0,135 g
1000 ml
The brain
The ESP8266 is a low-cost Wi-Fi microchip, with a full TCP/IP stack and microcontroller
capability, produced by Espressif Systems[1] in Shanghai, China.
We will be using a guy like this. I like the small
form factor and the power supply and
communication can be done by USB.
The Software
I have chosen ESPEasy, because I know it does the job in many cases. It comes along with a
WebInterface, which in many cases makes programming unnecessary.
There are tons of them and there is a playground with even more. I will start with a bunch of them,
since I will explain during this tutorial, how to attach the sensors to ESPEasy.
The Hogwarts Express
The BHT1750 is a Luxmeter. I have chosen this guy, since … I had it in stock. Good reason, isn’t it. The
real reason is, that it uses an I2C Bus. The line I2C is the
bus line operating between the Schuldorf and Darmstadt
main station platform 9 3/4 Monday to Friday during school
hours.
And you may attach a sensor to this bus line. The schedule
is printed on it’s back side.6
At the end of the bus I pull up the bus to 3.3V using a 47K Ohm Resistor. The pin D1 is SCL and D2 is
SDA. So don’t use those pins if you would like to use the I2C bus.
In ESPEasy use the tab “Hardware” to check if everything has been set up correctly.
The value of the resistors is not critical. I have seen anything from 1k8 (1800 ohms) to 47k (47000
ohms) used. 1k8, 4k7 and 10k are common values, but anything in this range should work OK. I
recommend 1k8 as this gives you the best performance. If the resistors are missing, the SCL and SDA
lines will always be low - nearly 0 volts - and the I2C bus will not work.
From: <http://www.robot-electronics.co.uk/i2c-tutorial>
Configuration of your lux meter
http://192.168.178.82/devices
YaBu – RS232
Computer Nerds like acronyms like yet another bus. This introduces our next sensor, which uses the
RS232 bus, the dust sensor SDS011.
If we turn this one around, we will find tons of pins. This sensor works with 5 volts. We make sure,
that we have enough power to operate it stable.
Then you will find two new pins TXD/RXD. What would be easier to connect it to TX/RX pins on the
Wemos.
If you are to use a new device come and ask. I have done the prep work here and the RX and TX ports
are using 3.3 volts, so we are all set. You will find such information from the data sheet. But only
cowards rtfm.
Beside the electrical specification you will find much background information here. https://cdn-
reichelt.de/documents/datenblatt/X200/SDS011-DATASHEET.pdf
There are more connections available, to connect the ESPEasy to your SDS011, but I could only get
the depicted option to work. Another word be patient. Gas sensors need time to give you stable
results.
The pitfall
Analog data
What shall I do with analog data coming from something as digital as a sensor? Because the sensor is
not digital. The sensor is composed by micro AL2O3 ceramic tube, Tin Dioxide (SnO2) sensitive layer,
measuring electrode and heater are fixed into a crust made by plastic and stainless steel net.
If mounted on a breakout
board you will find V+,
GND, D0 and A0 Pin.
Here, we have a digital
signal D0 though. Yes, but
… you all know a yes but
will say the opposite …
The digital pin is only a
threshold 0 below and 1
greater equal threshold.
We connect the A0
output to a voltage
divider. We use a
potentiometer, which
allows us to adjust Vout to
3.3 V. Shouldn’t 2 resistors do the job? Yes but … did I mention that I
am lazy and the multimeter does the job of the formula pretty well.
The analog pin A0 displays values from 0…1023 = 0 … 3.3 volts. So, you can do a simple 2-point
calibration. Looks easy, but … shouldn’t be the gas concentration be in ppm? Yes, it should, but didn’t
I tell you that I like to torture students with the real tricky staff? And this is not about electronics.
Calibrating the sensor
DS18B20 sensor
According to the ESPEasy man pages
one may connect this sensor to 3.3V.
Then you have 4 input/output pins HV1-4 (5.0V) and LV1-4 (3.3V).
oIn our examples we connect the sensor to 5V and our ESP to 3.3 V.
Configuration of your DS18b20 temperature sensor
<<
Pulse Counter
The pulse counter is the device to count a PWM signal. Let’s assume, you are interested how much
air your pump is pumping. We connect the
counter after the pump with a tube.
That’s it. Turn on your pump and think how to calibrate this sensor, so you get l/min displayed?
Error egressus circumdatus es
Or how do we calibrate a sensor.
Imagine you have a scale sensor and get a result of “920698.875” What can you do with that? Not
much. Hoc illud est quod nos vocamus quod normae. Gramms would be better, wouldn’t it. And
something you have to learn with your sensors in most times. Sensors deliver values, but in many
cases not meaningful ones.
Knowing, that nothing is placed on my scale we can easily transform this to 0 gramms by subtracting
“920698.875” from the displayed value. We call this taring, the result is an offset to the measured
value.
Next thing would be to add a second value. We can do this by adding a known weight to our scale.
Let’s say 42.5 gramms. Why that? One 2 € coins
weighs 8.5 gramms. The ECB puts a lot off effort in
the coin process to guarantee that. The best test
would be to use the prototype of the kilogram.
When I googled that, I learned that this is outdated
knowledge since 2019 Anyhow, good enough
for us.
If we draw a graph, we see that we have a linear function y=8.5x – 8.5. So, we can randomly pick 2
points for calibration.
Can we trust our scale now? Let’s try the following experiment. We pump water using a electric
pump and we make sure, that the the current is constant. We would assume, that the volume per
second is constant. Let’s look at some measurements from that. Well I can see, that the weight grows
steadily. So create a graph from that.
Time gramms
14:52:42 0
14:52:47 2,2
14:52:52 12,6
14:52:57 31,5
14:53:02 43
14:53:07 54,6
14:53:12 58,9
14:53:17 58,9
14:53:22 58,9
14:53:27 58,9
14:53:32 58,9
This is anything but linear function.
You’ve always had the power my dear, you just had to learn it for yourself.
There is a windows version which we will use to get started. Basically, there a 3 programs which do
the job.
We have built sensors and used ESPEasy for this. Have a look at the controllers tab.
Hey, this looks freightening, doesn’t it?
ON Rules#Timer=1 do
publish,%sysname%/Distance,",%systime%,[SR05#Distance]"
timerSet,1,5
endon
Outlook
If you have looked at the list of protocols, you will see that ThingSpeak protocol is supported.
But … it uses Matlab which is NOT an open source software. So I will not go down this road with you.
We will have a look at FHEM which is an open source project for home automation. It collects and
displays the data of your sensors.
Flashing the ESPEasy Software
You may add an initial configuration after flashing the firmware.
If configuring does not work,
you can do the job via the
Webinterface. Connect to the
ESP_Easy_0 Network from you
PC. Your brows
Debugging
Open the Serial Monitor. This will give you the information about your ESPEasy device.
Below you can see the connection to the WIFI AP and the IP address.