Pages: [1]   Go Down
Author Topic: Interfacing CO2 sensor with Android phone  (Read 1478 times)
0 Members and 1 Guest are viewing this topic.
Offline Offline
Newbie
*
Karma: 0
Posts: 5
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

Hello, I am working on interfacing a CO2 sensor with an Android phone via Arduino. I'm using this toolkit called Amarino

http://www.amarino-toolkit.net/

So far I have the bluetooth module communicating with the arduino over serial and the phone can successfully connect to the bluetooth module. Now the CO2 sensor I plan on connecting to the arduino via serial as well, so after some reading I decided I needed to use a software serial implementation as my arduino the Duemilanove only has one serial.

Now communication with the co2 sensor involves a Master/Slave situation. I must send the CO2 sensor 8 hexadecimal bytes and then read seven hex bytes of which the 4th and fifth concatenated is the co2 concentration.

I have some code, but as this is my first Arduino and I just learned about serial communication I am unsure if I am going in the write direction code wise.

Code:
/*
  Sends sensor data to Android
*/
 
#include <MeetAndroid.h>

//Software Serial Start
// include the SoftwareSerial library so you can use its functions:
#include <SoftwareSerial.h>

#define rxPin 2
#define txPin 3
// set up a new serial port
SoftwareSerial mySerial =  SoftwareSerial(rxPin, txPin);
byte pinState = 0;
byte inArray[8];
byte outArray[7];
//Software Serial End

MeetAndroid meetAndroid;




void setup()  
{
  //Software Serial Start
    // define pin modes for tx, rx, led pins:
  pinMode(rxPin, INPUT);
  pinMode(txPin, OUTPUT);
  // set the data rate for the SoftwareSerial port
  mySerial.begin(9600);
  //Software Serial End
  
 // Bluetooth Module Baud rate
  Serial.begin(115200);
  //Software Serial Start
  inArray[0]=0xFE;
  inArray[1]=0x04;
  inArray[2]=0x00;
  inArray[3]=0x03;
  inArray[4]=0x00;
  inArray[5]=0x01;
  inArray[6]=0xD5;
  inArray[7]=0xC5;
}


void loop()
{
  meetAndroid.receive(); // you need to keep this in your loop() to receive events
  
  // print out the character:
  for (int i = 0; i<8; i+=1){
    mySerial.print(inArray[i], HEX);
  }  
    // listen for new serial coming in:
  for (int i=0; i<7; i++){
    outArray[i] = mySerial.read();
  }
  /* To be implemented: obtaining the CO2 readings.
   concatenate outArray[4] and outArray[5] and convert to
   decimal.
   */
  String ppm = "CO2 in ppm";
  //send result to Android
  meetAndroid.send(ppm);
  
  // add a little delay otherwise the phone is pretty busy
  delay(100);
}


I am quite new at this; any help is welcome and appreciated.
« Last Edit: July 12, 2011, 07:27:30 pm by erwinreu » Logged

SF Bay Area
Offline Offline
Full Member
***
Karma: 1
Posts: 182
Arduino rocks
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

What CO2 sensor are you using?

It sounds similar to one that I was working with.
Logged

Offline Offline
Newbie
*
Karma: 0
Posts: 5
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

I'm using this sensor.

http://www.co2meter.com/collections/co2-sensors/products/k-30-co2-sensor-development-kit

I guess what I'm asking is: Is my communication over the Software Serial being done correctly?
« Last Edit: July 12, 2011, 07:28:17 pm by erwinreu » Logged

Global Moderator
Netherlands
Offline Offline
Shannon Member
*****
Karma: 212
Posts: 13531
In theory there is no difference between theory and practice, however in practice there are many...
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset


You should use NewSoftSerial iso SoftSerial as it is far more stable.
Logged

Rob Tillaart

Nederlandse sectie - http://arduino.cc/forum/index.php/board,77.0.html -
(Please do not PM for private consultancy)

SF Bay Area
Offline Offline
Full Member
***
Karma: 1
Posts: 182
Arduino rocks
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

I haven't used NewSoftSerial yet. But I don't think you'll have much trouble.
Logged

Offline Offline
Newbie
*
Karma: 0
Posts: 5
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

Thanks for the advice; I'll look into it.
Logged

0
Offline Offline
Newbie
*
Karma: 0
Posts: 10
Arduino rocks
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

Hello,

This is Andrew Robinson with CO2 Meter. I saw your post this morning.

I would recommend using I2C communication personally, it's a lot simpler and you'll be able to use the hardware I2C engine most likely.

Check out the simple Arduino application note, it's for the older platforms, but it should be directly relevant:
http://cdn.shopify.com/s/files/1/0019/5952/files/Senseair-Arduino.pdf?1264294173

Do let me know if you have any further questions! We love to help out people using our product in interesting ways.
Logged

Andrew Robinson
andrewbrobinson.com

Pages: [1]   Go Up
Jump to: