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.
/*
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.