Pages: [1]   Go Down
Author Topic: Having issues using an LDR and a Potentiomer for my AIr Conditioning System..  (Read 727 times)
0 Members and 1 Guest are viewing this topic.
Offline Offline
Jr. Member
**
Karma: 0
Posts: 51
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

Ok, i am currently having this problem right now. There are two tasks where it got my confused at some points. And they mention: -

[1] It should only work when the lights are on, using an LDR.
And

[2] Use a potentiometer as a calibration mechanism

Here is the code i've implemented for those tasks:

[1]:
Code:
const int ThermPin = A0;
const int LDRPin = A1;
const int PotentPin = A2;
const int SpeakerPin = 11;
const int ButtonPin = 6;
int ButtonState = 0;
const int FanPin = 5;
const int LEDPin1 = 2;
const int LEDPin2 = 3;
const int LEDPin3 = 4;



void setup(){
  Serial.begin(9600);
  pinMode(LDRPin,     INPUT);
  pinMode(ButtonPin,  INPUT);
  pinMode(LEDPin1,    OUTPUT);
  pinMode(LEDPin2,    OUTPUT);
  pinMode(LEDPin3,    OUTPUT);
  pinMode(SpeakerPin, OUTPUT);
  pinMode(FanPin,     OUTPUT);
}

int SteinHart_Celcs(int ThermPin){
   ButtonState = digitalRead(ButtonPin);
   int   SensorValue   = analogRead(ThermPin);
   int   LDRSensVal    = analogRead(LDRPin);
   int   PotentSensVal = analogRead(PotentPin);
   float C1 = 1.346e-03;
   float C2 = 2.309e-04;
   float C3 = 9.815e-08;
   float Rt = 10000.0;
   float logRt = log(((10240000/SensorValue) - Rt));
   float Temp = (1.0/(C1 + C2*logRt + C3*logRt*logRt*logRt));
   float Celcius = Temp - 273.15;
  if(Celcius >= 10 && Celcius <= 23){
     digitalWrite(LEDPin1,    HIGH);
     digitalWrite(LEDPin2,    LOW);
     digitalWrite(LEDPin3,    LOW);
     digitalWrite(SpeakerPin, LOW);
     digitalWrite(FanPin,     LOW);
      Serial.println("Status: Its COOOLD..D..D ");}
  if(Celcius >= 24 && Celcius <= 29){
     digitalWrite(LEDPin2,    HIGH);
     digitalWrite(LEDPin1,    LOW);
     digitalWrite(LEDPin3,    LOW);
     digitalWrite(SpeakerPin, LOW);
     digitalWrite(FanPin,     LOW);
      Serial.print("Status: Its WARM..OK ");}
  if(Celcius >= 30 && Celcius <= 40){
     digitalWrite(LEDPin3,    HIGH);
     digitalWrite(LEDPin1,    LOW);
     digitalWrite(LEDPin2,    LOW);
     digitalWrite(SpeakerPin, HIGH);
      Serial.print("Status: ITs HOT..SHUT THE SYSTEM DOWN...ASAP! " );}
  //if statement specifically made for the fan.
  if(Celcius >= 27 && Celcius <= 40){
     digitalWrite(FanPin,     HIGH);}
  //if statemewnt specifically made for the button reset sequence.
  if(ButtonState == HIGH){
    digitalWrite(SpeakerPin, LOW);}
  else{
    ButtonState = LOW;}
  //if statement made for the LDR.
  if(LDRSensVal <= 200 && LDRSensVal >= 0){
      digitalWrite(LEDPin1,    HIGH);
      digitalWrite(LEDPin2,    HIGH);
      digitalWrite(LEDPin3,    HIGH);}
  if(LDRSensVal <= 300 && LDRSensVal >= 220){
     digitalWrite(LEDPin1,    LOW);
     digitalWrite(LEDPin2,    LOW);    
     digitalWrite(LEDPin3,    HIGH);}
  if(LDRSensVal <= 400 && LDRSensVal >= 320){
     digitalWrite(LEDPin1,    LOW);
     digitalWrite(LEDPin2,    HIGH);    
     digitalWrite(LEDPin3,    LOW);}
  if(LDRSensVal <= 500 && LDRSensVal >= 420){
     digitalWrite(LEDPin1,    HIGH);
     digitalWrite(LEDPin2,    LOW);    
     digitalWrite(LEDPin3,    LOW);}
  if(LDRSensVal <= 600 && LDRSensVal >= 520){
     digitalWrite(LEDPin1,    LOW);
     digitalWrite(LEDPin2,    LOW);    
     digitalWrite(LEDPin3,    LOW);}
   Serial.print("LDRSensVal = ");
   Serial.print(LDRSensVal);
  //if statements made for the Potentiometer
  if (PotentSensVal <= 320 && PotentSensVal >= 11){
         digitalWrite(FanPin, LOW);}
  if (PotentSensVal <= 620 && PotentSensVal >= 321){
    digitalWrite(FanPin, HIGH);
      delay(1500);
    digitalWrite(FanPin, LOW);
     delay(1500);}      
  if (PotentSensVal <= 820 && PotentSensVal >= 621){
    digitalWrite(FanPin, HIGH);
     delay(600);
    digitalWrite(FanPin, LOW);
     delay(600);}  
  if (PotentSensVal <= 920 && PotentSensVal >= 821){
    digitalWrite(FanPin, HIGH);
     delay(400);
    digitalWrite(FanPin, LOW);
     delay(400);}    
  if (PotentSensVal <= 920 && PotentSensVal >= 821){
    digitalWrite(FanPin, HIGH);
      delay(200);
    digitalWrite(FanPin, LOW);
      delay(200);}  
  if (PotentSensVal <= 970 && PotentSensVal >= 921){  
    digitalWrite(FanPin, HIGH);}
   Serial.print("\t PotentSensVal = ");
   Serial.print(PotentSensVal);
  
   Serial.print("\t Celcius = ");
   Serial.print(Celcius);
   Serial.println(" C");

}
void loop(){
  SteinHart_Celcs(ThermPin);
   delay(100);
}
Making the system only works when the lights are on using the LDR.
« Last Edit: October 12, 2012, 11:21:40 pm by Jonraptor » Logged

