Bluetooth Humidity Temperature

Bluetooth & Humidity & Temperature sensor

I have internal data collection item, MrSmart. It have collected data more than 16 years. It also sends data to Internet to my home page.
I has collected also outside temperature more than two years using Bluetooth communication and SHT160-30 temperature sensor.


A graphical interface before I did my add on.

It has worked well.
It will give digital immediate data and analog charts for one month at time.


This is immediate digital data.

I need more data, so I decided to get outside humidity also.


This is temperature and humidity sensor module for microprocessor DHT22.

I looked sensors and I found very popular temp and humidity sensor DHT22( Banggood).
It has three wires, but most of DHT22 modules has four wires.
I also ordered Bluetooth (Banggood) serial module HC06.
It has only four wires VCC ( 3.3.. 5.0V), GND, TXD and RXD.


This is Bluetooth module for serial data HC06

I tested Bluetooth module with PC Bluetooth module and PC serial test program (Probyte/MrSmart)


This is Bluetooth module for serial data to PC.

It worked well.

Then I tested DHT22 module, but it has very bad English/Chinese datasheet(
All the programs which I found were Arduino type, but I use always PIC-cpus.

I can't find working PIC program, so I started to build it from zero.
Well it don't work at first, but then I got all the timings to work.

Still it has problems in getting the data. The data sheet doesn't give exact help.

I finally got everything right to serial data to PC.
I used PIC16F886 at this test stage to PC serial data.

I fetch my old Bluetooth device and installed DHT22 to it.
I take may old temperature device (SMT160-30) off and installed DHT22 instead.

I compile new PIC 18F2431 for that device.


This is a schematic diagram for my sensor, communications and cpu.

I put 230/5V power supply on and tested it in my workroom and went to look my data collector computer, which is in living room.

It is HP550, very modest device with WIN7 operating system.
Anyway it worked!

I put my CCS/PCH 5.007 compile code to here, If somebody will try it later.

    date 3.5.2018
    Pekka Ritamäki   
    Compiler CCS/PCW 5.007
    DHT22 in pin B0.
    This DHT22 has internal 10k pullup resistor. It has three pins from left GND,VCC,Data,
    VCC = 3.3-5V

    First give pulse 18 ms pulse down, then wait 26 ms
    Check that DHT22 responses with zero pulse  80 us
    Then DHT22 should give  80us high pulse
    Then read 5*8 bytes data so that DHT2 gives 50us low pulse, 
    then it gives actual data after 26us low or high data read 

    Humidity high value is value[0]*256 + humidity low value[1],  hum/10
    Temp  high value is value[2]*256 + low temp value is value[3], temp/10

    Then multiply value[0] with 256 and add low value[1], you get humidity value/10 

    Then multiply value[2] without highest bit with 256 and add value[3],  you get temperature value/10

    Take value[2] highest bit and if it is 1 then it the temperature is negative temperature

    This gives temperatue in Celsius degrees. 
    Convert to Farenheit T(°F) = T(°C) × 9/5 + 32 

#include <16F886.h>
#device *= 16
#FUSES  NOWDT                   //No Watch Dog Timer
#FUSES INTRC_IO                 //Internal RC Osc, no CLKOUT
#FUSES NOPROTECT                //Code not protected from reading
#FUSES IESO                     //Internal External Switch Over mode enabled
#FUSES BROWNOUT                 //Reset when brownout detected
#FUSES BORV21                   //Brownout reset at 2.1V
#FUSES PUT                      //Power Up Timer
#FUSES NOCPD                    //No EE protection
#FUSES NODEBUG                  //No Debug mode for ICD
#FUSES NOLVP                    //No low voltage prgming, B3(PIC16) or B5(PIC18) used for I/O
#FUSES NOWRT                    //Program memory not write protected

#use delay (internal = 8MHz)

#use rs232(baud=9600, xmit=PIN_C6,rcv=PIN_C7,errors)

#define DHT22_pin PIN_B0

 unsigned char value[5];   // read bytes from DHT22 
 float temp,hygro;         // real values
 // read first 30us low pulse, then actual data 

unsigned char get_byte()
   unsigned char s = 0;
   unsigned char value = 0;

   for(s = 0; s < 8; s ++)
      value <<= 1;
      while(!input(DHT22_pin)); // wait till DHT22 goes to low state 

          value |= 1;
   return value;   // return 8 bits byte 

// give a start pulse low 18ms,
// then wait 26 ms and chech DHT22 state
// then read 5 byte digits to common value[]'s 

unsigned char get_data()
   short chk = 0;
   unsigned char s = 0;
   unsigned char check_sum = 0;

   output_high(DHT22_pin);   // prosessor high
   output_low(DHT22_pin);    // then low 
   delay_ms(18);             // wait 18 ms
   output_high(DHT22_pin);   // prosessor high
   delay_us(26);             // delay 26 ms

   chk = input(DHT22_pin);   // raed DHT22 state
   if(chk)                    // if DHT22 goes low it is error state 
      return 1;
   delay_us(80);              // small delay 80us

   chk = input(DHT22_pin);    // read DHT22 again 
   if(!chk)                   // DHT22 keeps high state, it is a error, no device
      return 2;
   delay_us(80);               // small delay 80us

   for(s = 0; s <=4; s ++)     // read 5 digits to value[]'s   
       value[s] = get_byte();  

   output_high(DHT22_pin);     // put the prosessor to high state to wait the next measurement 

   for(s = 0; s < 4; s ++)
       check_sum += value[s];  // count  check_sum

   if(check_sum != value[4])
      return 3;                // not right, error 
      return 0;                 // no errors

// change  desimal charcters to real numbers,note 0x80 in value[2] gives negative temperature
void change( void)

   temp = 256*(float) (value[2] & 127); // hi byte gives 25 deg* bytes to low bytes

   temp += (float) value[3];      // add value[3]/10 
   temp /= 10; 

 if (value[2] & 0x80){    // this is negative 
   temp =-temp ; 

   hygro = 256*(float) (value[0] &127);   // hi byte gives 25 deg* bytes

    hygro += (float) value[1];       // add value[1]/10 
    hygro /=  10; 

// Main starts the program 
void main(void)

   unsigned char state = 0;
   disable_interrupts (GLOBAL);
   setup_timer_0(T0_internal  );
    printf("\rDHT22 read");

      state = get_data();// give a start pulse and then read 5 bytes

             case 1: 
            case 2:
               printf("\rNo Sensor Found!");
            case 3:
               printf("\rChecksum Error!");
               change ();
               printf("\rtemp=%f hygro=%f", temp, hygro); 
      delay_ms(500);     // minimum time  betwen measurements is 500ms

A part of graphical interface

Click the picture two times to get it bigger

Oh yes, how is it now?

The top red curve is moisture.
In the day it will drop when the temperature rises 30-20%, at night the humidity is up to 82%

The blue light curve rises up to 60 in the morning (= * 100 lux) and at night it drops to a few luxes.

The next blue curve is the temperature of the cold pipe in the air pump.
It spins over a warm air pipe, because these days there is no need for warmth.

The read warm tub already if up to 7C,
Normally in winter it is always above + 35C.

The green curve shows the inside temperature.
It's around 22-23C all the time.
This temperature is the most important, which is why I have done all systems!

The black curve shows the outside temperature.
It spins in the beginning of May around 10-35C, of course there is cold weather at night.

What about those empty areas between the days?

Well, I'll stick the data logger right away and no information will come.

When I sleep, I can not get information about my use,
Here is picture of my computer


On left upper part is picture of PC Bluetooth program.
It shows outside temperature, outside humidity, time (117s) to next saving to data file (c:\hotbox\201806.log) .
These data is combined to MrSmart data, but with different time and channel.

In next row is last saving date and time, how many data is saved.
Then there is Internet marking, which works every time the program is send data to Internet.

In the middle of the picture there is graphics picture which show all the channel together.
On lower left there is digital data from MrSmart.
They show heat pump cold and heat data.
Light in lux and inside temperature.

Pekka OH3GDO

Unless otherwise stated, the content of this page is licensed under Creative Commons Attribution-ShareAlike 3.0 License