Introduction: DIY Bluetooth Temperature Sensor (ATTINY85)

I wanted to build a bluetooth temperature sensor which I could use to read remotely the temperature in my green house. I decided that the first step would be to build a prototype on a breadboard. This project describes the construction and operation of the prototype, i.e. how a remote temperature reading may be viewed on an Android Phone or laptop.

Temperature is read from a low cost temperature sensor using a small but powerful microprocessor - ATTINY85 - and transmitted to a PC or Android Phone using a HC-06 bluetooth sensor.

The basic principle is that a serial connection is set up between the ATTINY85 chip and the user device via a bluetooth chip (HC-06).

.

Step 1: What You Will Need

1) Breadboard

2) Breadboard power adapter (e.g.Yurobot)

3) HC-06 bluetooth module

4) ATTINY85 sensor

5) Dallas DSB1820 temperature sensor

6) 4.7 k resistor to connect positive and data pins on the Dallas DSB1820

7) Windows laptop or Android Phone with bluetooth capability

8) Putty for Windows or terminal app for Android, e.g. Bluetooth Terminal HC-05

9) Various breadboard cables

10) PC with Arduino IDE

11) USBASP programmer

Step 2: Connecting Everything for Programming and Operations Mode

The ATTINY85 chip is at the core of this circuit.

Firstly, you have to program the ATTINY85. (I have shown how to program this chip in a number of my instructables). For this you need a USBASP programmer to upload your program sketch from the PC or laptop on which you will be compiling your code using the Arduino IDE.( see next section for code)

Secondly you set it up for operations mode, as in the diagram above. The rest of this page deals with the operations mode of the circuit. Note that the ATTINY85 comprises 8 pins. There is a little dimple on the ATTINY85 chip which may be used as a reference point. In the FIGURE 1 below, this is pin 1 aka PB5.

To connect all the components, follow the photograph above. Note that you need a 3.3. volt power supply.

<p style="margin-left: 20px;">// *** Pinout ATtiny25/45/85: FIGURE 1<br>// *** PDIP/SOIC/TSSOP
// *** =============================================================================================
// ***
// ***               (PCINT5/RESET/ADC0/dW) PB5   <strong>[1]*  [8]</strong>   VCC
// ***   (PCINT3/XTAL1/CLKI/OC1B/ADC3) PB3  <strong> [2]   [7]</strong>   PB2 (SCK/USCK/SCL/ADC1/T0/INT0/PCINT2)
// *** (PCINT4/XTAL2/CLKO/OC1B/ADC2) PB4  <strong> [3]   [6]</strong>   PB1 (MISO/DO/AIN1/OC0B/OC1A/PCINT1)
// ***                                                            GND   <strong>[4]   [5] </strong>  PB0 (MOSI/DI/SDA/AIN0/OC0A/OC1A/AREF/PCINT0)
// ***</p>

Step 3: Programming the ATTINY85

Again, I have shown how to do this in previous instructables. You need the following:

  1. Arduino IDE ( I used version 1.85)
  2. A USBASP programmer

Here are the settings for Arduino IDE environment

Tools Drop down Menu

  • Board: ATtiny25/45/85
  • Processor: ATtiny85
  • Clock: Internal 8 MHz
  • Programmer: USBasp

Note that when uploading the code, use the upload using programmer option under Sketch Drop down Menu.

Here is the code. I have also added the INO file as an attachment.

#include <onewire.h>
#include <dallastemperature.h>
#include <softwareserial.h>  //Software Serial Port
// ***
// *** Pinout ATtiny25/45/85:
// *** PDIP/SOIC/TSSOP
// *** =============================================================================================

// ATTINY 85 frequency set at internal 8 MHz </softwareserial.h></dallastemperature.h></onewire.h></p><p>// ***        (PCINT5/RESET/ADC0/dW) PB5   [1]*  [8]   VCC
// ***                                                      PB3   [2]   [7]   PB2 to HC-06 RX PIN
// ***                                               led    PB4   [3]   [6]   PB1 to HC-06 TX PIN
// ***                                                      GND   [4]   [5]   PB0 therm sensor data (midle) pin
// ***
// ATTINY 85 frequency set at internal 8 MHz 
// ***
// *** Pin on which the OneWire data
// *** wire is connected.
// ***
#define ONE_WIRE_BUS 0
#define RxD 1
#define TxD 2</p><p>//#define DEBUG_ENABLED  1
 
SoftwareSerial blueToothSerial(RxD,TxD);</p><p>int led = 4;</p><p>OneWire _oneWire = OneWire(ONE_WIRE_BUS);</p><p>// ***
// *** Pass our oneWire reference to Dallas Temperature.
// ***
DallasTemperature _sensors = DallasTemperature(&_oneWire);
 
void setup() 
{ 
  pinMode(RxD, INPUT);
  pinMode(TxD, OUTPUT);
  setupBlueToothConnection();
  
  pinMode(led,OUTPUT);
  digitalWrite(led,HIGH);
  delay(1000);
  digitalWrite(led,LOW);
  _sensors.begin();
  delay(10000);
} 
 
void loop() 
{ int count=0;
  char recvChar;
  while(1){
    //check if there's any data sent from the remote bluetooth shield
    if(blueToothSerial.available()){
      recvChar = blueToothSerial.read();
      count++ ;
        if(recvChar == '1'){
          digitalWrite(led,HIGH); 
          blueToothSerial.print("\r\n LED switched ON\r\n");  
          _sensors.requestTemperatures();
          delay(2000);
          float tempC = _sensors.getTempCByIndex(0);
          float tempF = _sensors.getTempFByIndex(0);
     
          delay(5000);
          blueToothSerial.print("\r\n LED switched OFF\r\n");  
          delay(1000);
          blueToothSerial.print("\r\n temperature ");
          blueToothSerial.print(tempC,1);
          blueToothSerial.print(" degC\r\n");  
          digitalWrite(led,LOW); 
          
        }
     }
  }
} 
 
void setupBlueToothConnection()
{
  blueToothSerial.begin(9600); //
  blueToothSerial.print("\r\n+STWMOD=0\r\n"); //set the bluetooth work in slave mode
  blueToothSerial.print("\r\n+STNA=HC-06\r\n"); //set the bluetooth name as "HC-06"
  blueToothSerial.print("\r\n+STOAUT=1\r\n"); // Permit Paired device to connect me
  blueToothSerial.print("\r\n+STAUTO=0\r\n"); // Auto-connection should be forbidden here
  
  delay(2000); // This delay is required.
  //blueToothSerial.print("\r\n+INQ=1\r\n"); //make the slave bluetooth inquirable 
  blueToothSerial.print("bluetooth connected!\n");
  
  delay(2000); // This delay is required.
  blueToothSerial.flush();
}</p>

Step 4: Operations

After switching on the circuit, you should see the led blinking and the HC-06 module showing a rapid blinking red light.You should then pair your device with the bHC-06 module. When prompted for a pairing code, type 1234 or 0000.

1. Running on Windows.
This should work for Windows 8 and 10. First of all, pair the bluetooth module. To do this, ensure that bluetooth is enabled on the Windows device and add it as a new device if not previously paired.

Next, find out which port Windows is using for the serial connection. You can do this from the Arduino IDE from the Tools Menu - Port then Serial Monitor (select 9600) or using Putty in which case you can determine the correct port from Windows Device Manager (hover over Windows button in the bottom left of the screen then click the right mouse button to device the Device Manager option). With Putty you need to select connection type as serial then change COM1 to the comm port that you identified from Windows Device Manager. Keep 9600 as the baud rate.

With either of these terminal windows open, press 1 and you should see the following:

LED switched ON

LED switched OFF

temperature XX.X degC

2. 1. Running on Android

Similar to above, pair the device then open the app - see the photo- and press 1 to display the messages alluded to above.