Offline Offline
Jr. Member
**
Karma: 0
Posts: 51
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

[2]:

Code:
//My Global Variables
const int ThermPin   = A0;
const int LDRPin     = A1;
const int PotentPin  = A2;
const int SpeakerPin = 11;
const int ButtonPin  = 6;
const int ButtonPin1 = 7;
int ButtonState   = 0;
int ButtonState1  = 0;
const int FanPin  = 5;
const int LEDPin1 = 2;
const int LEDPin2 = 3;
const int LEDPin3 = 4;
const int rows = 10;
const int cols = 2;
int Table[rows][cols] ={   //col 0||col 1
                            { 25, 4470 }, //row 0
                            { 26, 4250 }, //row 1
                            { 27, 4030 }, //row 2
                            { 28, 3800 }, //row 3
                            { 29, 3530 }, //row 4
                            { 30, 3270 }, //row 5
                            { 31, 3200 }, //row 6
                            { 32, 3170 }, //row 7
                            { 33, 3100 }, //row 8
                            { 34, 3070 }  //row 9
                       };    
void setup(){
  Serial.begin(9600);
  pinMode(LDRPin,     INPUT);
  pinMode(ButtonPin,  INPUT);
  pinMode(ButtonPin1, INPUT);
  pinMode(LEDPin1,    OUTPUT);
  pinMode(LEDPin2,    OUTPUT);
  pinMode(LEDPin3,    OUTPUT);
  pinMode(SpeakerPin, OUTPUT);
  pinMode(FanPin,     OUTPUT);
}

int getTempLookUp(int ThermPin)
{
float Vin = 5.0;
float ThermResist = 0.0;
float R2 = 10000.0;
float SensorValue = 0.0;
float Vout = 0.0;
                        
  SensorValue = analogRead(ThermPin);
  Serial.println();
  Serial.print("LookupValue = ");
  Serial.print(SensorValue);
  
  Vout = (((SensorValue+1)*Vin)/1024.0);
  Serial.print("\t");
  Serial.print("\t Voltage = ");
  Serial.print(Vout);
  Serial.print(" V");
  
  ThermResist =((R2*Vin)/Vout)-R2;
  Serial.print("\t");
  Serial.print("\t Resistance = ");
  Serial.print(ThermResist);
  Serial.print(" Ohm");
}
int getTempCelc(int ThermPin)
{
  float Vin = 5.0;
  float ThermResist = 0.0;
  float R2 = 10000.0;
  float SensorValue = 0.0;
  float Vout = 0.0;
                        
  SensorValue = analogRead(ThermPin);
  
  Vout = (((SensorValue+1)*Vin)/1024.0);
  
  ThermResist =((R2*Vin)/Vout)-R2;
   for(int i; i<rows; i++){
   if(ThermResist >= Table[i+1][1] && ThermResist <= Table[i][1] ){
     Serial.println();
     Serial.print("Array_Celcius = ");
     Serial.print(Table[i][0]);
     Serial.print(" C");
     Serial.print("\t");}}
}

