Skip to content

Instantly share code, notes, and snippets.

@apetrone
Created January 19, 2014 01:23
Show Gist options
  • Save apetrone/8499186 to your computer and use it in GitHub Desktop.
Save apetrone/8499186 to your computer and use it in GitHub Desktop.
aquarium_thermostat
/*
Date: January 2014
Author: Adam Petrone
Aquarium Thermostat
*/
#include <Wire.h>
#include <LiquidCrystal.h>
#include <TinyDHT.h>
#include <OneWire.h>
#include <DallasTemperature.h>
const uint8_t WATER_SENSOR_PIN = 7;
const uint8_t AMBIENT_SENSOR_PIN = 8;
// Data / Clock pins for i2c
// Leonardo: 2, 3
LiquidCrystal lcd(0);
OneWire ow(WATER_SENSOR_PIN);
DallasTemperature sensors(&ow);
DeviceAddress tempSensor;
DHT dht(AMBIENT_SENSOR_PIN, DHT22);
long last_millis = 0;
long next_sensor_check = 2000;
uint16_t temp = 0;
void setup()
{
sensors.begin();
dht.begin();
lcd.begin(16, 2);
lcd.setBacklight(HIGH);
lcd.print("initializing...");
delay(500);
lcd.clear();
lcd.setCursor(0,0);
lcd.print("Ambient Water");
}
void loop()
{
int sensor_value = analogRead(WATER_SENSOR_PIN);
// 10 to 1000
int output = map(sensor_value, 0, 1023, 10, 1000);
long delta_millis = millis() - last_millis;
next_sensor_check -= delta_millis;
last_millis = millis();
if (next_sensor_check <= 0)
{
next_sensor_check = 2000;
temp = dht.readTemperature(1);
}
{
sensors.requestTemperatures();
float value = sensors.getTempFByIndex(0);
lcd.setCursor(0,1);
lcd.print(temp);
lcd.print("F");
lcd.setCursor(10,1);
lcd.print(value);
lcd.print("F");
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment