Page 88 - 완) I MDP 프로젝트 작품 보고서(전체과 1학년)1.6
P. 88

다. Source Code

            1) Arduino
            #include <DHT11.h>
            #define SensorPin 0          //pH meter Analog output to Arduino Analog Input 0
            #define LED 13
            #define FAN 12
            #define HEATER 11
            #define PUMP 9
            unsigned long int avgValue;  //Store the average value of the sensor feedback
            float b;
            int buf[10],temp;
            int data,count=0;
            int pin=2;    // 연결한 아두이노 디지털 핀 번호
            DHT11 dht11(pin);
            void setup()
            {
              pinMode(LED,OUTPUT);
              pinMode(HEATER,OUTPUT);
              pinMode(FAN,OUTPUT);
              pinMode(PUMP,OUTPUT);
              Serial.begin(9600);
            }

            void loop()
            {
              int err;
              float temp, humi;
              for(int i=0;i<10;i++)       //10개의 값을 받음
              {
                buf[i]=analogRead(SensorPin);
                delay(10);
              }
              for(int i=0;i<9;i++)        //10개의 값을 오름차순으로 정렬함
              {
                for(int j=i+1;j<10;j++)
                {
                  if(buf[i]>buf[j])
                  {
                    temp=buf[i];
                    buf[i]=buf[j];
                    buf[j]=temp;
                  }
                }
              }
              avgValue=0;
              for(int i=2;i<8;i++)                      //정렬된값의 중간값을 저장
                avgValue+=buf[i];
              float phValue=(float)avgValue*5.0/1024/6; // PH센서 ADC의 값을 전압으로 변환
              phValue=3.5*phValue;                      //전압을 PH값으로 변환
              Serial.print((char)phValue);             //PH값의 정수부를 블루투스로 통신
              Serial.print((char)((phValue-(int)phValue)*100));   //PH값의 소수부를 블루투스로 통신
            if((err=dht11.read(humi, temp))==0)       //에러가 없을경우
              {
                Serial.print((char)temp);              //온도값 출력
                Serial.print((char)humi);              //습도값 출력
              }
              else                                      //에러가 있을경우
              {
                Serial.println();
                Serial.print("Error No :");            //온습도센서의 에러 출력
                Serial.print(err);
                Serial.println();




                                                         -  81  -
   83   84   85   86   87   88   89   90   91   92   93