Go Down

Topic: 2 diffrent analog value influenced eachother (Read 566 times) previous topic - next topic

Midway

Hi,

When I integrate the PAvalue it will influenced the Temp / Fan control.

Code: [Select]
#include <LiquidCrystal.h>
 
  float Voltage;
  float TempC;
 

  int FAN = 9;                            // FAN Optocoupler (CNY74-2) connected to digital PWM pin 9
  int Temperature;
  int PAvalue;
// int PAvalue = 0;

 const int PA = 2;                       // analog channel 2 (PA signal Input).
 const int LM35 = 0;                     // analog channel 0 (LM35CZ).
 const int LowTemp = 30;                 // Setting LOW Temperature setpoint. The Fan reach full speed then temperature is more than 10°C above setpoint.

LiquidCrystal lcd(12, 11, 5, 4, 3, 2);    // lcd naar Digital pin (4=2,6=3,11=4,12=5,13=6,14=7) (lcd header "gnd" = 1,(3),5,16) and (lcd header "+5 volt" = 2,15)

 
void setup()
{
   lcd.begin(16,2);
   pinMode(FAN, OUTPUT);                 // Set pin for output to control FAN Optocoupler.
}
void loop()
{
   Temperature = analogRead(LM35);                         // read the value from the LM35 sensor
   Voltage = Temperature * (5.0/1024);                     // convert reading to voltage (in V), for 5V input
   TempC = ( 5.0 * Temperature * 100.0) / 1024.0;          // convert voltage to temperature

   lcd.setCursor(0,1);
   lcd.print(TempC);                                       // Print Celsius temperature to LCD
   lcd.print((char)223);                                   // degree symbol
   lcd.print("C ");

   analogWrite(FAN, constrain( (TempC - LowTemp) * 25, 0, 255));   // If the temperature is highher than the set point, run the fans.
{
}
   PAvalue = analogRead(PA);                               // read the value from the PA output driver.
   float PAVin = PAvalue * (4.5 / 1024.0);

   if (PAVin>4)
{
   lcd.setCursor(8, 0);
   lcd.print("10");
}
  else
   if (PAVin>3 && PAVin<4)
{
   lcd.setCursor(8, 0);
   lcd.print(" 8");
}
  else
   if (PAVin>2 && PAVin<3)
{
   lcd.setCursor(8, 0);
   lcd.print(" 6");
}
  else
   if (PAVin>1 && PAVin<2)
{
   lcd.setCursor(8, 0);
   lcd.print(" 4");
}
  else
   if (PAVin>0.5 && PAVin<1)
{
   lcd.setCursor(8, 0);
   lcd.print(" 3");
}
  else
   if (PAVin>0 && PAVin<0.5)
{
   lcd.setCursor(8, 0);
   lcd.print(" 2");
}
{
   lcd.setCursor(0, 0);
   lcd.print("Output:");
   lcd.setCursor(11, 0);
   lcd.print("Watt");
   lcd.setCursor(10, 1);
   lcd.print(PAVin);
   lcd.setCursor(15, 1);
   lcd.print("V");
}
}


Do i forget something?

Any help will appriciate.

Thanks
Ed.

Grumpy_Mike

Quote
Do i forget something?

You forgot to include a schematic. This is basically a hardware problem. You might be able to solve it by taking two readings and just using the second one.

Midway

Hi,

For each analog input I use for example a 10K potentiometer.
From each potentiometer i receive a value from 0Vdc to 5Vdc

The problem is, when i adjust one of them, it affects the other value.

Ed.

AWOL

Take a reading and discard the cvalue.
Read the same input again and use that value.

What's with the crazy code format?
Using the auto format tool will make things easier to read.
"Pete, it's a fool looks for logic in the chambers of the human heart." Ulysses Everett McGill.
Do not send technical questions via personal messaging - they will be ignored.

Grumpy_Mike

Quote
The problem is, when i adjust one of them, it affects the other value.

So the problem is that you have wired it wrong. Using 10K pots will not affect each other unless you have bad wiring, like long ground connections.

PeterH


When I integrate the PAvalue it will influenced the Temp / Fan control.


Are you sure it's affecting the actual reading, rather than just corrupting the LCD display? You are moving the cursor around and writing values to various parts of the display and it seems to me that changes to that logic might cause unexpected output on the LCD. I suggest you print out the raw and calculated values and check whether they are actually going wrong.
I only provide help via the forum - please do not contact me for private consultancy.

Midway

Hi PeterH,

Thanks for the good question.

Quote
Are you sure it's affecting the actual reading

Yes, Im sure.

U can test very easely, just Upload the sketch and put 2 potentiometers on the analog input.
When u adjust 1 of them it affect the other.

Im pretty sure that i have written the sketch well.


thanks for the help so far.

Ed.

AWOL

#7
Sep 06, 2013, 10:00 am Last Edit: Sep 06, 2013, 09:42 pm by AWOL Reason: 1
Code: [Select]

const byte analogPin [2] = {0, 2};  // adjust as necessary
void setup ()
{
 Serial.begin (115200);
}

void loop ()
{
 for (int i = 0; i < 2; i++)
 {
   int val = analogRead (analogPin [i]);
   // val = analogRead (analogPin [i]);  // try un-commenting this line and see if it makes a difference
   Serial.print ("Channel ");
   Serial.print (analogPin []);
   Serial.print (" ");
   Serial.println(val);
 }
}
"Pete, it's a fool looks for logic in the chambers of the human heart." Ulysses Everett McGill.
Do not send technical questions via personal messaging - they will be ignored.

Midway

#8
Sep 06, 2013, 09:01 pm Last Edit: Sep 06, 2013, 09:42 pm by Midway Reason: 1
When the temperature will be changed this has effect on the PAvalue.

When the PAvalue has changed, this has effect on the temperature.

Midway

problem Solved.

solution;
Code: [Select]
  Temperature = analogRead(LM35);                         // 1st read the value DUMMY
  Temperature = analogRead(LM35);                         // read the value from the LM35 sensor


and:
Code: [Select]
  PAvalue = analogRead(PA);                               // 1st read the value DUMMY
  PAvalue = analogRead(PA);                               // read the value from the PA output driver.


thanks all for the help.

Go Up