sd card, dust sensor, bmp180(temperature,,)

#include <Wire.h>

#include <Adafruit_Sensor.h>

#include <Adafruit_BMP085_U.h>

#include <SPI.h>

#include <SD.h>

Adafruit_BMP085_Unified bmp = Adafruit_BMP085_Unified(10085);

const int chipSelect = 4;

/*

Standalone Sketch to use with a Arduino UNO and a

Sharp Optical Dust Sensor GP2Y1010AU0F

*/

int measurePin = 0; //Connect dust sensor to Arduino A0 pin

int ledPower = 2; //Connect 3 led driver pins of dust sensor to Arduino D2

int samplingTime = 280;

int deltaTime = 40;

int sleepTime = 9680;

float voMeasured = 0;

float calcVoltage = 0;

float dustDensity = 0;

void displaySensorDetails(void)

{

sensor_t sensor;

bmp.getSensor(&sensor);

Serial.println("------------------------------------");

Serial.print ("Sensor: "); Serial.println(sensor.name);

Serial.print ("Driver Ver: "); Serial.println(sensor.version);

Serial.print ("Unique ID: "); Serial.println(sensor.sensor_id);

Serial.print ("Max Value: "); Serial.print(sensor.max_value); Serial.println(" hPa");

Serial.print ("Min Value: "); Serial.print(sensor.min_value); Serial.println(" hPa");

Serial.print ("Resolution: "); Serial.print(sensor.resolution); Serial.println(" hPa");

Serial.println("------------------------------------");

Serial.println("");

delay(500);

}

void setup(void)

{

Serial.begin(9600);

Serial.println("Pressure Sensor Test"); Serial.println("");

/* Initialise the sensor */

if(!bmp.begin())

{

/* There was a problem detecting the BMP085 ... check your connections */

Serial.print("Ooops, no BMP085 detected ... Check your wiring or I2C ADDR!");

while(1);

}

if (!SD.begin(chipSelect)) {

Serial.println("Card failed, or not present");

// don't do anything more:

return;

}

Serial.println("card initialized.");

/* Display some basic information on this sensor */

displaySensorDetails();

pinMode(ledPower,OUTPUT);

}

/**************************************************************************/

/*

Arduino loop function, called once 'setup' is complete (your own code

should go here)

*/

/**************************************************************************/

void loop(void)

{

/* Get a new sensor event */

sensors_event_t event;

bmp.getEvent(&event);

/* data type init */

String dataString = "";

String pressString = "";

String altiString = "";

String tempString = "";

String dustString="";

digitalWrite(ledPower,LOW); // power on the LED

delayMicroseconds(samplingTime);

voMeasured = analogRead(measurePin); // read the dust value

delayMicroseconds(deltaTime);

digitalWrite(ledPower,HIGH); // turn the LED off

delayMicroseconds(sleepTime);

// 0 - 5V mapped to 0 - 1023 integer values

// recover voltage

calcVoltage = voMeasured * (5.0 / 1024.0);

// linear eqaution taken from Monitoring your Air Quality

// Chris Nafis (c) 2012

dustDensity = 0.17 * calcVoltage - 0.1;

Serial.print("Raw Signal Value (0-1023): ");

Serial.print(voMeasured);

Serial.print(" - Voltage: ");

Serial.print(calcVoltage);

Serial.print(" - Dust Density: ");

Serial.println(dustDensity); // unit: mg/m3

dustString="- Dust Density: "+String(dustDensity);

delay(1000);

/* Display the results (barometric pressure is measure in hPa) */

if (event.pressure)

{

/* Display atmospheric pressue in hPa */

String pressString = String(event.pressure);

Serial.print("Pressure: ");

Serial.print(pressString);

Serial.println(" hPa");

float temperature;

bmp.getTemperature(&temperature);

tempString = String(temperature);

Serial.print("Temperature: ");

Serial.print(tempString);

Serial.println(" C");

/* Then convert the atmospheric pressure, and SLP to altitude */

/* Update this next line with the current SLP for better results */

float seaLevelPressure = SENSORS_PRESSURE_SEALEVELHPA;

altiString = (bmp.pressureToAltitude(seaLevelPressure, event.pressure));

Serial.print("Altitude: ");

Serial.print(altiString);

Serial.println(" m");

Serial.println("");

dataString = altiString + ", " + pressString + ", " + tempString+", " +dustString;

/*file write init */

File dataFile = SD.open("data.txt", FILE_WRITE);

/*

파일 쓰기 프로세스

*/

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 data.txt");

}

}

else

{

Serial.println("Sensor error");

}

delay(1000);

}

I enter this code.When I see the Serial monitor dust measurement(+temperature measurement) is showed. But dust measurement is not saved in SD card(Sorry, I can't use English well,,,_)

I can't measure dust density

What does that mean exactly ?

For the sake of sanity here is the code formatted better and in code tags

#include <Wire.h>
#include <Adafruit_Sensor.h>
#include <Adafruit_BMP085_U.h>
#include <SPI.h>
#include <SD.h>
Adafruit_BMP085_Unified bmp = Adafruit_BMP085_Unified(10085);
const int chipSelect = 4;

/*
 Standalone Sketch to use with a Arduino UNO and a

 Sharp Optical Dust Sensor GP2Y1010AU0F

*/
int measurePin = 0; //Connect dust sensor to Arduino A0 pin
int ledPower = 2;   //Connect 3 led driver pins of dust sensor to Arduino D2
int samplingTime = 280;
int deltaTime = 40;
int sleepTime = 9680;
float voMeasured = 0;
float calcVoltage = 0;
float dustDensity = 0;

void displaySensorDetails(void)
{
  sensor_t sensor;
  bmp.getSensor(&sensor);
  Serial.println("------------------------------------");
  Serial.print ("Sensor: ");
  Serial.println(sensor.name);
  Serial.print ("Driver Ver: ");
  Serial.println(sensor.version);
  Serial.print ("Unique ID: ");
  Serial.println(sensor.sensor_id);
  Serial.print ("Max Value: ");
  Serial.print(sensor.max_value);
  Serial.println(" hPa");
  Serial.print ("Min Value: ");
  Serial.print(sensor.min_value);
  Serial.println(" hPa");
  Serial.print ("Resolution: ");
  Serial.print(sensor.resolution);
  Serial.println(" hPa");
  Serial.println("------------------------------------");
  Serial.println("");
  delay(500);
}

void setup(void)
{
  Serial.begin(9600);
  Serial.println("Pressure Sensor Test");
  Serial.println("");
  /* Initialise the sensor */
  if (!bmp.begin())
  {
    /* There was a problem detecting the BMP085 ... check your connections */
    Serial.print("Ooops, no BMP085 detected ... Check your wiring or I2C ADDR!");
    while (1);
  }
  if (!SD.begin(chipSelect))
  {
    Serial.println("Card failed, or not present");
    // don't do anything more:
    return;
  }
  Serial.println("card initialized.");
  /* Display some basic information on this sensor */
  displaySensorDetails();
  pinMode(ledPower, OUTPUT);
}

/**************************************************************************/

/*

Arduino loop function, called once 'setup' is complete (your own code

should go here)

*/

/**************************************************************************/

void loop(void)
{
  /* Get a new sensor event */
  sensors_event_t event;
  bmp.getEvent(&event);
  /* data type init */
  String dataString = "";
  String pressString = "";
  String altiString = "";
  String tempString = "";
  String dustString = "";
  digitalWrite(ledPower, LOW); // power on the LED
  delayMicroseconds(samplingTime);
  voMeasured = analogRead(measurePin); // read the dust value
  delayMicroseconds(deltaTime);
  digitalWrite(ledPower, HIGH); // turn the LED off
  delayMicroseconds(sleepTime);
  // 0 - 5V mapped to 0 - 1023 integer values
  // recover voltage
  calcVoltage = voMeasured * (5.0 / 1024.0);
  // linear eqaution taken from http://www.howmuchsnow.com/arduino/airquality/
  // Chris Nafis (c) 2012
  dustDensity = 0.17 * calcVoltage - 0.1;
  Serial.print("Raw Signal Value (0-1023): ");
  Serial.print(voMeasured);
  Serial.print(" - Voltage: ");
  Serial.print(calcVoltage);
  Serial.print(" - Dust Density: ");
  Serial.println(dustDensity); // unit: mg/m3
  dustString = "- Dust Density: " + String(dustDensity);
  delay(1000);
  /* Display the results (barometric pressure is measure in hPa) */
  if (event.pressure)
  {
    /* Display atmospheric pressue in hPa */
    String pressString = String(event.pressure);
    Serial.print("Pressure: ");
    Serial.print(pressString);
    Serial.println(" hPa");
    float temperature;
    bmp.getTemperature(&temperature);
    tempString = String(temperature);
    Serial.print("Temperature: ");
    Serial.print(tempString);
    Serial.println(" C");
    /* Then convert the atmospheric pressure, and SLP to altitude */
    /* Update this next line with the current SLP for better results */
    float seaLevelPressure = SENSORS_PRESSURE_SEALEVELHPA;
    altiString = (bmp.pressureToAltitude(seaLevelPressure, event.pressure));
    Serial.print("Altitude: ");
    Serial.print(altiString);
    Serial.println(" m");
    Serial.println("");
    dataString = altiString + ", " + pressString + ", " + tempString + ", " + dustString;
    /*file write init */
    File dataFile = SD.open("data.txt", FILE_WRITE);
    /*

      파일 쓰기 프로세스

    */
    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 data.txt");
    }
  }
  else
  {
    Serial.println("Sensor error");
  }
  delay(1000);
}

I really don't understand how anyone could work with it formatted as it was

Sorry, I can't use English well,,,_

Pretty

damned

good

at

using

the

Enter

key,

though.