HOME     STORE     BLOG     SCHEMATICS     TUTORIALS     DOWNLOADS     CONTACT

DS18B20 Bluetooth Thermometer
 


 

DS18B20 Bluetooth Thermometer

 


One morning I woke up and wanted to know what the temperature outside was, and instead of running over to Home Depot and picking up a $2.00 glass thermometer, I decided to build my own wireless temperature sensor. At the heart of the board is a PIC12F675 microcontroller in an SO8 package. The right-hand side of the board houses the linear power supply (LP2950), bottom-center is the DS18B20 1-Wire temperature sensor, and out in left-field you can see the Sure TTL Bluetooth Module.


DS18B20 Bluetooth Thermometer

Being a big fan of standard protocols, I opted to transmit the temperature data over a Bluetooth SPP (Serial Port Protocol) link as opposed to XBee or another similar wireless architecture. Though the Bluetooth radio sucks a fair bit of power in comparison to an XBee module, the advantage is that not custom hardware is required on the receiving end. Since nearly all modern laptops have an integrated Bluetooth chipset, this effectively means that no hardware is required on the PC end.

After looking through all of my boxes of miscellaneous junk, I found a Sure Bluetooth Module I had bought several years ago for another project. For prototyping, the surface-mount module had already been attached to a home-etched PCB with header pins so that it could be plugged into a breadboard. Since I don't have access to a hot-air rework station, I ordered another GP-GC021 module for the final project. The module shown below was the one I originally started out with, whereas the photo above shows my most recently acquired module.

I decided to use a PIC12F675 for the main MCU for no reason other than the fact that I had one sitting in my parts bin. I was originally planning to exploit the PIC's internal 4MHz oscillator, however I found out later that since the serial module is fixed at 9600 baud, the main system clock had to be jacked up to 8MHz to keep pace and transmit data at the right speed.

As with all my projects, the schematics and PCB layout were done in Altium Designer. Over the years I have tried my hand at a few different EDA (Electronic Design Automation) suites including Eagle, ExpressPCB, and EdwinXP, however I find Altium stands head-and-shoulders above the rest of the crowd. If you are just a hobbyist, Altium is probably out of your price range, however their student licensing is fantastic; and many colleges and universities maintain large license sets or even site licenses. At Okanagan College we are very fortunate to have access to the colleges' floating license, which allows students to use Altium on any computer we want, regardless of whether or not we are on campus. I should make it clear that while I do not work for Altium, I have fought many epic battles with CAD software over the years; and while Altium and I have had our disagreements, overall it is a pleasure to work with.

Footnotes:
- The schematics, firmware, and all other related files are all included in the attached ZIP archive.
- Programming is not one of my strong suites, and as such the firmware is written in PICBasic. A ready-to-burn HEX file is in the ZIP archive, however if you want to modify the firmware at all you will need to have a copy of ProtonIDE in order to compile it.
- If you are planning on making a PCB from the included Gerber files, beware that the land size for F1 (the fuse on the sensor VCC bus) is actually too small (sorry).
- Everything here is presented as-is with no warranty whatsoever.


'****************************************************************
'* Bluetooth Thermometer - R1 B23.BAS *
'****************************************************************

' MCU Selection
Device = 12F675

' 8.000Mhz Crystal
XTAL = 8

' Define Symbolic Pin References
Symbol DQ = GPIO.0 ' 1-Wire Net Pin
Symbol TX = GPIO.1 ' Bluetooth TX
Symbol RX = GPIO.2 ' Bluetooth RX

' Configuration Fuses: External Oscillator (High-Speed), Watchdog off, Code-Protect Off
Config HS_OSC, WDT_OFF, CP_OFF

' Define Variables
Dim temperature As Word
Dim C As Byte
Dim CPerD As Byte
Dim sample_count As Word
Dim sample_delay As Word
Dim tx_pace As Word
Dim temp_dec As Byte
Dim sign As Byte

' Inserts a small delay between the transmission of each character to prevent data loss
tx_pace = 80

' Sample Rate
sample_delay = 10000


' Set all pins as digital
ALL_DIGITAL = true

' Set pin directions
Output TX
Input RX


' 20-Second Boot Delay
DelayMS 20000


' Display "POST" information
SerOut TX, 84, tx_pace, [13, 10, 10, 10, "Bluetooth Thermometer - Power Up Sucessful", 13, 10]
SerOut TX, 84, tx_pace, [13, 10, "Hardware Version: R3.0"]
SerOut TX, 84, tx_pace, [13, 10, "Firmware Version: R1 B23"]
SerOut TX, 84, tx_pace, [13, 10, "Sample Spacing (seconds): ", Dec sample_delay/1000, 13, 10]

' SerOut Data Format: SerOut (pin)(Baudmode (9600 8N1 Inverted))(Pace)[Data]


' Blank Space
SerOut TX, 84, tx_pace, [13,10,10,10]

' Wait two seconds
DelayMS 2000

' Initialize Sample Counter to zero
sample_count = 0


' Print "START" to signal the begining of the data collection to the host
SerOut TX, 84, tx_pace, ["START", 13, 10,10]


' Main sampling/transmission loop
acquisition:

OWrite DQ, 1, fault, [$CC, $44] ' Send calculate temperature command
' If no 1-Wire sensor is found, jump to the "fault" function
' OWrite and ORead functions are quite comprehensive - See the PICBasic Library for details


Repeat
DelayMS 50 ' Wait for the conversion to complete
ORead DQ, 4, [C] ' Read the counter value from the DS18B20
Until C <> 0

OWrite DQ, 1, [$CC, $BE] ' Send "Read Scratchpad" command
ORead DQ, 2, [temperature.LowByte,temperature.HighByte, C, C, C, C, C, CPerD]


' Figure out if the value is positive or negative; flip the sign
' Bits 8-15 are 1 for a negative temperature and 0 for a positive
If temperature.8=1 Then

' If negative then drop the first bit, and invert the value
temperature=(temperature.LowByte ^ $FF) >> 1

' If Count = 0 then increment Temp
If C = 0 Then temperature = temperature + 1
' Change the sign to a negative
sign = "-"
Else
' If positive then drop the first byte
temperature = (temperature >> 1)
' And change the sign value to positive
sign = "+"

' Invert the decimal value
temp_dec = 100 - temp_dec
EndIf

' Each Count is 1/16 of a degree, therefore 100/16 = 6.25, and that's our decimal value (of the temperature)
temp_dec = (6.25 * C)


' Increment the sample counter
sample_count = (sample_count + 1)


' Transmit the data to the host over the Bluetooth Link
' Transmitting "" seems to prevent data loss
SerOut TX, 84, tx_pace, [""]

' Format: sample count, comma, sign, temperature whole, decimal place, temperature fraction, "c"
SerOut TX, 84, tx_pace, [Dec sample_count, ", ", sign, Dec temperature, ".", Dec Dig temp_dec, 1, 0, "c", 13, 10]


' Wait for the specified amount of time before sending the next sample
DelayMS sample_delay

' Restart the sampling acquisition process
GoTo acquisition


' If the 1-Wire sensor is not found, the first OWRITE command will fail and jump here to indicate the fault
fault:
SerOut TX, 84, tx_pace, [13, 10, "ERROR: 1-Wire Network Fault Detected - Check Sensor Wiring", 13, 10]
DelayMS 1000
' Try again - If the problem is fixed return to normal operation
GoTo acquisition






DS18B20 Bluetooth Thermometer

DS18B20 Bluetooth Thermometer





Accurate LC Meter Capacitance Inductance Meter with 16F628 and LCD
Volt Ampere Meter with 16F876 Microcontroller and LCD display
 
Accurate LC Meter

Build your own Accurate LC Meter (Capacitance Inductance Meter) and start making your own coils and inductors. This LC Meter allows to measure incredibly small inductances making it perfect tool for making all types of RF coils and inductors. LC Meter can measure inductances starting from 10nH - 1000nH, 1uH - 1000uH, 1mH - 100mH and capacitances from 0.1pF up to 900nF. The circuit includes an auto ranging as well as reset switch and produces very accurate and stable readings.
PIC Volt Ampere Meter

Volt Ampere Meter measures voltage of 0-70V or 0-500V with 100mV resolution and current consumption 0-10A or more with 10mA resolution. The meter is a perfect addition to any power supply, battery chargers and other electronic projects where voltage and current must be monitored. The meter uses PIC16F876A microcontroller with 16x2 backlighted LCD.

50MHz 60MHz Frequency Meter / Counter with 16F628 & LCD
1Hz - 2MHz XR2206 Function Generator
60MHz Frequency Meter / Counter

Frequency Meter / Counter measures frequency from 10Hz to 60MHz with 10Hz resolution. It is a very useful bench test equipment for testing and finding out the frequency of various devices with unknown frequency such as oscillators, radio receivers, transmitters, function generators, crystals, etc.
1Hz - 2MHz XR2206 Function Generator

1Hz - 2MHz XR2206 Function Generator produces high quality sine, square and triangle waveforms of high-stability and accuracy. The output waveforms can be both amplitude and frequency modulated. Output of 1Hz - 2MHz XR2206 Function Generator can be connected directly to 60MHz Counter for setting precise frequency output.

BA1404 HI-FI Stereo FM Transmitter
USB IO Board PIC18F2455 / PIC18F2550
BA1404 HI-FI Stereo FM Transmitter

Be "On Air" with your own radio station! BA1404 HI-FI Stereo FM Transmitter broadcasts high quality stereo signal in 88MHz - 108MHz FM band. It can be connected to any type of stereo audio source such as iPod, Computer, Laptop, CD Player, Walkman, Television, Satellite Receiver, Tape Deck or other stereo system to transmit stereo sound with excellent clarity throughout your home, office, yard or camp ground.
USB IO Board

USB IO Board is a tiny spectacular little development board / parallel port replacement featuring PIC18F2455/PIC18F2550 microcontroller. USB IO Board is compatible with Windows / Mac OSX / Linux computers. When attached to Windows IO board will show up as RS232 COM port. You can control 16 individual microcontroller I/O pins by sending simple serial commands. USB IO Board is self-powered by USB port and can provide up to 500mA for electronic projects. USB IO Board is breadboard compatible.

ESR Meter / Transistor Tester Kit
Audiophile Headphone Amplifier Kit
 
ESR Meter / Capacitance / Inductance / Transistor Tester Kit

ESR Meter kit is an amazing multimeter that measures ESR values, capacitance (100pF - 20,000uF), inductance, resistance (0.1 Ohm - 20 MOhm), tests many different types of transistors such as NPN, PNP, FETs, MOSFETs, Thyristors, SCRs, Triacs and many types of diodes. It also analyzes transistor's characteristics such as voltage and gain. It is an irreplaceable tool for troubleshooting and repairing electronic equipment by determining performance and health of electrolytic capacitors. Unlike other ESR Meters that only measure ESR value this one measures capacitor's ESR value as well as its capacitance all at the same time.
Audiophile Headphone Amplifier Kit

Audiophile headphone amplifier kit includes high quality audio grade components such as Burr Brown OPA2134 opamp, ALPS volume control potentiometer, Ti TLE2426 rail splitter, Ultra-Low ESR 220uF/25V Panasonic FM filtering capacitors, High quality WIMA input and decoupling capacitors and Vishay Dale resistors. 8-DIP machined IC socket allows to swap OPA2134 with many other dual opamp chips such as OPA2132, OPA2227, OPA2228, dual OPA132, OPA627, etc. Headphone amplifier is small enough to fit in Altoids tin box, and thanks to low power consumption may be supplied from a single 9V battery.
 

Arduino Prototype Kit
RF Remote Control 433MHz Four Channel
 
Arduino Prototype Kit

Arduino Prototype is a spectacular development board fully compatible with Arduino Pro. It's breadboard compatible so it can be plugged into a breadboard for quick prototyping, and it has VCC & GND power pins available on both sides of PCB. It's small, power efficient, yet customizable through onboard 2 x 7 perfboard that can be used for connecting various sensors and connectors. Arduino Prototype uses all standard through-hole components for easy construction, two of which are hidden underneath IC socket. Board features 28-PIN DIP IC socket, user replaceable ATmega328 microcontroller flashed with Arduino bootloader, 16MHz crystal resonator and a reset switch. It has 14 digital input/output pins (0-13) of which 6 can be used as PWM outputs and 6 analog inputs (A0-A5). Arduino sketches are uploaded through any USB-Serial adapter connected to 6-PIN ICSP female header. Board is supplied by 2-5V voltage and may be powered by a battery such as Lithium Ion cell, two AA cells, external power supply or USB power adapter.
200m 4-Channel 433MHz Wireless RF Remote Control

Having the ability to control various appliances inside or outside of your house wirelessly is a huge convenience, and can make your life much easier and fun. RF remote control provides long range of up to 200m / 650ft and can find many uses for controlling different devices, and it works even through the walls. You can control lights, fans, AC system, computer, printer, amplifier, robots, garage door, security systems, motor-driven curtains, motorized window blinds, door locks, sprinklers, motorized projection screens and anything else you can think of.
 

Electronics-DIY.com © 2002-2024. All Rights Reserved.