int getTempKelv(int ThermPin)
{
  float Vin = 5.0;
  float ThermResist = 0.0;
  float R2 = 10000.0;
  float SensorValue = 0.0;
  float Vout = 0.0;
                        
  SensorValue = analogRead(ThermPin);
  
  Vout = (((SensorValue+1)*Vin)/1024.0);
  ThermResist =((R2*Vin)/Vout)-R2;
  
  for(int i; i<rows; i++){
   if(ThermResist >= Table[i+1][1] && ThermResist <= Table[i][1] ){
     Serial.print("\t Array_Kelvins = ");
     Serial.print(Table[i][0] + 273.15);
     Serial.print(" K");
     Serial.print("\t");}}
}

int getTempFare(int ThermPin)
{
  float Vin = 5.0;
  float ThermResist = 0.0;
  float R2 = 10000.0;
  float SensorValue = 0.0;
  float Vout = 0.0;
                        
  SensorValue = analogRead(ThermPin);
  
  Vout = (((SensorValue+1)*Vin)/1024.0);
  ThermResist =((R2*Vin)/Vout)-R2;
  
  for(int i; i<rows; i++){
   if(ThermResist >= Table[i+1][1] && ThermResist <= Table[i][1] ){
     Serial.print(" Array_Farenheit = ");
     Serial.print(  (Table[i][0] *9.0)/ 5.0 +32.0);
     Serial.print(" F");
     Serial.println();}}  
}
//---------------------------------------------------------------------
//SteinHart's Style!
int SteinHart_Kelvs(int ThermPin){
   int   SensorValue = analogRead(ThermPin);
   float C1 = 1.346e-03;
   float C2 = 2.309e-04;
   float C3 = 9.815e-08;
   float Rt = 10000.0;                    
   float logRt = log(((10240000/SensorValue) - Rt));
   float Temp = (1.0/(C1 + C2*logRt + C3*logRt*logRt*logRt));
   Serial.print("SH_Kelvin = ");
   Serial.print(Temp);
   Serial.print(" K");}

int SteinHart_Celcs_1(int ThermPin){
   int   SensorValue = analogRead(ThermPin);
   float C1 = 1.346e-03;
   float C2 = 2.309e-04;
   float C3 = 9.815e-08;
   float Rt = 10000.0;
   float logRt = log(((10240000/SensorValue) - Rt));
   float Temp = (1.0/(C1 + C2*logRt + C3*logRt*logRt*logRt));
   float Celcius = Temp - 273.15;
   Serial.print("\t");
   Serial.print("\t SH_Celcius = ");
   Serial.print(Celcius);
   Serial.print(" C");}

int SteinHart_Faren(int ThermPin){
   int   SensorValue = analogRead(ThermPin);
   float C1 = 1.346e-03;
   float C2 = 2.309e-04;
   float C3 = 9.815e-08;
   float Rt = 10000.0;
   float logRt = log(((10240000/SensorValue) - Rt));
   float Temp = (1.0/(C1 + C2*logRt + C3*logRt*logRt*logRt));
   float Celcius = Temp - 273.15;
   float Farenheit = ((Celcius *9.0) /5.0 +32.0);
   Serial.print("\t");
   Serial.print("\t SH_Farenheit = ");
   Serial.print(Farenheit);
   Serial.println(" F");}
