Datalogging Sensor Workshop

Our pick was Carbon Monoxide Sensor:

It was a difficult to get the sensor working until we realized that the sensor requires heating up for at least 60 seconds to stabilize.

here is the code:

#include <SD.h>

// On the Ethernet Shield, CS is pin 4. Note that even if it’s not
// used as the CS pin, the hardware CS pin (10 on most Arduino boards,
// 53 on the Mega) must be left as an output or the SD library
// functions will not work.
const int chipSelect = 8;
const int analogInPin = A0; // Analog input pin that the potentiometer is attached to
const int analogOutPin = 9; // Analog output pin that the LED is attached to

int sensorValue = 0; // value read from the pot

void setup() {

// initialize serial communications at 9600 bps:
Serial.begin(9600);
pinMode(7,OUTPUT);

if (!SD.begin(chipSelect)) {
Serial.println(“Card failed, or not present”);

while(true){
digitalWrite(7,LOW);
delay(1000);
digitalWrite(7,HIGH);
delay(1000);
}

// don’t do anything more:
return;
}
Serial.println(“card initialized.”);

unsigned char i;
digitalWrite(7,LOW);
for (i=0;i<60;i++){
delay(1000);
Serial.print(“preheating….”);
Serial.print(i);
Serial.println(” of 60 seconds”);
}
Serial.println(“preheating finished.”);
digitalWrite(7,HIGH);
}

void loop() {
digitalWrite(7,LOW);
delay(15);
digitalWrite(7,HIGH);
delay(3);

// make a string for assembling the data to log:
String dataString = “”;

// read three sensors and append to the string:
dataString += String(millis());
dataString += “,”;
int sensor = analogRead(0);
dataString += String(sensor);

// open the file. note that only one file can be open at a time,
// so you have to close this one before opening another.
File dataFile = SD.open(“datalog.txt”, FILE_WRITE);

// if the file is available, write to it:
if (dataFile) {
dataFile.println(dataString);
dataFile.close();
// print to the serial port too:
Serial.println(dataString);
}
// if the file isn’t open, pop up an error:
else {
Serial.println(“error opening datalog.txt”);
}
}

We had to adjust the built-in potentiometer to get the value to be stabilized:

We chose the street right in front of Tisch building because there were enough cars and smokers, which we believed that they should create sufficient amount of Carbon Monoxide. We stood there for like 10 minutes starting at 7:05 PM to 7:15PM

 

 

Leave a Reply

Your email address will not be published. Required fields are marked *

*

You may use these HTML tags and attributes: <a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code> <del datetime=""> <em> <i> <q cite=""> <strike> <strong>