Adds

24 June 2015

Arduino with a thermistor and LDR to get temperature and light value - prints data to PLX-DAQ Excel spreadsheet

Code gets:

- Temperature from a thermistor

- Light value from an LDR

and

Prints the data to the Serial Monitor

Data is sent to an Excel spreadsheet through data acquisition software, PLX-DAQ, Download here


Please let me know if you experience any problems with this code. Be sure to check back for more Arduino code.

Schematic:



Code:


 /*  
   
 Oliver Holden  
 Created 28/10/2014  
   
 Components:  
 * Arduino UNO  
 * Thermistor  
 * 10K resistor  
 * LDR  
 * 10K resistor  
   
 - Gets Temperature form a Thermistor  
   
 - Gets an analogue value of Light from an LDR  
   
 Prints the data to the Serial Monitor  
 Data is sent to an Excel spreadsheet through data   
 acquisition software, PLX-DAQ, Download http://www.parallax.com/downloads/plx-daq  
   
 Schematic for this project is on  
 http://breadboarder.blogspot.co.uk/  
   
 */  
   
 int ThermistorPin = A0;  // Thermistor Reading pin  
 int LDRPin= A2;   // LDR Reading pin  
   
 int LDRReading = analogRead(LDRPin);   // Reading LDR analogue value  
   
 int x = 0;   // For PLX-DAQ  
 int row = 0;   // For PLX-DAQ  
   
   
 void setup()  
 {  
   Serial.begin(9600);   // Opening serial connection at 9600bps  
  Serial.println("Thermistor temperature and LDR light measurement:");   // Printing Serial Monitor header  
  Serial.println("LABEL, Time, T (C), LDR");   // Setting headers of colums in PLX-DAQ spreadsheet  
  Serial.println("\n-----------------------------");  
          
 }  
   
 void loop() {  
    
 int Vo;   // Integer value of voltage reading  
   
 float R = 9870.0;   // Fixed resistance in the voltage divider  
 float logRt,Rt,T;  
 float c1 = 1.009249522e-03, c2 = 2.378405444e-04, c3 = 2.019202697e-07;  
   
 Vo = analogRead(ThermistorPin);   // Reading voltage Thermistor Reading pin  
   
 Rt = R*( 1023.0 / (float)Vo - 1.0 );  
   
 logRt = log(Rt);  
   
 T = ( 1.0 / (c1 + c2*logRt + c3*logRt*logRt*logRt ) ) - 273.15;   // Converting voltage to temperature  
   
 Serial.print("     "); Serial.print(T);  // Printing data to Serial Monitor  
   
   
 Serial.print("     "); Serial.print(LDRReading);  
   
  row++;   // For PLX-DAQ  
  x++;   // For PLX-DAQ  
    
  delay(1000);   // Printing data once a second  
   
 }  

No comments:

Post a Comment