Temperature sensor output values on smartphone
The article will tell about the project of the thermometer, the main difference from similar projects is that the value of temperature sensor will be transmitted to the smartphone via Bluetooth and displayed on its screen. Such a temperature sensor can be placed in an inaccessible location, such as behind the window or in the refrigerator. And you can always check the temperature without visual contact with the sensor. You run mobile app, connect over Bluetooth and see the screen of Smartphone or tablet to control the temperature. The sensor itself is implemented using Arduino. To implement the transfer values of temperature on the smartphone we use the library RemoteXY.
For making of the electrical part of the device, you need any Arduino board, the thermistor 1K, resistor 1K, it is also desirable battery compartment for stand-alone power the Arduino. The thermistor will fit on any resistance from 1 to 100 K, but in this case, the resistor should be the same. Below is a diagram of connections of all structural elements. We did it all together on a breadboard.
The thermistor circuit is included in the voltage divider, a second shoulder which is constant resistance. Thus, when the temperature changes will change the resistance of the thermistor, and hence one arm of the voltage divider. The voltage divider will change along with the temperature. The midpoint of the voltage divider we have connected to an analog input of the Arduino with the number A5.
The development of the program we will start with calibration of the sensor. Calibration we perform two-point, and to do this we need the reference temperature. I have a thermometer of room that shows 25 degrees Celsius, this will be the first reference temperature. I know that my body temperature is 36.6 degrees Celsius, and this will be the second reference temperature. So let us assume that the resistance of our thermistor within certain limits varies linearly depending on the temperature. This, subsequently, to calculate the current temperature will use linear interpolation.
For calibration, we need to determine what value input Arduino ADC with temperature sensor that we have chosen the reference. Use Serial and port monitor, to transmit the ADC value on the computer that we could see what it is when our reference temperatures. To do this we need the following simple Arduino sketch.
void setup()
{
Serial.begin(9600);
}
void loop()
{
int sensorValue = analogRead(A5);
Serial.println(sensorValue);
delay(1);
}
This sketch in each cycle of the program measure the voltage of the analog pin A5, digitizes it, and sends it to Serial. You can connect the port monitor (Service/Port Monitor) and see what values are passed. Now we need to remember this ADC values at the chosen reference temperature. The first reference temperature you get, if your thermistor had been long enough in the room. To obtain the second reference temperature attach the thermistor to your body and hold on to it for a few minutes. Rewrite the ADC values, which are transmitted to the port monitor at these temperatures. We got the following values:
T=25.0°C ADC=580
T=36.6°C ADC=514
Go to online editor RemoteXY and create the management interface. It consists of a text field, through which is transmitted the measured temperature, and a text label. The length of the text field specified in the settings, is determined by the maximum length of the transmitted string. In our case it can be of value "-40.0" or "100.0". That is, the length of the string cannot exceed 5 characters. You can leave the default system length 10 characters.
Selected in the project settings of the target platform Arduino (SoftwareSerial), library version and the generated source code of our interface. Don't forget to download RemoteXY library and import it to the Arduino IDE (Sketch/Import library/Add library...).
For transmit the value of temperature on the smartphone screen we need to get the current value of the ADC, to get the value of the current temperature using a linear interpolation on the two known points, convert the received value into a string and write it in the field text_1 patterns RemoteXY. To convert a double type to a string using the function:
dtostrf (floatVar, minStringWidthIncDecimalPoint, numVarsAfterDecimal, charBuf)
The problem of linear interpolation we will solve using a simple formula:
Collecting everything together we get the following source code is the sketch for Arduino:
/////////////////////////////////////////////
// RemoteXY include library //
/////////////////////////////////////////////
/* RemoteXY select connection mode and include library */
#define REMOTEXY_MODE__SOFTWARESERIAL
#include <SoftwareSerial.h>
#include <RemoteXY.h>
/* RemoteXY connection settings */
#define REMOTEXY_SERIAL_RX 2
#define REMOTEXY_SERIAL_TX 3
#define REMOTEXY_SERIAL_SPEED 9600
/* RemoteXY configurate */
unsigned char RemoteXY_CONF[] =
{ 0,11,27,0,1,5,67,0,24,23
,54,16,2,11,129,0,23,12,39,9
,0,84,101,109,112,44,32,194,176,67
,0 };
/* this structure defines all the variables of your control interface */
struct {
/* output variable */
char text_1[11]; /* string end zero UNICODE */
/* other variable */
unsigned char connect_flag; /* =1 if wire connected, else =0 */
} RemoteXY;
/////////////////////////////////////////////
// END RemoteXY include //
/////////////////////////////////////////////
/* the first measured value of the first point */
#define SENS_1_VAL 514
#define SENS_1_TMP 36.6
/* the second measured value of the second point */
#define SENS_2_VAL 580
#define SENS_2_TMP 25.0
void setup()
{
RemoteXY_Init ();
Serial.begin(9600);
}
void loop()
{
RemoteXY_Handler ();
/* get the ADC value */
int sensorValue = analogRead(A5);
/*
calculated current temperature using
a linear interpolation on the two known points
*/
double temp = SENS_1_TMP + (SENS_2_TMP - SENS_1_TMP) /
(SENS_2_VAL - SENS_1_VAL) * (sensorValue - SENS_1_VAL);
/*
convert the temperature value into a string
and place it immediately in the field text_1 patterns RemoteXY
*/
dtostrf(temp, 0, 1, RemoteXY.text_1);
/*
send the value of the ADC to Serial
in order that we could check the values
*/
Serial.println(sensorValue);
delay(1);
}
In this code, you must change the defined values SENS_1_VAL, SENS_1_TMP, SENS_2_VAL, SENS_2_TMP, substituting them your that you got when you measured values for calibration.
Upload the sketch to your Arduino. Download to your smartphone or tablet RemoteXY app. And can control the temperature when you are away from your sensor, using Bluetooth.