pentiumcadiz
Created April 14, 2016 © GPL3+

Temperature logger

3-probe temperature microSD logger

IntermediateFull instructions provided894
Temperature logger

Things used in this project

Hardware components

Arduino Nano R3
Arduino Nano R3
×1
Temperature Sensor
Temperature Sensor
×3
catalex microSD adapter
×1

Story

Read more

Schematics

Schematics

How to connect all the components

Code

Temp_logger

Arduino
Captura de temperaturas a tarjeta microSD
/*
  Triple sensor de temperatura con almacenamiento de datos en microSD
  Developed by PentiumCadiz - dic2014
  Based on "SD card read/write", created by David A. Mellis and
modified by Tom Igoe
  This code is in the public domain.

 microSD card attached to SPI bus as follows:
 ** MOSI - pin 11
 ** MISO - pin 12
 ** CLK - pin 13
 ** CS - pin 10

 */

 // include the SD library:
#include <SD.h>

File logfile;  // Fichero de log de las temperaturas

const int chipSelect = 10;    // Funciona Ok con tarjeta micro SD
Catalex dic2014

// Pines sensores de tenp (TMP36)
int tempM = 1;  //entrada temperatura del motor. Pin analógico A0 al
sensor TMP36
int tempV = 3; // entrada temperatura del Variador
int tempB = 5; // entrada temperatura de la Batería

// Medición de la temperatura
float voltajeM, gradosM;
// variables tipo float para guardar los valores de lectura de los sensores
float voltajeV, gradosV, voltajeB, gradosB;

boolean unavez = true;

//  -------  Fin de declaración de variables -----------

void setup()
{
 // Open serial communications and wait for port to open:
  Serial.begin(9600);
   while (!Serial) {
    ; // wait for serial port to connect. Needed for Leonardo only
  }

  Serial.print("Initializing SD card...");
  // On the Ethernet Shield, CS is pin 4. It's set as an output by default.
  // Note that even if it's not used as the CS pin, the hardware SS pin
  // (10 on most Arduino boards, 53 on the Mega) must be left as an output
  // or the SD library functions will not work.
   pinMode(10, OUTPUT);

 // See if the card is present and can be initialized:
  if (!SD.begin(chipSelect)) {
    Serial.println("initialization failed!");
    return;
  }
  Serial.println("initialization done.");

// Asignación de pines digitales a Vcc y Gnd

// pin D2 a tierra (0v)
  pinMode(2, OUTPUT);
  digitalWrite(2, LOW);

// pin D4 a tierra (0v)
  pinMode(4, OUTPUT);
  digitalWrite(4, LOW);

// pin D6 a tierra (0v)
  pinMode(6, OUTPUT);
  digitalWrite(6, LOW);

}

void loop(void) {

 // Convertir el valor que nos devuelve el analogRead(n), comprendido
entre 0 y 1023,
 // a un valor comprendido entre los 0.0 y los 5.0 voltios
  voltajeM = analogRead(tempM) * 0.004882814;
  voltajeV = analogRead(tempV) * 0.004882814;
  voltajeB = analogRead(tempB) * 0.004882814;

// Fórmula del datasheet para convertir el valor del voltaje a grados
centigrados
  gradosM = (voltajeM - 0.5) * 100.0;
  gradosV = (voltajeV - 0.5) * 100.0;
  gradosB = (voltajeB - 0.5) * 100.0;

if (unavez)
{
    Serial.print("Medidas actuales\n");
}

 //Mostramos mensaje con las temperaturas
  Serial.print("Motor: ");
  Serial.print(gradosM);
  Serial.print("\t\tVariador: ");
  Serial.print(gradosV);
  Serial.print("\t\tBatería: ");
  Serial.println(gradosB);

  // Grabar los datos leidos en la tarjeta

// Open the file.
  File logFile = SD.open("temp.log", FILE_WRITE);
  if (logFile)
  {
if (unavez)
{
    logFile.println("Grabando Medidas actuales ********************\n");
}
   logFile.print(gradosM);
   logFile.print("\t");
   logFile.print(gradosV);
   logFile.print("\t");
   logFile.println(gradosB);
   // close the file:
   logFile.close();
  }
  else {
    // if the file didn't open, print an error:
    Serial.println("error opening temp.log");
  }
  delay(3000);  //Usamos un retardo de 3 segundos entre lectura y lectura
  unavez = false;

}

Credits

pentiumcadiz
2 projects • 7 followers
Software professional. Hardware enthusiast.
Contact

Comments

Please log in or sign up to comment.