Actually, the weather sensor is probably the second thing that everyone does after they flash the LED on the Arduino. And since this fate cannot be avoided, then we must deal with it as quickly as possible in order to move on.
I initially did not plan to watch the temperature and humidity locally, because I spend most of the time during the week, first, outside the house, and, second, with a smartphone. Therefore, there were two options: receive the weather by mail or upload to any suitable online service.
Honestly, I first wanted to
do good and throw it into the water, send the weather to
Openweathermap.org and even did it for a while. But then it began - then the service suddenly refuses, and I sit and wonder what happened, his IP will change, and I need to climb into the code of the central controller again.
')
In general, I refused OWM, and used the experience to adapt the sensor to another online service. Although he does not use the data for the forecast, it turned out to be very convenient for me to look at the current weather and statistics.
Other devices and devices of the series Purpose
PI-TV-2 is designed to measure the current values ​​of humidity and temperature, and transfer them to the
central home controller -2-12 over the radio channel.
Has no other assignments yet, although the power supply and the Arduino Pro Mini controller on board seem to hint that you can add something else. Than I probably will do someday.
. That's how it looks in the interior. But the expectation is that design imperfections constantly cover the curtains

Principle of operation
PI-TV-2 is designed to work with the
central home controller -2-12 or similar device capable of receiving and interpreting the received data. The data format is lower in the text and is also visible in the sketch.
PI-TV-2 does not display current readings and does not have a wired connection to any external devices, except for the temperature / humidity sensor and the transmitter.
Indications of temperature and humidity, measured by the DHT21 sensor, are transmitted to the central controller by radio with an interval of half an hour. The central controller uploads the HTTP POST protocol to the
People’s Monitoring service at one-hour intervals. Both intervals are not tied to each other and are not synchronized.
DEMO sensor readingsDuring normal operation, the built-in Arduino LED blinks at intervals of about 8 seconds.
Error correction and control of the reception and integrity of the transmitted data are not provided.
Iron
The design of PI-TV-2 is very simple and consists of only four main components (links, as usual, just for example):
1.
Arduino Pro Mini 5V, 16 MHz with an ATmega328 chip.
2. Combined temperature and humidity
sensor DHT21 .
3. 433 MHz transmitter with amplitude modulation (
from such a kit , for example).
4. Resistor 4.7kohm, 0.125W
5. Power supply 5V - 9V (optional, you can experiment with batteries or rechargeable batteries).
6. To fill the code in the Arduino Pro Mini, you will need and
here is such (or similar) COM-USB converter (optional - maybe you already have one).
It is this controller - because it is compact and already lay in my box for any homemade products. And I bought a pack of these controllers, because they were inexpensive and met more often than version 3B. Yes, and I did not think that I would feed this economy from 3B, so 5B was more important.
. something like this you will connect to fill the sketch

The acquisition of the DHT21 temperature and humidity sensor is determined by the fact that I somehow ordered a very simple but nice watch for my wife on DX. Only after the payment was made, the shop unsubscribed that there were no hours in stock, and they could return the money to the account in the shop, that is, for future purchases. In short, took almost without looking.

I selected the parameters taking into account the fact that the sensor is most likely to be outdoor, therefore not DHT11, but DHT21 whose minimum measurement temperature is -40 ° C. I must say: this is for Moscow, and if you have other lows, the sensor will also be completely different. For example, the super popular DS18B20, which measures up to -55C and something else for humidity.
. fits

An analog transmitter is required for communication with the analog receiver of the central controller using the protocol implemented in the
RC-Switch library. Again, in the central controller, I use the library for two purposes: control of wireless sockets and peripherals, as well as data exchange with service controllers. This allows you to do a minimum of equipment and at the same time saves memory, since they do not need specialized libraries for wireless communications.
Another choice is autonomous or networked power. Again, I honestly tried to use self-powered: I liked the idea that the sensor would just hang somewhere without wires. But it did not work out. In fact, even the Arduino Pro Mini has a fairly high energy consumption, if you do not know how to turn off everything and everyone. And I have not learned.
The maximum that I managed to squeeze “sleep” with various libraries was about a week of work on 14500 batteries. Two batteries died in a couple of weeks for some strange reason. In theory, the protection should have prevented over-discharge, but in fact it simply blocked the battery. Removing protection extended the battery life by another week, after which she died permanently.
The bottom line is the power supply side and no worries.
Logically assembly is as follows:
1. DHT21 sensor
GND - to the power supply minus;
VCC - to Arduino pin VCC or to any Arduino digital pin in OUTPUT / HIGH mode to save battery power (code is pin 7) or to the 5V output of the power supply (if you have a 5V block). To 9V sensor can not be connected;
OUT - directly to pin 5 Arduino and through a 4.7 kΩ resistor - to the power supply (we pull up to the power).
. in principle, and the wires can be seen, but to be 100% sure you need to open it

2. Transmitter
GND - to the power supply minus;
VCC - to the power supply plus (from 3V to 12V), it is also possible to pin the VCC Arduino or to any digital pin Arduino in the OUTPUT / HIGH mode in order to save battery power (code is pin 8);
DATA - to pin 6 Arduino.
. something like this in the process

. based on batteries (rechargeable batteries)

3. Arduino
If you have a 5V source, then its plus can be connected to the VCC pin.
If the power source gives noticeably more than 5V (but not more than 12V), then - to the pin of RAW. At the same time on the pins VCC will be 5V, which can be used for the DHT21 sensor and other peripherals.
Minus power supply, respectively, to
GND Arduino.
A bit of “battery power saving options.” The fact is that we send the Arduino to sleep, but what to do with the peripherals that are constantly connected to the power supply? To fence the keys on the supply chain? Not necessarily. After all, Arduino digital pins can be used to power low-power devices - transmitters, receivers, some sensors.
And this, in turn, makes it easy to turn on and off peripherals as needed. To enable, simply transfer the pin to the OUTPUT mode, write HIGH to it and get + 5V power. And to turn off, we write in the same pin LOW.
That's all with logic.
Physically, the assembly is complicated by the fact that I, first of all, placed everything in the case from a wireless bell, because I hoped to use its battery compartment. By the way, it turned out that the Arduino indicator LED turned out to be next to the “light music” window of the former call, so that through it you could monitor the controller’s activity, since the code requires periodic flashing (yes, and here it is!).
. until I discharged the power LED - it was also visible

Secondly, I connected the DHT21 sensor through the plug connector for easy maintenance of the weather sensor. I extended the sensor wire so that it could be pulled out of the window without any problems.
And thirdly, the power supply LED disappeared when it was still obsessed with the idea of ​​battery power. After all, when the power is on, the LED lights up constantly, but why does it need a weather sensor?
For mounting the sensor outside the window, a small magnet is stuck on it. In this form, the sensor "sticks" visor or "window sill". I fix it below so that it does not flood with water and does not overheat by the sun.
To power the whole PI-TV-2 in the final version I used a piece of wire with a connector for an existing network adapter.
Well, the weather sensor itself hangs on the window on the same magnets: one magnet on the sensor, the other on the window. By the way, they are very well joined by faces (magnet thickness of the order of a millimeter), which noticeably reduces bulkiness: the sensor seems to be simply glued to the frame.
. also not very aesthetic, but - back

Soft
The peculiarity of the current version of the code is that it was inherited from attempts to make an autonomous meteorological sensor. Therefore, here you can observe the energy-saving library in all its glory, and if you wish - try to power the sensor from batteries. It needs at least 5V, while 14500 batteries with a capacity of 900 or 1000 Chinese mAh last about a week of continuous operation.
Please note: one 14500 battery is small, so you need two. And two - a total of 7.4V according to the characteristics on board the batteries (and about 8.4V immediately after full charge), so you need to connect to the pin of the RAW Arduino so as not to kill it. And the sensor DHT21, respectively, only to pin VCC Arduino or to the power supply digital pin.
Since the energy-saving library used lulls the controller for no more than 8 seconds, its call lives in a cycle that provides about half an hour of not very healthy, but still sleep.
In the same cycle, the built-in Arduino LED flashes. When working on batteries, it allowed us to quickly and simply understand the controller alive, or it was already time to recharge. Now it is just an indicator of activity.
As a result, the sensor readings are transmitted to the central controller at half-hour intervals. This interval was chosen at once for several reasons: maximum battery saving (when it was relevant) with more or less reliable data and resource saving of the central controller, which has other things to do but post weather to the Internet.
To transfer readings, I use, so to speak, a proprietary protocol that runs on top of the RC-Switch. It looks like this: the sensor transmits the numbers of the form 161HSXXX, where H is a sign of humidity, S is the sign of temperature, XXX is the value of the climatic parameter accurate to tenths, multiplied by 10.
If H = 1, the controller considers that the moisture readings are transmitted. If H = 0, the controller thinks it got a temperature. If S = 0, the temperature is considered positive, if S = 1, then it is negative.
Both parameters are transmitted by the weather sensor at a short interval in order to guarantee the processing time on the side of the central controller, which then draws all the form of an HTTP POST request for transmission to the Internet. Storage and visualization of parameters is carried out using the "
People's Monitoring ". Of course, you can choose any other suitable resource or your own service, but then do not forget to correct the code of the central controller or your service to receive data in the existing format.
Do not forget that to compile this code, you will need three non-standard libraries:
1.
DHT22 for sensor.
2.
LowPower for power saving mode.
3.
RC-Switch for transmitting readings.
Wireless weather sensor sketch Final word
The biggest problem after energy efficiency is the reliability of the radio channel. Whether I'm doing something wrong, or just at home, some surprisingly poor environment with interference, but the sensor more or less earned at a distance of 5-6 meters from the controller only if a rather large telescopic antenna was screwed to the conventional transmitter, or if i used a
more expensive transmitter .
Another feature is that my DHT21 instance actually stops measuring humidity at its high values. At some point, it simply wedges by 99.9%, and until the humidity decreases to a certain threshold, the value does not change.
And since this has become attached to me, there is a mass of texts on the Internet about the current consumed by the Arduino. Individuals managed to reduce consumption to micro-ampere units, but this is mainly on “clean” controllers without any built-in voltage regulators, LEDs, etc., and so on. Here,
for example .
And, again, if I made a mistake somewhere - say, I will correct it.