Categories
DrupalRecover Tech

The Arduino is really quite handy to have around. Right now we’ve got one reporting the temperature and humidity of a chicken incubater. It could also control the temperature, humidity, and egg rotation but we haven’t gone there yet. Even so it’s nice to get the measurements with the audible warning. Then you can always repurpose all this stuff to do something else once you are done incubating.

You just need (unvalidated list):

Add in a stepper motor, voltage switch, and some sort of fluid controller and you could do it all. Unglorious image of this – the OLED is very nice:

Here’s the relevant code – it of course plays the 1st 4 notes of Beethoven’s 5th as a warning (or at least an attempt at that not having found the true notes):

#include <Wire.h>
#include "Adafruit_GFX.h"
#include "Adafruit_SSD1306.h"
#include <Adafruit_Sensor.h>
#include "DHT.h"
#define OLED_DC 11
#define OLED_CS 12
#define OLED_CLK 10
#define OLED_MOSI 9
#define OLED_RESET 13
Adafruit_SSD1306 display(OLED_MOSI, OLED_CLK, OLED_DC, OLED_RESET, OLED_CS);

#define DHTTYPE DHT22   // DHT 22  (AM2302)
#define DHTPIN 2     // what pin we're connected to
DHT dht(DHTPIN, DHTTYPE);

#define speakerPin 4

// TONES  ==========================================
// Start by defining the relationship between 
//       note, period, &  frequency. 
#define  c     3830    // 261 Hz 
#define  d     3400    // 294 Hz 
#define  e     3038    // 329 Hz 
#define  f     2864    // 349 Hz 
#define  g     2550    // 392 Hz 
#define  a     2272    // 440 Hz 
#define  b     2028    // 493 Hz 
#define  C     1912    // 523 Hz 

//TH 
//thermometer - humidity

float temp;
float humidity;

void setup() {
  Serial.begin(9600);
  display.begin(SSD1306_SWITCHCAPVCC);
  display.setTextSize(1);
  display.setTextColor(WHITE); 

  Serial.println("Startup!");
}

void loop() {
  display.clearDisplay();   // clears the screen and buffer
  getWeather();
}

void getWeather() {
  //-----------
  //read DHT
  float humidity = dht.readHumidity();
  float t = dht.readTemperature();
  t = t * 9.0 / 5.0 + 32.0;
  // check if returns are valid, if they are NaN (not a number) then something went wrong!
  if (isnan(t) || isnan(humidity)) {
    Serial.println("Failed to read from DHT");
  } 
  else {
    Serial.print("Humidity: "); 
    Serial.print(humidity);
    Serial.print(" %\t");
    Serial.print("Temperature: "); 
    Serial.print(t);
    Serial.println(" *C");
  }

  updateDisplay(humidity,t);

  delay(10000);   //10 seconds seems often enough
}

void updateDisplay(float h, float t) {
  display.setCursor(0,0);
  display.print("Temp:  ");
  display.print(t);
  display.println(" F");
  display.println(" ");
  display.print("Humidity:  ");
  display.println(h);
  display.println(" ");

  // warnings
  if (t < 98.8 || t > 100) {
    display.println("CHECK TEMP!!!");
    display.println(" ");
    playWarning();
  }

  if (h < 50 || h > 70) {
    display.println("CHECK HUMIDITY!!!");
    playWarning();
  }
  display.display();
}

void playWarning() {
  tone(speakerPin, g);
  delay(200);
  noTone(4);
  delay(200);
  tone(speakerPin, g);
  delay(200);
  noTone(4);
  delay(200);
  tone(speakerPin, g);
  delay(200);
  noTone(4);
  delay(200);
  tone(speakerPin, C);
  delay(400);
  noTone(4);
}

Leave a Reply

Your email address will not be published. Required fields are marked *