Micro SD breakout board

I am trying to collect data from a AM2315 humidity sensor (https://www.adafruit.com/products/1293) to my SD card and then from there to my computer. Everything seems to be working but the data that goes on the SD card is not the right numbers. Thank you for any help

This is the code I’m using:

[code]
/* Example sketch for AM2315 humidity - temperature sensor
Written by cactus.io, and requires the cactus_io_AM2315 library. public domain
This sketch will work with the Adafruit AM2315 sensor.
For hookup details using this sensor then visit
Hookup | Code | Arduino to AM2315 Temperature - Humidity Sensor Tutorial
*/

#include <Wire.h>
#include “cactus_io_AM2315.h”

AM2315 am2315;

#include <SPI.h>
#include <SD.h>

const int chipSelect = 10;

void setup() {
Serial.begin(9600);
Serial.println(“AM2315 Humidity - Temperature Sensor”);
Serial.println(“RH\t\tTemp (C)\tTemp (F)”);

if (!am2315.begin()) {
Serial.println(“Sensor not found, check wiring”);
while (1);
}
// Open serial communications and wait for port to open:
Serial.begin(9600);
while (!Serial) {
; // wait for serial port to connect. Needed for native USB port only
}

Serial.print(“Initializing SD card…”);

// see if the card is present and can be initialized:
if (!SD.begin(chipSelect)) {
Serial.println(“Card failed, or not present”);
// don’t do anything more:
return;
}
Serial.println(“card initialized.”);

}

void loop() {

am2315.readSensor();

Serial.print(am2315.getHumidity()); Serial.print(" %\t\t");
Serial.print(am2315.getTemperature_C()); Serial.print(" *C\t");
Serial.print(am2315.getTemperature_F()); Serial.println(" *F\t");

// Add a 2 second
delay(1500);

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

// read three sensors and append to the string:
for (int analogPin = 0; analogPin < 3; analogPin++) {
int sensor = analogRead(analogPin);
dataString += String(sensor);
if (analogPin < 2) {
dataString += “,”;
}
}

// 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”);
}

}

[code]

I also attached the images of the serial monitor screen and then the data that goes to the SD card. Thank you.

GabrielPierre:
I am trying to collect data from a AM2315 humidity sensor (https://www.adafruit.com/products/1293) to my SD card and then from there to my computer. Everything seems to be working but the data that goes on the SD card is not the right numbers. Thank you for any help

This is the code I’m using:

/* Example sketch for AM2315 humidity - temperature sensor

Written by cactus.io, and requires the cactus_io_AM2315 library. public domain
  This sketch will work with the Adafruit AM2315 sensor.
  For hookup details using this sensor then visit
  Hookup | Code | Arduino to AM2315 Temperature - Humidity Sensor Tutorial
*/

#include <Wire.h>
#include “cactus_io_AM2315.h”

AM2315 am2315;

#include <SPI.h>
#include <SD.h>

const int chipSelect = 10;

void setup() {
 Serial.begin(9600);
 Serial.println(“AM2315 Humidity - Temperature Sensor”);
 Serial.println(“RH\t\tTemp (C)\tTemp (F)”);

if (!am2315.begin()) {
    Serial.println(“Sensor not found, check wiring”);
    while (1);
 }
// Open serial communications and wait for port to open:
 Serial.begin(9600);
 while (!Serial) {
   ; // wait for serial port to connect. Needed for native USB port only
 }

Serial.print(“Initializing SD card…”);

// see if the card is present and can be initialized:
 if (!SD.begin(chipSelect)) {
   Serial.println(“Card failed, or not present”);
   // don’t do anything more:
   return;
 }
 Serial.println(“card initialized.”);

}

void loop() {
 
 am2315.readSensor();
 
 Serial.print(am2315.getHumidity()); Serial.print(" %\t\t");
 Serial.print(am2315.getTemperature_C()); Serial.print(" *C\t");
 Serial.print(am2315.getTemperature_F()); Serial.println(" *F\t");

// Add a 2 second
 delay(1500);

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

// read three sensors and append to the string:
 for (int analogPin = 0; analogPin < 3; analogPin++) {
   int sensor = analogRead(analogPin);
   dataString += String(sensor);
   if (analogPin < 2) {
     dataString += “,”;
   }
 }

// 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”);
 }

}




I also attached the images of the serial monitor screen and then the data that goes to the SD card. Thank you.

The output you appended is not from this sketch. Your output shows “Initializing SD card…” before “AM2315 Humidity - Temperature Sensor”.

Post matching code.

Chuck.

P.S. use [ code ] [ /code] (without any spaces inside the braces )