Adds

24 June 2015

Arduino with a thermistor and RGB LED - PLX-DAQ Excel spreadsheet

Code gets:

- Temperature from a thermistor

and

RGB LED changes colour depending on the Temperature

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  
 * RGB LED  
 * 3x 220 ohm resistors  
   
 - Gets Temperature form a Thermistor  
   
 - RGB LED changes colour depending on the Temperature   
   
 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 redPin = 11;  // Red Leg of LED,  connected to digital pin 11  
 int grnPin = 10; // Green Leg of LED, connected to digital pin 10  
 int bluPin = 9; // Blue Leg of LED, connected to digital pin 9  
   
 int ThermistorPin = A0;  // Thermistor Reading pin  
   
 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 measurement:");   // Printing Serial Monitor header    
  Serial.println("\n      Vo      Rt      T (C)");             
    
  pinMode(redPin, OUTPUT);  // Sets the LED pins as outputs  
  pinMode(grnPin, OUTPUT);  
  pinMode(bluPin, OUTPUT);  
          
 }  
   
 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 of 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(Vo);  // Printing data to Serial Monitor  
   
   
 Serial.print("     "); Serial.print(Rt);  
   
   
 Serial.print("     "); Serial.println(T);  
   
   
 // Setting the colours of the RGB LED based on temperature,  
 // Colour is shown for 0.1s before checking temperature again.  
   
 if(T >= 26.2)  
  {  
   digitalWrite(redPin, HIGH);  // red  
   delay(100);  
     
   digitalWrite(grnPin, LOW);  
   digitalWrite(bluPin, LOW);  
   
  }  
   
 if((T < 26) && (T >= 23.2))  
  {  
   digitalWrite(redPin, HIGH);  // yellow  
   digitalWrite(grnPin, HIGH);  
   delay(100);  
     
   digitalWrite(bluPin, LOW);  
   
  }  
    
  if((T < 23) && (T > 20.2))  
  {  
   digitalWrite(grnPin, HIGH);  // green  
   delay(100);  
     
   digitalWrite(redPin, LOW);  
   digitalWrite(bluPin, LOW);  
    
  }  
   
 if((T < 20) && (T > 17.2))  
  {  
   digitalWrite(grnPin, HIGH);  // aqua  
   digitalWrite(bluPin, HIGH);  
   delay(100);  
     
   digitalWrite(redPin, LOW);  
     
   
  }  
   
  if(T <= 17)  
  {  
   digitalWrite(bluPin, HIGH);  // blue  
   delay(100);  
     
   digitalWrite(grnPin, LOW);  
   digitalWrite(redPin, LOW);  
    
  }  
    
 row++;   // For PLX-DAQ  
 x++;   // For PLX-DAQ  
   
 delay(1000);   // Printing data once a second  
   
 }  

No comments:

Post a Comment