//---------------------------------------------------------------------
//The Rest of My Work...
int SteinHart_Celcs(int ThermPin){
   ButtonState  = digitalRead(ButtonPin);
   int   SensorValue   = analogRead(ThermPin);
   int   LDRSensVal    = analogRead(LDRPin);
   int   PotentSensVal = analogRead(PotentPin);
   float C1 = 1.346e-03;
   float C2 = 2.309e-04;
   float C3 = 9.815e-08;
   float Rt = 10000.0;
   float logRt = log(((10240000/SensorValue) - Rt));
   float Temp = (1.0/(C1 + C2*logRt + C3*logRt*logRt*logRt));
   float Celcius = Temp - 273.15;
  if(Celcius >= 10 && Celcius <= 23){
     digitalWrite(LEDPin1,    HIGH);
     digitalWrite(LEDPin2,    LOW);
     digitalWrite(LEDPin3,    LOW);
     digitalWrite(SpeakerPin, LOW);
     digitalWrite(FanPin,     LOW);
      Serial.println("Status: Its COOOLD..D..D ");}
  if(Celcius >= 24 && Celcius <= 29){
     digitalWrite(LEDPin2,    HIGH);
     digitalWrite(LEDPin1,    LOW);
     digitalWrite(LEDPin3,    LOW);
     digitalWrite(SpeakerPin, LOW);
     digitalWrite(FanPin,     LOW);
      Serial.print("Status: Its WARM..OK ");}
  if(Celcius >= 30 && Celcius <= 40){
     digitalWrite(LEDPin3,    HIGH);
     digitalWrite(LEDPin1,    LOW);
     digitalWrite(LEDPin2,    LOW);
     digitalWrite(SpeakerPin, HIGH);
      Serial.print("Status: ITs HOT..SHUT THE SYSTEM DOWN...ASAP! " );}
  //if statement specifically made for the fan.
  if(Celcius >= 27 && Celcius <= 40){
     digitalWrite(FanPin,     HIGH);}
  //if statemewnt specifically made for the button reset sequence.
  if(ButtonState == HIGH){
    digitalWrite(SpeakerPin, LOW);}
  else{
    ButtonState = LOW;}
  //if statement made for the LDR.
  if(LDRSensVal <= 200 && LDRSensVal >= 0){
      digitalWrite(LEDPin1,    HIGH);
      digitalWrite(LEDPin2,    HIGH);
      digitalWrite(LEDPin3,    HIGH);}
  if(LDRSensVal <= 300 && LDRSensVal >= 220){
     digitalWrite(LEDPin1,    LOW);
     digitalWrite(LEDPin2,    LOW);    
     digitalWrite(LEDPin3,    HIGH);}
  if(LDRSensVal <= 400 && LDRSensVal >= 320){
     digitalWrite(LEDPin1,    LOW);
     digitalWrite(LEDPin2,    HIGH);    
     digitalWrite(LEDPin3,    LOW);}
  if(LDRSensVal <= 500 && LDRSensVal >= 420){
     digitalWrite(LEDPin1,    HIGH);
     digitalWrite(LEDPin2,    LOW);    
     digitalWrite(LEDPin3,    LOW);}
  if(LDRSensVal <= 600 && LDRSensVal >= 520){
     digitalWrite(LEDPin1,    LOW);
     digitalWrite(LEDPin2,    LOW);    
     digitalWrite(LEDPin3,    LOW);}
   Serial.print("LDRSensVal = ");
   Serial.print(LDRSensVal);
  //if statements made for the Potentiometer
  if (PotentSensVal <= 320 && PotentSensVal >= 11){
         digitalWrite(FanPin, LOW);}
  if (PotentSensVal <= 620 && PotentSensVal >= 321){
    digitalWrite(FanPin, HIGH);
      delay(1500);
    digitalWrite(FanPin, LOW);
     delay(1500);}      
  if (PotentSensVal <= 820 && PotentSensVal >= 621){
    digitalWrite(FanPin, HIGH);
     delay(600);
    digitalWrite(FanPin, LOW);
     delay(600);}  
  if (PotentSensVal <= 920 && PotentSensVal >= 821){
    digitalWrite(FanPin, HIGH);
     delay(400);
    digitalWrite(FanPin, LOW);
     delay(400);}    
  if (PotentSensVal <= 920 && PotentSensVal >= 821){
    digitalWrite(FanPin, HIGH);
      delay(200);
    digitalWrite(FanPin, LOW);
      delay(200);}  
  if (PotentSensVal <= 970 && PotentSensVal >= 921){  
    digitalWrite(FanPin, HIGH);}
   Serial.print("\t PotentSensVal = ");
   Serial.print(PotentSensVal);
    
   Serial.print("\t Celcius = ");
   Serial.print(Celcius);
   Serial.println(" C");
}

void loop(){
  ButtonState1 = digitalRead(ButtonPin1);
  SteinHart_Celcs(ThermPin);
    //if Statements for the Array of buttons
   if(ButtonState1 == HIGH){
      getTempLookUp    (ThermPin);
      getTempCelc      (ThermPin);
      getTempKelv      (ThermPin);
      getTempFare      (ThermPin);
      SteinHart_Kelvs  (ThermPin);
      SteinHart_Celcs_1(ThermPin);  
      SteinHart_Faren  (ThermPin);
       delay(100);}
   else
      if(ButtonState1 == LOW){
        SteinHart_Celcs(ThermPin);}

   delay(100);
}
Would help a bit if you explain to me how the Potentiometer is used as a calibration mechanism.
« Last Edit: October 12, 2012, 11:21:51 pm by Jonraptor » Logged

