제어예제

뒤로가기
제목

가스(연기)센서

작성자 대표 관리자(ip:)

작성일 2017-08-11 16:01:41

조회 164

평점 0점  

추천 추천하기

내용

가스(연기)센서


============================================

int led = 12; //LED pin
int gas_sensor = A0; //Sensor pin

float m = -0.318; //Slope
float b = 1.133; //Y-Intercept
float R0 = 11.820; //Sensor Resistance in fresh air from previous code

void setup()

 {
  Serial.begin(115200); //Baud rate
  pinMode(led, OUTPUT); //Set LED as output
  digitalWrite(led, LOW); //Turn LED off
  pinMode(gas_sensor, INPUT); //Set gas sensor as input
}

void loop()

 {
  float sensor_volt; //Define variable for sensor voltage
  float RS_gas; //Define variable for sensor resistance
  float ratio; //Define variable for ratio
  float sensorValue = analogRead(gas_sensor);   //Read analog values of sensor
  sensor_volt = sensorValue * (5.0 / 1023.0);      //Convert analog values to voltage
  RS_gas = ((5.0 * 10.0) / sensor_volt) - 10.0;    //Get value of RS in a gas
  ratio = RS_gas / R0;                                        // Get ratio RS_gas/RS_air

  double ppm_log = (log10(ratio) - b) / m;          //Get ppm value in linear scale according to the the ratio value
  double ppm = pow(10, ppm_log);                    //Convert ppm value to log scale
  double percentage = ppm / 10000;                  //Convert to percentage
  Serial.print(percentage);                     //Load screen buffer with percentage value
  Serial.println("%");                              //Load screen buffer with "%"

  if (ppm > 2000)

{                                                       //Check if ppm value is greater than 2000
    digitalWrite(led, HIGH); //Turn LED on
  }

else

{
                                                          //Case ppm is not greater than 2000
    digitalWrite(led, LOW);
                                                            //Turn LED off
  }
  delay(500);
}



=============================================


첨부파일

비밀번호
수정

비밀번호 입력후 수정 혹은 삭제해주세요.

댓글목록

등록된 댓글이 없습니다.

댓글 수정

이름

비밀번호

내용

/ byte

수정 취소

비밀번호

확인 취소

댓글 입력

이름

비밀번호

내용

/ byte

평점

에게만 댓글 작성 권한이 있습니다.