About Temp/Humidity App for Arduino
I created this App to be able to connect to an Arduino via wireless Bluetooth. The user can then receive temperature and humidity data from the Arduino. This is designed to be used in the classroom to show students 1) how to use basic electronic devices and sensors, 2) an introduction to coding, and 3) to collect scientific data for statistical analysis.
I hope to upload a video tutorial shortly to enable you to set up the Arduino and breadboard along with the sensors and other components you will need to do this project.
The code for the Arduino is as follows:
#include "DHT.h"
#include
#define DHTPIN 2
#define DHTTYPE DHT22
DHT dht(DHTPIN, DHTTYPE);
const int analogReadPin = 2;
int outPinRed = 9;
int outPinGreen = 10;
int outPinBlue = 11;
int temperatureValue = 0;
SoftwareSerial BT(1, 0); //TX, RX respectively
void setup() {
Serial.begin(9600);
dht.begin();
pinMode(outPinRed, OUTPUT);
pinMode(outPinGreen, OUTPUT);
pinMode(outPinBlue, OUTPUT);
}
// BT.begin(9600);
void loop() {
// while (BT.available())
{
digitalWrite(outPinRed, LOW);
digitalWrite(outPinGreen, HIGH);
digitalWrite(outPinBlue, LOW);
float h = dht.readHumidity();
float t = dht.readTemperature();
float f = dht.readTemperature(true);
if (isnan(t) || isnan(h) || isnan(f))
{
Serial.println("Failed to read from DHT");
digitalWrite(outPinRed, HIGH);
digitalWrite(outPinGreen, LOW);
digitalWrite(outPinBlue, LOW);
return;
}
digitalWrite(outPinRed, LOW);
digitalWrite(outPinGreen, LOW);
digitalWrite(outPinBlue, HIGH);
temperatureValue = ((t * 9) / 5 + 32);
analogWrite(analogReadPin, h);
analogWrite(analogReadPin, temperatureValue);
Serial.print("Humidity = ");
Serial.print(h);
Serial.println(" %");
Serial.print("Temp = ");
Serial.print(temperatureValue);
Serial.println(" F");
}
delay(1000);
}