'round the world...
Offline Offline
Faraday Member
**
Karma: 41
Posts: 3113
View Profile
WWW
 Bigger Bigger  Smaller Smaller  Reset Reset

LDR light dependant resistor, potmeter is a variable resistance... if you swap the LDR by a potmeter you can test the system without actually having to use light...

By getting the curve of the resistance/light of the LDR, you can then simulate with the potmeter any point of light based on the resistance. Thus testing the accuracy of your light measurement and control of the system.

By the way, all those floats... they could be moved into memory. smiley
Logged

Eu não sou o teu criado. Se respondo no fórum é para ajudar todos mediante a minha disponibilidade e disposição. Responder por mensagem pessoal iria contra o propósito do fórum e por isso evito-o.
Se realmente pretendes que eu te ajude por mensagem pessoal, então podemos chegar a um acordo e contrato onde me pagas pela ajuda que eu fornecer e poderás então definir os termos de confidencialidade do meu serviço. De forma contrária toda e qualquer ajuda que eu der tem de ser visível a todos os participantes do fórum (será boa ideia, veres o significado da palavra fórum).
Nota também que eu não me responsabilizo por parvoíces escritas neste espaço pelo que se vais seguir algo dito por mim, entende que o farás por tua conta e risco.

Dito isto, mensagens pessoais só se forem pessoais, ou seja, se já interagimos de alguma forma no passado ou se me pretendes convidar para uma churrascada com cerveja (paga por ti, obviamente).

Seattle, WA USA
Online Online
Brattain Member
*****
Karma: 551
Posts: 46218
Seattle, WA USA
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

Code:
  pinMode(LDRPin,     INPUT);
Analog pins are input only. So, pinMode affects digital pins only. This call is not necessary.

You've explained what the code should do. Now, what does it actually do? What is the problem that you need help with?
Logged

0
Online Online
Shannon Member
****
Karma: 162
Posts: 10475
Arduino rocks
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

Code:
  pinMode(LDRPin,     INPUT);
Analog pins are input only. So, pinMode affects digital pins only.

No, analog pins are usuable with digitalWrite() and pinMode()  - but with different pin numbers (use the aliases A0, A1 etc).

Quote
This call is not necessary.

Pins are set to INPUT at power up and reset, but adding the call _documents_ the pin use (and that it is used), so is usually good style.
Logged

