What with the glorious sunny weather, I wondered how hot my flat actually gets. It's certainly felt far too warm recently.
Now, the sensible way to find out is to go and buy a thermometer. But Robert Days are closed for the evening. So instead I dug out an Arduino kit I was given for my birthday (Elegoo's "The Most Complete Starter Kit for the Mega 2560") and set to work...
The answer: 27°C!
I'm using a DHT11 combined temperature and humidity sensor and a generic LCD display showing the results, running off of a 9V battery so I can wander around with it. The nice thing about Arduino development is there are libraries for everything, so there's surprisingly little code behind this:
// Based off sample lessons 12 (DHT11) and 22 (LCD)
// DHT11
#include
#define DHT_SENSOR_TYPE DHT_TYPE_11
static const int DHT_SENSOR_PIN = 2;
DHT_nonblocking dht_sensor( DHT_SENSOR_PIN, DHT_SENSOR_TYPE );
/*
* Poll for a measurement, keeping the state machine alive. Returns
* true if a measurement is available.
*/
static bool measure_environment( float *temperature, float *humidity )
{
static unsigned long measurement_timestamp = millis( );
/* Measure once every four seconds. */
if( millis( ) - measurement_timestamp > 3000ul )
{
if( dht_sensor.measure( temperature, humidity ) == true )
{
measurement_timestamp = millis( );
return( true );
}
}
return( false );
}
// LCD
// include the library code:
#include
// initialize the library with the numbers of the interface pins
LiquidCrystal lcd(7, 8, 9, 10, 11, 12);
void setup() {
// set up the LCD's number of columns and rows:
lcd.begin(16, 2);
// Print a message to the LCD.
//01234567890123456
lcd.print("Temp: ");
lcd.setCursor(0, 1);
//01234567890
lcd.print("Humidity: ");
}
void loop() {
float temperature;
float humidity;
/* Measure temperature and humidity. If the functions returns
true, then a measurement is available. */
if( measure_environment( &temperature, &humidity ) == true )
{
Serial.print( "T = " );
Serial.print( temperature, 1 );
Serial.print( " deg. C, H = " );
Serial.print( humidity, 1 );
Serial.println( "%" );
lcd.setCursor(10, 0);
lcd.print(" ");
lcd.setCursor(10, 0);
lcd.print(temperature, 1);
lcd.print("C");
lcd.setCursor(10, 1);
lcd.print(" ");
lcd.setCursor(10, 1);
lcd.print(humidity, 1);
lcd.print("%");
}
}