domingo, 24 de janeiro de 2016

Sensor de CO2 K-30 - Arquivo 004

Referência: 
http://www.co2meters.com/Documentation/AppNotes/AN126-K3x-sensor-arduino-uart.pdf

Lista de Materiais:
IDE Arduino 1.0.6
1x  Board Arduino UNO
1x  Protoboard 830 furos
1x  Cabo USB-A male to USB-B male 
1x  Conj. de fios jumper p/ protoboard
1x  Sensor de CO2 K-30

Montagem:





Firmware 01:
#include "SoftwareSerial.h"

SoftwareSerial K_30_Serial(12,13);  
                                    
byte readCO2[] = {0xFE, 0X44, 0X00, 0X08, 0X02, 0X9F, 0X25};  
byte response[] = {0,0,0,0,0,0,0}; 
int valMultiplier = 1;
//******************************************************************
void setup(){
  Serial.begin(9600);         
  K_30_Serial.begin(9600);    
}
//******************************************************************
void loop() {
  sendRequest(readCO2);
  unsigned long valCO2 = getValue(response);
  Serial.print("Co2 ppm = ");
  Serial.println(valCO2);
  delay(2000);
}
//******************************************************************
void sendRequest(byte packet[]){
  while(!K_30_Serial.available()){
    K_30_Serial.write(readCO2,7);
    delay(50);
  }
  int timeout=0;  
  while(K_30_Serial.available() < 7 ){
    timeout++;  
    if(timeout > 10){
        while(K_30_Serial.available()) 
          K_30_Serial.read();
          break;                        
      }
      delay(50);
  }
  for (int i=0; i < 7; i++){
    response[i] = K_30_Serial.read();
  }  
}
//******************************************************************
unsigned long getValue(byte packet[]){
    int high = packet[3];                        
    int low = packet[4];                         
    unsigned long val = high*256 + low;                
    return val* valMultiplier;

}

Firmware 02:
#include "kSeries.h"

kSeries K_30(12,13); 
//******************************************************************
void setup(){
 Serial.begin(9600); 
 Serial.println("Serial Up!");
}
//******************************************************************
void loop(){
 double co2 = K_30.getCO2('p');      //returns co2 value in ppm ('p')  or porcent ('%')
 Serial.print("Co2 ppm = ");
 Serial.println(co2);

}

Download: kSeries.h

Nenhum comentário:

Postar um comentário