[ I won't respond to messages, use the forum please ]

Seattle, WA USA
Online Online
Brattain Member
*****
Karma: 551
Posts: 46218
Seattle, WA USA
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

Quote
No, analog pins are usuable with digitalWrite() and pinMode()  - but with different pin numbers (use the aliases A0, A1 etc).
Like this?
Code:
   int   LDRSensVal    = analogRead(LDRPin);

Clearly, the pin IS being used as an analog pin, which, by definition, is INPUT only. Telling a pin that can be a digital pin in either direction or an analog pin that can be input only, that is is an input pin WHEN IT IS USED AS AN ANALOG PIN is what is unnecessary.

The call only affects the mode of the pin WHEN IT IS USED AS A DIGITAL PIN. That is not the case here, so "documenting" some other potential (but never used) mode of the pin is NOT helpful.
Logged

Offline Offline
Jr. Member
**
Karma: 0
Posts: 51
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

I don't know why but. My LED keeps on blinking at some point...

Code(so far): -
Code:
//My Global Variables
const int ThermPin   = A0;
const int LDRPin     = A1;
const int PotentPin  = A2;
const int SpeakerPin = 11;
const int ButtonPin  = 6;
const int ButtonPin1 = 7;
int ButtonState   = 0;
int ButtonState1  = 0;
const int FanPin  = 5;
const int LEDPin1 = 2;
const int LEDPin2 = 3;
const int LEDPin3 = 4;
const int LEDPin4 = 8;
const int rows = 10;
const int cols = 2;
int Table[rows][cols] ={   //col 0||col 1
                            { 25, 4470 }, //row 0
                            { 26, 4250 }, //row 1
                            { 27, 4030 }, //row 2
                            { 28, 3800 }, //row 3
                            { 29, 3530 }, //row 4
                            { 30, 3270 }, //row 5
                            { 31, 3200 }, //row 6
                            { 32, 3170 }, //row 7
                            { 33, 3100 }, //row 8
                            { 34, 3070 }  //row 9
                       };    
void setup(){
  Serial.begin(9600);
  pinMode(ButtonPin,  INPUT);
  pinMode(ButtonPin1, INPUT);
  pinMode(LEDPin1,    OUTPUT);
  pinMode(LEDPin2,    OUTPUT);
  pinMode(LEDPin3,    OUTPUT);
  pinMode(LEDPin4,    OUTPUT);
  pinMode(SpeakerPin, OUTPUT);
  pinMode(FanPin,     OUTPUT);
}

int getTempLookUp(int ThermPin)
{
float Vin = 5.0;
float ThermResist = 0.0;
float R2 = 10000.0;
float SensorValue = 0.0;
float Vout = 0.0;
                        
  SensorValue = analogRead(ThermPin);
  Serial.println();
  Serial.print("LookupValue = ");
  Serial.print(SensorValue);
  
  Vout = (((SensorValue+1)*Vin)/1024.0);
  Serial.print("\t");
  Serial.print("\t Voltage = ");
  Serial.print(Vout);
  Serial.print(" V");
  
  ThermResist =((R2*Vin)/Vout)-R2;
  Serial.print("\t");
  Serial.print("\t Resistance = ");
  Serial.print(ThermResist);
  Serial.print(" Ohm");
  Serial.print("\t");
}
int getTempCelc(int ThermPin)
{
  float Vin = 5.0;
  float ThermResist = 0.0;
  float R2 = 10000.0;
  float SensorValue = 0.0;
  float Vout = 0.0;
                        
  SensorValue = analogRead(ThermPin);
  
  Vout = (((SensorValue+1)*Vin)/1024.0);
  
  ThermResist =((R2*Vin)/Vout)-R2;
   for(int i; i<rows; i++){
   if(ThermResist >= Table[i+1][1] && ThermResist <= Table[i][1] ){
     Serial.println();
     Serial.print("Array_Celcius = ");
     Serial.print(Table[i][0]);
     Serial.print(" C");
     Serial.print("\t");}}
}

int getTempKelv(int ThermPin)
{
  float Vin = 5.0;
  float ThermResist = 0.0;
  float R2 = 10000.0;
  float SensorValue = 0.0;
  float Vout = 0.0;
                        
  SensorValue = analogRead(ThermPin);
  
  Vout = (((SensorValue+1)*Vin)/1024.0);
  ThermResist =((R2*Vin)/Vout)-R2;
  
  for(int i; i<rows; i++){
   if(ThermResist >= Table[i+1][1] && ThermResist <= Table[i][1] ){
     Serial.print("\t Array_Kelvins = ");
     Serial.print(Table[i][0] + 273.15);
     Serial.print(" K");
     Serial.print("\t");}}
}

int getTempFare(int ThermPin)
{
  float Vin = 5.0;
  float ThermResist = 0.0;
  float R2 = 10000.0;
  float SensorValue = 0.0;
  float Vout = 0.0;
                        
  SensorValue = analogRead(ThermPin);
  
  Vout = (((SensorValue+1)*Vin)/1024.0);
  ThermResist =((R2*Vin)/Vout)-R2;
  
  for(int i; i<rows; i++){
   if(ThermResist >= Table[i+1][1] && ThermResist <= Table[i][1] ){
     Serial.print(" Array_Farenheit = ");
     Serial.print(  (Table[i][0] *9.0)/ 5.0 +32.0);
     Serial.print(" F");
     Serial.println();}}  
}
//---------------------------------------------------------------------
//SteinHart's Style!
int SteinHart_Kelvs(int ThermPin){
  int   SensorValue = analogRead(ThermPin);
  int   PotentSensVal = analogRead(PotentPin);  
   float C1 = 1.346e-03;
   float C2 = 2.309e-04;
   float C3 = 9.815e-08;
   float Rt = 10000.0;                    
   float logRt = log(((10240000/SensorValue) - Rt));
   float Temp = (1.0/(C1 + C2*logRt + C3*logRt*logRt*logRt));
   Serial.print("SH_Kelvin = ");
   Serial.print(Temp);
   Serial.print(" K");}

int SteinHart_Celcs_1(int ThermPin){
   int   SensorValue = analogRead(ThermPin);
   float C1 = 1.346e-03;
   float C2 = 2.309e-04;
   float C3 = 9.815e-08;
   float Rt = 10000.0;
   float logRt = log(((10240000/SensorValue) - Rt));
   float Temp = (1.0/(C1 + C2*logRt + C3*logRt*logRt*logRt));
   float Celcius = Temp - 273.15;
   Serial.print("\t");
   Serial.print("\t SH_Celcius = ");
   Serial.print(Celcius);
   Serial.print(" C");}

int SteinHart_Faren(int ThermPin){
   int   SensorValue = analogRead(ThermPin);
   float C1 = 1.346e-03;
   float C2 = 2.309e-04;
   float C3 = 9.815e-08;
   float Rt = 10000.0;
   float logRt = log(((10240000/SensorValue) - Rt));
   float Temp = (1.0/(C1 + C2*logRt + C3*logRt*logRt*logRt));
   float Celcius = Temp - 273.15;
   float Farenheit = ((Celcius *9.0) /5.0 +32.0);
   Serial.print("\t");
   Serial.print("\t SH_Farenheit = ");
   Serial.print(Farenheit);
   Serial.println(" F");}

Logged

Offline Offline
Jr. Member
**
Karma: 0
Posts: 51
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

Code:
//---------------------------------------------------------------------
//The Rest of My Work...
int SteinHart_Celcs(int ThermPin){
   ButtonState  = digitalRead(ButtonPin);
   int   SensorValue   = analogRead(ThermPin);
   int   LDRSensVal    = analogRead(LDRPin);
   int PotentSensVal   = analogRead(PotentPin);

   float C1 = 1.346e-03;
   float C2 = 2.309e-04;
   float C3 = 9.815e-08;
   float Rt = 10000.0;
   float logRt = log(((10240000/SensorValue) - Rt));
   float Temp = (1.0/(C1 + C2*logRt + C3*logRt*logRt*logRt));
   float Celcius = Temp - 273.15;
  if(Celcius >= 10 && Celcius <= 23){
     digitalWrite(LEDPin1,    HIGH);
     digitalWrite(LEDPin2,    LOW);
     digitalWrite(LEDPin3,    LOW);
     digitalWrite(SpeakerPin, LOW);
     digitalWrite(FanPin,     LOW);
      Serial.print("Status: Its COOOLD..D..D ");}
  if(Celcius >= 24 && Celcius <= 29){
     digitalWrite(LEDPin2,    HIGH);
     digitalWrite(LEDPin1,    LOW);
     digitalWrite(LEDPin3,    LOW);
     digitalWrite(SpeakerPin, LOW);
     digitalWrite(FanPin,     LOW);
      Serial.print("Status: Its WARM..OK ");}
  if(Celcius >= 30 && Celcius <= 100){
     digitalWrite(LEDPin3,    HIGH);
     digitalWrite(LEDPin1,    LOW);
     digitalWrite(LEDPin2,    LOW);
     digitalWrite(SpeakerPin, HIGH);
      Serial.print("Status: ITs HOT..SHUT THE SYSTEM DOWN...ASAP! " );}
  //if statement specifically made for the fan.
  if(Celcius >= 27 && Celcius <= 100){
     digitalWrite(FanPin,     HIGH);}
  //if statemewnt specifically made for the button reset sequence.
  if(ButtonState == HIGH){
    digitalWrite(SpeakerPin, LOW);}
  else{
    ButtonState = LOW;}
  //if statement made for the potentiometer

  //if statement made for the LDR.
    if(LDRSensVal <= 200 && LDRSensVal >= 0){
     digitalWrite(LEDPin1,    HIGH);
     digitalWrite(LEDPin2,    HIGH);
     digitalWrite(LEDPin3,    HIGH);}
  if(LDRSensVal <= 300 && LDRSensVal >= 220){
     digitalWrite(LEDPin1,    LOW);
     digitalWrite(LEDPin2,    LOW);
     digitalWrite(LEDPin3,    HIGH);}
  if(LDRSensVal <= 400 && LDRSensVal >= 320){
     digitalWrite(LEDPin1,    LOW);
     digitalWrite(LEDPin2,    HIGH);
     digitalWrite(LEDPin3,    LOW);}
  if(LDRSensVal <= 500 && LDRSensVal >= 420){
     digitalWrite(LEDPin1,    HIGH);
     digitalWrite(LEDPin2,    LOW);
     digitalWrite(LEDPin3,    LOW);}
  if(LDRSensVal <= 1023 && LDRSensVal >= 520){
     digitalWrite(LEDPin1,    LOW);
     digitalWrite(LEDPin2,    LOW);
     digitalWrite(LEDPin3,    LOW);}
   Serial.print("LDRValue = ");
   Serial.print(LDRSensVal);
   //if statement for the potentiometer   
    if(PotentSensVal <= 200 && PotentSensVal >= 0){
     digitalWrite(LEDPin1,    HIGH);
     digitalWrite(LEDPin2,    HIGH);
     digitalWrite(LEDPin3,    HIGH);}
  if(PotentSensVal <= 300 && PotentSensVal >= 220){
     digitalWrite(LEDPin1,    LOW);
     digitalWrite(LEDPin2,    LOW);
     digitalWrite(LEDPin3,    HIGH);}
  if(PotentSensVal <= 400 && PotentSensVal >= 320){
     digitalWrite(LEDPin1,    LOW);
     digitalWrite(LEDPin2,    HIGH);
     digitalWrite(LEDPin3,    LOW);}
  if(PotentSensVal <= 500 && PotentSensVal >= 420){
     digitalWrite(LEDPin1,    HIGH);
     digitalWrite(LEDPin2,    LOW);
     digitalWrite(LEDPin3,    LOW);}
  if(PotentSensVal <= 1023 && PotentSensVal >= 520){
     digitalWrite(LEDPin1,    LOW);
     digitalWrite(LEDPin2,    LOW);
     digitalWrite(LEDPin3,    LOW);}   
   Serial.print("\t Pot_LDRValue = ");
   Serial.print(PotentSensVal);
   
   Serial.print("\t ThermistorVal = ");
   Serial.print(SensorValue);
   Serial.print("\t Celcius = ");
   Serial.print(Celcius);
   Serial.println(" C");
}

void loop(){
  ButtonState1 = digitalRead(ButtonPin1);
  //if Statements for the Array of buttons
   if(ButtonState1 == HIGH){
      getTempLookUp    (ThermPin);
      getTempCelc      (ThermPin);
      getTempKelv      (ThermPin);
      getTempFare      (ThermPin);
      SteinHart_Kelvs  (ThermPin);
      SteinHart_Celcs_1(ThermPin); 
      SteinHart_Faren  (ThermPin);
       delay(10);}
   else{
    if(ButtonState1 == LOW){
       SteinHart_Celcs(ThermPin);}}
       
}
Logged

'round the world...
Offline Offline
Faraday Member
**
Karma: 41
Posts: 3113
View Profile
WWW
 Bigger Bigger  Smaller Smaller  Reset Reset

you have 4 LEDs...

you say My LED is blinking. Is that all of them?

I notice that when you activate teh LEDs, you also send some strings through the serial port... have you considered inspecting them to see what is happening?
Logged

Eu não sou o teu criado. Se respondo no fórum é para ajudar todos mediante a minha disponibilidade e disposição. Responder por mensagem pessoal iria contra o propósito do fórum e por isso evito-o.
Se realmente pretendes que eu te ajude por mensagem pessoal, então podemos chegar a um acordo e contrato onde me pagas pela ajuda que eu fornecer e poderás então definir os termos de confidencialidade do meu serviço. De forma contrária toda e qualquer ajuda que eu der tem de ser visível a todos os participantes do fórum (será boa ideia, veres o significado da palavra fórum).
Nota também que eu não me responsabilizo por parvoíces escritas neste espaço pelo que se vais seguir algo dito por mim, entende que o farás por tua conta e risco.

Dito isto, mensagens pessoais só se forem pessoais, ou seja, se já interagimos de alguma forma no passado ou se me pretendes convidar para uma churrascada com cerveja (paga por ti, obviamente).

Offline Offline
Jr. Member
**
Karma: 0
Posts: 51
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

you have 4 LEDs...

you say My LED is blinking. Is that all of them?

I notice that when you activate teh LEDs, you also send some strings through the serial port... have you considered inspecting them to see what is happening?
Well...it technically starts with the one of them. Based on the room temperature (e.g. if its 21 C or less, the green LED is lit. Otherwise, if its above 21 C the yellow LED goes on while the green LED turns off).
Yes i have. There don't seem to have any Delay statements around. Aside from the button press at the loop function...And the 4th LED doesn't concern me as much.
« Last Edit: October 14, 2012, 04:35:24 am by Jonraptor » Logged

Offline Offline
Jr. Member
**
Karma: 0
Posts: 51
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

I still need those serial printout statements to measure my LDR, Potentiometer and a Thermister all together....i couldn't just delete them just like that...
Logged

Seattle, WA USA
Online Online
Brattain Member
*****
Karma: 551
Posts: 46218
Seattle, WA USA
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

Please explain why you have 4 functions to get the temperature 4 different ways. The device you are using reports once value. Write one function to convert that value to a temperature in some scale. When you want the temperature in some other scale, call that one function and convert the temperature on one scale to the temperature on another scale.

Don't replicate code like that.
Logged

Pages: [1]   Go Up
Jump to: