에프티크레이이티드(http://fdc.ne.kr)에서 제공하는 교육용 아두이노를 이용하여 제작했습니다.

사용한 센서는 

- 조도 센서

- 온도 센서

- 습도 센서

를 사용하여 

버튼을 땐경우에는 - 온도,습도 를 출력

버튼을 누른경우에는 - 조도를 출력합니다.


#include 
#include 
#include  
#define dataPin  22 // 온습도 데이터 입력핀 설정
#define clockPin 23 // 시간 데이터 입력핀 설정
SHT1x sht1x(dataPin, clockPin);
LiquidCrystal lcd(32, 54, 33, 34, 35, 36, 37);
int buttonState = 0;
const int cdsInPin = A0;  // Analog input pin that the potentiometer is attached to
const int analogInPin = A1;  // Analog input pin that the potentiometer is attached to

int sensorValue = 0;        // value read from the pot
int cdsValue = 0;        // value read from the pot


void setup()
{
   Serial.begin(9600); // 
   Serial.println("Starting up");
   Wire.begin();        // join i2c bus (address optional for master) 
   delay(500);  
   pinMode(8, INPUT);  //LED Set "Relay Board Cn1"
   lcd.begin(8,2);              // 8열 2줄 LCD 활용 시작
   lcd.clear();                  // LCD 화면 비움
  
}
void loop()
{
  buttonState = digitalRead(8);
  sensorValue = analogRead(analogInPin);
  cdsValue = analogRead(cdsInPin)*10;   
  float sensor;
  float cds;
  
  // Read values from the sensor
  sensor = analogInPin;
  cds = cdsInPin;   
  const int lookup[10] = {0x3F,0x06,0x5B,0x4F,0x66,
                          0x6D,0x7D,0x07,0x7F,0x6F};
  int Count, Thousands, Hundreds, Tens, Base;  
  Wire.beginTransmission(0x38);
  Wire.write((byte) 0);
  Wire.write(B01000111);
  Wire.endTransmission();
  
  float temp_c; // 섭씨 
  float temp_f; // 화씨
  float humidity; // 습도

  // 위의 변수 값에 센서로부터의 값을 입력 받도록 설정한다.
  temp_c = sht1x.readTemperatureC();
  temp_f = sht1x.readTemperatureF();
  humidity = sht1x.readHumidity();

  if(buttonState == HIGH){
  
      //LCD START
      lcd.setCursor(0,0);           // 0, 0 윗줄 시작
      lcd.print("Temp= ");    // 따옴표 사이에 원하는 글을 적는다.
      lcd.print(temp_c, DEC);    // 따옴표 사이에 원하는 글을 적는다.
      
      lcd.setCursor(0,1);           // 0, 1 아랫줄 시작
      lcd.print("Humi= ");
      lcd.print(temp_f, DEC);
      //LCD END
      
      // 7 SEGMENT START
      Wire.beginTransmission(0x38);
      Wire.write(1);
      Thousands = (int)temp_c/10;
      Hundreds = (int)(temp_c - (Thousands*10));
      Tens = (int)temp_f/10;
      Base = (int)(temp_f - (Tens*10));
      
      Wire.write(lookup[Thousands]);
      Wire.write(lookup[Hundreds]);
      Wire.write(lookup[Tens]);
      Wire.write(lookup[Base]);
      Wire.endTransmission();

      
  }else{
      
    if(cdsValue >= 160)
      {
        Serial.print("Relay Cn1 On\n");
        Serial.print("Trun off Light 0n\n");
    
        digitalWrite(33, LOW);
        digitalWrite(32, HIGH);
        
        lcd.begin(8,2); 
        lcd.clear();
        lcd.setCursor(0,0);        
        lcd.print("cds");   
        lcd.print(cdsValue,DEC);
        lcd.setCursor(0,1);          
        lcd.print("lightoff");
        
        Wire.beginTransmission(0x38);
        Wire.write(1);
        if(cdsValue>99 && cdsValue<1000){
          Thousands = 0;
          Hundreds = cdsValue/100;
          Tens = (cdsValue - (Hundreds*100))/10;
          Base = (cdsValue - (Hundreds*100)-(Tens*10));
        
          Wire.write(lookup[Thousands]);
          Wire.write(lookup[Hundreds]);
          Wire.write(lookup[Tens]);
          Wire.write(lookup[Base]);
          Wire.endTransmission();

        }else if(cdsValue>9 && cdsValue<100){
          Thousands = 0;
          Hundreds = 0;
          Tens = cdsValue/10;
          Base = (cdsValue - (Tens*10));
          
          Wire.write(lookup[Thousands]);
          Wire.write(lookup[Hundreds]);
          Wire.write(lookup[Tens]);
          Wire.write(lookup[Base]);
          Wire.endTransmission();

        }else if(cdsValue>10){
          Thousands = 0;
          Hundreds = 0;
          Tens = 0;
          Base = cdsValue;
        
          Wire.write(lookup[Thousands]);
          Wire.write(lookup[Hundreds]);
          Wire.write(lookup[Tens]);
          Wire.write(lookup[Base]);
          Wire.endTransmission();

        }
      }
  
    else
    {
      Serial.print("Relay Cn2 On\n");
      Serial.print("Trun On the light On\n");
  
      digitalWrite(32, LOW);
      digitalWrite(33, HIGH);
      
      lcd.begin(8,2); 
      lcd.clear();
      lcd.setCursor(0,0);        
      lcd.print("cds ");   
      lcd.print(cdsValue,DEC);
      lcd.setCursor(0,1);          
      lcd.print("light on");
    }
  }
  // 7 SEGMENT END
  delay(50);
}






이 프로그램을 응용하여 릴리즈를 활용하여 

조도값을 받아 어두울때는 전등을 키고 밝을때는 전등을끄는 기능과

추울때는 히터를 틀고 더울때는 히터를 키는 소스를 구현하였습니다.



 

#include 
#include 
#include  
#define dataPin  22 // 온습도 데이터 입력핀 설정
#define clockPin 23 // 시간 데이터 입력핀 설정
SHT1x sht1x(dataPin, clockPin);
LiquidCrystal lcd(40, 54, 41, 42, 43, 44, 45);
const int cdsInPin = A0;  // Analog input pin that the potentiometer is attached to
const int analogInPin = A1;  // Analog input pin that the potentiometer is attached to

int sensorValue = 0;        // value read from the pot
int cdsValue = 0;        // value read from the pot


void setup()
{
   Serial.begin(9600); // 
   Serial.println("Starting up"); 
   pinMode(32, OUTPUT); 
   pinMode(33, OUTPUT);    
   lcd.begin(8,2);              // 8열 2줄 LCD 활용 시작
   lcd.clear();                  // LCD 화면 비움
  
}
void loop()
{

  sensorValue = analogRead(analogInPin);
  cdsValue = analogRead(cdsInPin)*10;   
  float sensor;
  float cds;
  
  // Read values from the sensor
  sensor = analogInPin;
  cds = cdsInPin;   
  
  float temp_c; // 섭씨 
  float temp_f; // 화씨
  float humidity; // 습도

  // 위의 변수 값에 센서로부터의 값을 입력 받도록 설정한다.
  temp_c = sht1x.readTemperatureC();
  temp_f = sht1x.readTemperatureF();
  humidity = sht1x.readHumidity();

  if(temp_c<20){ // 온도의 기준은 20도
  
      //LCD START
      lcd.setCursor(0,0);           // 0, 0 윗줄 시작
      lcd.print("T=");    // 따옴표 사이에 원하는 글을 적는다.
      lcd.print((int)temp_c, DEC);    // 따옴표 사이에 원하는 글을 적는다.
      digitalWrite(32, HIGH); 
      lcd.print(" ON  ");    // 따옴표 사이에 원하는 글을 적는다.
      
  }else{
    //LCD START
      lcd.setCursor(0,0);           // 0, 0 윗줄 시작
      lcd.print("T=");    // 따옴표 사이에 원하는 글을 적는다.
      lcd.print((int)temp_c, DEC);    // 따옴표 사이에 원하는 글을 적는다.
      digitalWrite(32, LOW); 
      lcd.print(" OFF  ");    // 따옴표 사이에 원하는 글을 적는다.
  }
      
  if(cdsValue >= 160) // 밝기의 기준은 160
    {
      Serial.print("Relay Cn1 On\n");
      Serial.print("Trun off Light 0n\n");
  
      lcd.setCursor(0,1);
      lcd.print("L=");    // 따옴표 사이에 원하는 글을 적는다.
      lcd.print(cdsValue, DEC);    // 따옴표 사이에 원하는 글을 적는다.
      lcd.print(" OFF  ");    // 따옴표 사이에 원하는 글을 적는다.
      digitalWrite(33, LOW); 
  }
  else
  {
    Serial.print("Relay Cn2 On\n");
    Serial.print("Trun On the light On\n");

    lcd.setCursor(0,1);          
    lcd.print("L=");    // 따옴표 사이에 원하는 글을 적는다.
    lcd.print(cdsValue, DEC);    // 따옴표 사이에 원하는 글을 적는다.
    lcd.print(" ON  ");    // 따옴표 사이에 원하는 글을 적는다.
    digitalWrite(33, HIGH); 
  }
  delay(1000);
}




+ Recent posts