본문 바로가기
OldStory/Makes

부화기

by Alnilam 2013. 6. 29.
반응형

image

image

image

부하기 완성

이제 유정란만 구하면 된다.


다음은 아두이노 소스 코드 

#include "LCD4884.h"

#include <Wire.h>


#define ON 1

#define OFF 0

#define TARGET_TEMP 38.0

#define ALPHA 0.5


const int light = 13;


unsigned int day;

unsigned int hour;

unsigned int minute;

unsigned int sec;


void setup()

{

    Serial.begin(9600);

    Wire.begin(); // join i2c bus (address optional for master)

    lcd.LCD_init();

    lcd.LCD_clear();

    lcd.LCD_backlight(0);

    

    pinMode(light, OUTPUT);

    

    digitalWrite(light, ON);

    

    day = 0;

    hour = 4;

    minute = 10;

    sec = 0;

}


#define SHT20_I2C_ADDRESS 0x40

#define SHT20_I2C_CMD_MEASURE_TEMP 0xe3

#define SHT20_I2C_CMD_MEASURE_HUMI 0xe5

void sht20_cmd(byte cmd)

{

  Wire.beginTransmission(SHT20_I2C_ADDRESS); // transmit to device 

  Wire.write(byte(cmd));            // sends instruction byte  

  Wire.endTransmission();     // stop transmitting

}


unsigned int sht20_cmd_read()

{

  byte msb,lsb;

  byte checksum;

  unsigned int measure;

 

  Wire.requestFrom(SHT20_I2C_ADDRESS, 3);  // read request for measure msb, lsb and checksum

  msb = Wire.read();

  lsb= Wire.read();

  checksum = Wire.read();

 

  measure = msb<<8 | (lsb & 0xfc);

  

  return measure;

}


void sendPlotData(String seriesName, float data)

{

  Serial.print("{");

  Serial.print(seriesName);

  Serial.print(",T,");

  Serial.print(data);

  Serial.print("}");

}



void loop()

{

  float temp = 0.0; // temperature

  float humi = 0.0; // releative humidity

  

  sht20_cmd(SHT20_I2C_CMD_MEASURE_TEMP);

  temp = -46.85 + 175.72 * sht20_cmd_read()/65536;

  lcd.setCursor(0,1);

  lcd.print("TEMP : ");

  lcd.print(temp);

  

  

  sht20_cmd(SHT20_I2C_CMD_MEASURE_HUMI);

  humi = -6.0 + 125.0 * sht20_cmd_read()/65536;

  lcd.setCursor(0,2);

  lcd.print("HUMI : ");

  lcd.print(humi);

  

  if(temp > TARGET_TEMP+ALPHA)

      digitalWrite(light, OFF);  // off

  else if (temp < TARGET_TEMP-ALPHA)

      digitalWrite(light, ON);

      

  sendPlotData("TEMP", temp);

  sendPlotData("HUMI", humi);

  delay(1000);

  

  sec++;

  if(sec == 60 ) {

     sec = 0;

     minute ++;

  }

  if(minute == 60) {

    minute = 0;

    hour ++ ;

  }

  if(hour == 24) {

    hour = 0;

    day ++ ;

  }

  

  lcd.setCursor(0,4);

  lcd.print("DAY :");

  lcd.print(day);


  lcd.setCursor(0,5);

  lcd.print("TIME:");


  lcd.print(hour);

  lcd.print(":");

  lcd.print(minute);

  lcd.print(":");

  lcd.print(sec);

  lcd.print("  ");

}


반응형

'OldStory > Makes' 카테고리의 다른 글

Raffaello D'Andrea: The astounding athletic power of quadcopters  (0) 2013.07.09
Reprap  (0) 2013.07.06
계란부화기 - 온습도 센서 테스트  (0) 2013.06.27
계란부화기 - 부품 구입  (0) 2013.06.26
쿼드콥터  (0) 2013.06.22