DIY BLE Thermometer With Arduino and Blynk

DIY BLE Thermometer With Arduino and Blynk

Konstantin Dimitrov has shared a new tutorial on Arduino Project Hub on how to make an Arduino/Genuino 101 Bluetooth Low Energy (BLE) thermometer with TMP102 and Blynk. Blynk is a platform with iOS and Android apps to control Arduino, Raspberry Pi and the likes over the Internet. You can easily build graphical interfaces for all your projects by simply dragging and dropping widgets.

You will need:

In order to program this project, you should first include Blynk library by going to:

Sketch => Include Library => Manage Libraries. Click on “Manage Libraries”, then type Blynk in the search bar and you will get the library.  You should scan this QR code once you install the Blynk app on your smartphone to complete the settings.

“Now you need to get the “Auth Token”. Tap on the “Nut” icon then tap on the device and again on it, now you should see your “Auth Token”. E-mail or rewrite it, cause you will need it in the next step !”

In order to connect the Blynk app, tap on the Bluetooth app, tap on “Connect BLE Device” and choose your 101 board. You are now connected!

Finally upload this sketch on you Arduino:

/**************************************************************
 * Blynk is a platform with iOS and Android apps to control
 * Arduino, Raspberry Pi and the likes over the Internet.
 * You can easily build graphic interfaces for all your
 * projects by simply dragging and dropping widgets.
 *
 * This sketch was created by Konstatin Dimitrov 
 * under GNU v3.0 Licence 
 * 
 * Based on example scetch: Arduino_101_BLE
 ***************************************************
 *
 * This scetch shows how to send data from TMP102 with 
 * Arduino/Genuino 101 BLE to Blynk.
 *
 * Note: This requires CurieBLE library
 *   from http://librarymanager/all#CurieBLE
 *
 * NOTE: BLE support is in beta!
 *
 **************************************************************/

//#define BLYNK_USE_DIRECT_CONNECT

#define BLYNK_PRINT Serial

#include <Wire.h>
#include <BlynkSimpleCurieBLE.h>
#include <CurieBLE.h>

// You should get Auth Token in the Blynk App.
// Go to the Project Settings (nut icon).
char auth[] = "AUTH_TOKEN";

//TMP102 I2C (TWI) address in HEX
int tmp102Address = 0x48;

BLEPeripheral  blePeripheral;

void setup() {
  Serial.begin(9600);
  Wire.begin();
  delay(1000);
  
  blePeripheral.setLocalName("BLE Thermometer");
  blePeripheral.setDeviceName("BLE Thermometer");
  blePeripheral.setAppearance(384);

  Blynk.begin(blePeripheral, auth);

  blePeripheral.begin();
  
  Serial.println("Waiting for connections...");
}

//Temperature readings in Celsius on V0
BLYNK_READ(0)
  {
  float celsius = getTemperature();
  Blynk.virtualWrite(0, celsius);
  }
//Temperature readings in Fahrenheit on V1
BLYNK_READ(1)
  {
  float celsius = getTemperature();
  float fahrenheit = (1.8 * celsius) + 32;
  Blynk.virtualWrite(1, fahrenheit);
  }

BLYNK_READ(2)
  {
  float celsius = getTemperature();
  float kelvin = 273.15 + celsius;
  Blynk.virtualWrite(2, kelvin);
  }
  
void loop() {
  Blynk.run();
  blePeripheral.poll();
  }

float getTemperature(){
  Wire.requestFrom(tmp102Address,2); 

  byte MSB = Wire.read();
  byte LSB = Wire.read();

  //it's a 12bit int, using two's compliment for negative
  int TemperatureSum = ((MSB << 8) | LSB) >> 4; 

  float celsius = TemperatureSum*0.0625;
  return celsius;
}

To know more details, check the project’s page. Also check more projects by Konstnatin and follow him!

Please follow and like us:
Pin Share
Subscribe
Notify of
guest

0 Comments
Inline Feedbacks
View all comments
Get new posts by email:
Get new posts by email:

Join 97,426 other subscribers

Archives