📜 ⬆️ ⬇️

Bluetooth thermometer


Probably everyone has already heard about the Arduino . I decided to play with this platform, and to make a Bluetooth thermometer, the readings of which can be viewed on a phone or computer equipped with a Bluetooth module.


Operating principle


Bluetooth is connected to Arduino via UART, which is emulated by software (softwareSerial library is used). This frees up the hardware port, which makes it possible to simultaneously read data through the cable and via bluetooth. Also connected to the Arduino thermal sensor.
Readings from the temperature sensor and sent to the bluetooth and cable to the computer (if necessary). Any device equipped with bluetooth and supporting the btspp protocol receives data from the Arduino bluetooth module. And then applied software based on these data can build graphs, keep statistics, or simply display the current temperature.

Iron


Bought on robocraft.ru :
ORduino Nano (ATmega168) - 500 rub
Bluetooth module HC-05 - 330 rubles
Analog temperature sensor LM335 - 40 rubles
I bought on the radio market:
1 resistor for 2.2 koma, stabilizers for 3.3 V and 5.5 V, capacitors for them ~ 30 rub
')
The LM335 is analog, so to calculate how many volts it comes from, you need to know the supply voltage. If we make a mistake in the voltage even by 0.01 V, then the sensor will already give an error of 1 degree, and the higher the voltage setpoint differs from the current voltage, the greater will be the error. Not to mention the fact that the sensor itself has an error of 1 degree. A highly stabilized power source is required. And the best result here will show the usual batteries (more precisely, a battery made of galvanic cells) connected to the Arduino via a voltage regulator (there is no such stabilizer in Nano). But shemku consumes 60-70 mA. It's a bit too much for batteries (the “Krona” will be planted in about an hour or half an hour, but it will work for tests). A network power supply give not a stable voltage. Due to the pulsation sensor readings will jump heavily.
The easiest way out of this situation is to use digital temperature sensors. For example, 1-Wire DS18B20 sensor.

Soft


It should be noted that the Bluetooth module HC-05 came to me at a speed of 9600 (claimed 38400). Benefit it can be changed through AT-commands. To work with the module in the AT command mode, you can use a simple sketch by connecting PIO11 to +5 V through a 220 Ohm resistor.

#include <SoftwareSerial.h> SoftwareSerial mySerial(2, 3); //   rx  tx  void setup() { Serial.begin(9600); mySerial.begin(9600); } void loop() { if (mySerial.available()) { int c = mySerial.read(); //   software- Serial.write(c); //   hardware- } if (Serial.available()) { int c = Serial.read(); //   hardware- mySerial.write(c); //   software- } } 


The sketch for working with a thermal sensor and Bluetooth is also not complicated. Data is transmitted in binary format, in batches. Each package starts with
0xDEAD

 #include <SoftwareSerial.h> SoftwareSerial mySerial(2, 3); const double opVoltage = 4.98; //   ( ) const byte tmpPin = 0; //  ,     void setup() { Serial.begin(9600); mySerial.begin(9600); pinMode(13, OUTPUT); } void loop() { double vl = (analogRead(tmpPin)*opVoltage)/1024; //     int tempK = vl*100; //     int tempC = tempK - 273; //      byte packet[] = {0xDE, 0xAD, tempC >> 8, tempC & 0xFF }; //   //   Serial.write(packet, 4); //   mySerial.write(packet, 4); // - //   -   digitalWrite(13, HIGH); delay(500); digitalWrite(13, LOW); delay(1500); } 


The MIDlet for the phone is written in J2ME (what else is the same MIDlet ), plus the fact that it will work on any phone with jsr82 support. But, knowing about the “cross-platform” J2ME, at least should work :)
Please note that the address of my Bluetooth module is listed in the midlet.

Midlet sources as well as Arduino sketches can be found here.

Scheme


Bluetooth connects to pins D2 and D3.
The voltage from the temperature sensor is removed to pin A0.






Conclusion


The thermometer can be used as a home or as a street, only then the entire device must be protected from an aggressive environment. And do not drill any holes in the wall under the wire.

And you can also write a client for a mobile phone and get access to the Internet or send SMS. And do not need any GSM / GPRS shields and AT-commands. Only a phone with bluetooth, but that's another story ...

useful links


Bluetooth module HC-05
Analog Temperature Sensor - LM335
1-Wire Temperature Sensor DS18S20
Sources

Source: https://habr.com/ru/post/139477/


All Articles