Last active
August 29, 2015 14:01
-
-
Save davidkaste/cf6d0dbee89dbb244d78 to your computer and use it in GitHub Desktop.
Bluetooth temperature monitor
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/* | |
* Author: David Castellà <d.castella.85 at gmail dot com> | |
* Sketch title: Bluetooth temperature monitor | |
* Sketch filename: btmon.ino | |
* Date: 2014/05/21 | |
* Version: 0.1 | |
* | |
* This program is free software: you can redistribute it and/or modify | |
* it under the terms of the GNU General Public License as published by | |
* the Free Software Foundation, either version 3 of the License, or | |
* (at your option) any later version. | |
* | |
* This program is distributed in the hope that it will be useful, | |
* but WITHOUT ANY WARRANTY; without even the implied warranty of | |
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | |
* GNU General Public License for more details. | |
* | |
* You should have received a copy of the GNU General Public License | |
* along with this program. If not, see <http://www.gnu.org/licenses/>. | |
*/ | |
#include <OneWire.h> | |
#include <SoftwareSerial.h> | |
#include <DallasTemperature.h> | |
#define ONE_WIRE_BUS 2 | |
#define RxD 10 | |
#define TxD 11 | |
#define KEY 4 | |
#define LED 2 | |
/**/ | |
#define userid 1 | |
/**/ | |
OneWire oneWire(ONE_WIRE_BUS); | |
DallasTemperature sensors(&oneWire); | |
SoftwareSerial BTSerial(RxD, TxD); | |
byte pinEstado = 0; | |
void setup() { | |
pinMode(LED, OUTPUT); | |
pinMode(KEY, OUTPUT); | |
pinMode(13, OUTPUT); | |
digitalWrite(13, LOW); | |
digitalWrite(LED, LOW); | |
digitalWrite(KEY, LOW); | |
BTSerial.begin(9600); | |
BTSerial.flush(); | |
delay(500); | |
Serial.begin(9600); | |
Serial.flush(); | |
Serial.println("Ready"); | |
sensors.begin(); | |
} | |
void loop() { | |
char command; | |
float temp; | |
String response = ""; | |
if (BTSerial.available()) { | |
command = BTSerial.read(); | |
BTSerial.flush(); | |
Serial.println("Received request for temperature"); | |
if (command == 'T') { | |
Serial.println("Sending response with temp value: "); | |
temp = getTemp(); | |
Serial.print(userid); | |
Serial.print("/"); | |
Serial.println(temp); | |
BTSerial.print(userid); | |
BTSerial.print("/"); | |
BTSerial.println(temp); | |
} | |
} | |
} | |
float getTemp() { | |
sensors.requestTemperatures(); | |
return sensors.getTempCByIndex(0); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment