Pages: [1]   Go Down
Author Topic: 2 diffrent analog value influenced eachother  (Read 518 times)
0 Members and 1 Guest are viewing this topic.
Offline Offline
Newbie
*
Karma: 0
Posts: 46
I just want to learn more :)
View Profile
WWW
 Bigger Bigger  Smaller Smaller  Reset Reset

Hi,

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

Code:
#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.
Logged

Manchester (England England)
Offline Offline
Brattain Member
*****
Karma: 639
Posts: 34726
Solder is electric glue
View Profile
WWW
 Bigger Bigger  Smaller Smaller  Reset Reset

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.
Logged

Offline Offline
Newbie
*
Karma: 0
Posts: 46
I just want to learn more :)
View Profile
WWW
 Bigger Bigger  Smaller Smaller  Reset Reset

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.
Logged

Global Moderator
UK
Offline Offline
Brattain Member
*****
Karma: 310
Posts: 26637
I don't think you connected the grounds, Dave.
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

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.
Logged

"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.

Manchester (England England)
Offline Offline
Brattain Member
*****
Karma: 639
Posts: 34726
Solder is electric glue
View Profile
WWW
 Bigger Bigger  Smaller Smaller  Reset Reset

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.
Logged

UK
Offline Offline
Shannon Member
****
Karma: 223
Posts: 12630
-
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

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.
Logged

I only provide help via the forum - please do not contact me for private consultancy.

Offline Offline
Newbie
*
Karma: 0
Posts: 46
I just want to learn more :)
View Profile
WWW
 Bigger Bigger  Smaller Smaller  Reset Reset

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.
Logged

Global Moderator
UK
Offline Offline
Brattain Member
*****
Karma: 310
Posts: 26637
I don't think you connected the grounds, Dave.
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

Code:
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);
  }
}
« Last Edit: September 06, 2013, 02:42:10 pm by AWOL » Logged

"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.

Offline Offline
Newbie
*
Karma: 0
Posts: 46
I just want to learn more :)
View Profile
WWW
 Bigger Bigger  Smaller Smaller  Reset Reset

When the temperature will be changed this has effect on the PAvalue.

When the PAvalue has changed, this has effect on the temperature.
« Last Edit: September 06, 2013, 02:42:10 pm by Midway » Logged

Offline Offline
Newbie
*
Karma: 0
Posts: 46
I just want to learn more :)
View Profile
WWW
 Bigger Bigger  Smaller Smaller  Reset Reset

problem Solved.

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

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

thanks all for the help.
Logged

Pages: [1]   Go Up
Jump to: