loading

In this tutorial I make a temperature and light sensor data logger with an Arduino so that I can test different locations for plants or places to sleep outside in the summer that don't get to much sun

Step 1: Things You Will Need

1 Arduino board

1 Breadboard

1 Photoresistor

1 Temperature Sensor

1 SD Card

1 SD Card Reader

1 9v Battery

Jumper Wires

Step 2: Assembly

Hook up the SD card reader:

MOSI - pin 11

MISO - pin 12

CLK - pin 13

CS - pin 4

Gnd - Gnd

5v - 5v

3.3v - NOTHING

Other Gnd - Gnd

Photoresistor:

One end to 5v and the other end to pin2

after the cable to pin 2 there should be a resistor to gnd

Temperature Sensor:

Gnd - Gnd

Vin - 5v (it an also be to 3.3v but you will need to change the code)

Central Pin - Pin3

SD card:

Plug it in (:

Step 3: Code

/*
** MOSI - pin 11 ** MISO - pin 12 ** CLK - pin 13 ** CS - pin 4

*/

#include #include

#define PhotoresistorPin 2 #define TempPin 3 const int chipSelect = 4;

String FileName = "DataLog.txt";

long int LastLog;

void setup() { Serial.begin(9600);

pinMode(TempPin, INPUT); pinMode(PhotoresistorPin, INPUT); pinMode(13, OUTPUT);

Serial.print("Initializing SD card..."); // make sure that the default chip select pin is set to // output, even if you don't use it: pinMode(10, OUTPUT);

// see if the card is present and can be initialized: if (!SD.begin(chipSelect)) { Serial.println("Card failed, or not present");

//turns on the onboard led to signal that something is wrong digitalWrite(13,HIGH); // don't do anything more: return; }

Serial.print("Card initialized.");

}

void loop() {

//delays 10 minutes while (LastLog + 600000 > millis()) { delay(1000); }

int PhotoResistance = GetPhotoresistence(); float Temparature = GetTemperature(); LogData(PhotoResistance, Temparature); }

void LogData(int Resistance, int Temparature) { //the file you edit File dataFile;

dataFile = SD.open(FileName, FILE_WRITE);

dataFile.print("Minutes Running:"); dataFile.print(millis() / 60000); dataFile.print(" Photoresistor: "); dataFile.print(Resistance); dataFile.print(" Temparature: "); dataFile.print(Temparature); dataFile.println("C"); dataFile.close();

LastLog = millis(); }

float GetTemperature() {

float Temperature = analogRead(TempPin); Temperature = Temperature * 0.48828125; delay(1000); return Temperature; }

int GetPhotoresistence() {

int Photoresistence = analogRead(PhotoresistorPin); return Photoresistence; }

Step 4: Finished!!

Now just plug in the battery and it will start logging data!

About This Instructable

1,649views

34favorites

License:

More by Digital Explorer:Temperature And Light Sensor Data Logger Laser Controller 
Add instructable to: