ANALOG READ

Hi all
I m new here and I need some advices

I use this code on Arduino mega 2560 and 4 potentiometers isnteand of sensors but no return to 0 value

#include <Wire.h>

#include <LiquidCrystal_PCF8574.h>

LiquidCrystal_PCF8574 lcd(0x27); // set the LCD address to 0x27 for a 16 chars and 2 line display

int voltagePin = A0;
int curentPin = A1;
int weightPin = A2;
int presurePin = A3;
int voltageValue = 0;
int curentValue = 0;
int weightValue = 0;
int presureValue = 0;
int voltage = 0;
int curent = 0;
int weight = 0;
int presure = 0;

void setup()

{

Serial.begin(115200);
Serial.println(“LCD…”);
Wire.begin();
Wire.beginTransmission(0x27);
lcd.begin(20, 4); // initialize the lcd
lcd.setBacklight(255);
lcd.home();
lcd.clear();
lcd.print(“VOLTAGE”);
lcd.setCursor(0, 1);
lcd.print(“CURENT”);
lcd.setCursor(0, 2);
lcd.print(“WEIGHT”);
lcd.setCursor(0, 3);
lcd.print(“PRESURE”);

} // setup()

void loop()

{
voltageValue = analogRead(voltagePin);
voltage = (voltageValue / 2.045);
curentValue = analogRead(curentPin);
curent = (curentValue / 2.045);
weightValue = analogRead(weightPin);
weight = (weightValue / 2.045);
presureValue = analogRead(presurePin);
presure = (presureValue / 2.045);
lcd.setCursor(10, 0);
lcd.print(voltage);
lcd.setCursor(10, 1);
lcd.print(curent);
lcd.setCursor(10, 2);
lcd.print(weight);
lcd.setCursor(10, 3);
lcd.print(presure);

delay(300);
}

the lcd display is i2c bus

hope to some advices

Many thanks

Is there a question?

yes I asked for help but I changed some in cone and now more better

new code

#include <Wire.h>

#include <LiquidCrystal_PCF8574.h>

LiquidCrystal_PCF8574 lcd(0x27); // set the LCD address to 0x27 for a 16 chars and 2 line display

int voltagePin = A0;
int curentPin = A1;
int weightPin = A2;
int presurePin = A3;
float voltageValue = 0.000;
float curentValue = 0.000;
float weightValue = 0.000;
float presureValue = 0.000;
float voltage = 0.000;
float curent = 0.000;
float weight = 0.000;
float presure = 0.000;

void setup()

{

Serial.begin(115200);
Serial.println(“LCD…”);
Wire.begin();
Wire.beginTransmission(0x27);
lcd.begin(20, 4); // initialize the lcd
lcd.setBacklight(255);
lcd.home();
lcd.clear();
lcd.print(“VOLTAGE”);
lcd.setCursor(0, 1);
lcd.print(“CURENT”);
lcd.setCursor(0, 2);
lcd.print(“WEIGHT”);
lcd.setCursor(0, 3);
lcd.print(“PRESURE”);

} // setup()

void loop()

{
voltageValue = analogRead(voltagePin);
voltage = (voltageValue / 204.5);
curentValue = analogRead(curentPin);
curent = (curentValue / 204.5);
weightValue = analogRead(weightPin);
weight = (weightValue / 204.5);
presureValue = analogRead(presurePin);
presure = (presureValue / 204.5);
lcd.setCursor(10, 0);
lcd.print(voltage);
lcd.setCursor(10, 1);
lcd.print(curent);
lcd.setCursor(10, 2);
lcd.print(weight);
lcd.setCursor(10, 3);
lcd.print(presure);

delay(300);
}

Not sure what "more better" means (unless "more" means "way longer than it needs to be") but it would be helpful if you: a) told us what your problem is (assuming there is a problem) b) started using code tags when posting code.

the problem was I used integer value insteand of floating value and in integer value don't return to 0

voltageValue = analogRead(voltagePin); analogRead does not return a float.

Very few of your global variables need to be global. ( And those that do should be constants)

I agree but if you use as integer library fail trey my first code and tell me result I m a beginner in this area last working project done was 10 years ago in asm language but machine code hard but never fail

#include <Wire.h>

#include <LiquidCrystal_PCF8574.h>

LiquidCrystal_PCF8574 lcd(0x27);  // set the LCD address to 0x27 for a 16 chars and 2 line display

const byte voltagePin = A0;
const byte curentPin = A1;
const byte weightPin = A2;
const byte presurePin = A3;

void setup()
{
  Serial.begin(115200);
  Serial.println("LCD...");
  Wire.begin();
  Wire.beginTransmission(0x27);
  lcd.begin(20, 4); // initialize the lcd
  lcd.setBacklight(255);
  lcd.home();
  lcd.clear();
  lcd.print("VOLTAGE");
  lcd.setCursor(0, 1);
  lcd.print("CURENT");
  lcd.setCursor(0, 2);
  lcd.print("WEIGHT");
  lcd.setCursor(0, 3);
  lcd.print("PRESURE");
} // setup()

void loop()
{
  int voltageValue = analogRead(voltagePin);
  float voltage = (voltageValue / 204.5);
  int curentValue = analogRead(curentPin);
  float curent = (curentValue / 204.5);
  int weightValue = analogRead(weightPin);
  float weight = (weightValue / 204.5);
  int presureValue = analogRead(presurePin);
  flost presure = (presureValue / 204.5);
  lcd.setCursor(10, 0);
  lcd.print(voltage);
  lcd.setCursor(10, 1);
  lcd.print(curent);
  lcd.setCursor(10, 2);
  lcd.print(weight);
  lcd.setCursor(10, 3);
  lcd.print(presure);
 
  delay(300);
}

Uncompiled, untested (but simpler and shorter)

yes but if you don't use float return will be 5 volts if you use float will be 5.00 volts

georgegt: yes but if you don't use float return will be 5 volts if you use float will be 5.00 volts

There's a difference? :D (It's about using float appropriately)

georgegt: yes but if you don't use float return will be 5 volts if you use float will be 5.00 volts

Do you want to have it more preciese like 4,55V? the analog read is from 0 --> 1023 with an input read from 0--> 5V

so doing "the math" to calcultate the resolution is: 5/1023= 0,004887.... so for every analogRead, you read in a resolution of 0,004887... per step.

is this what you're looking for?

quick edit: implying this basic math in your code to get more precise results.

Hi, Welcome to the forum.

Please read the first post in any forum entitled how to use this forum. http://forum.arduino.cc/index.php/topic,148850.0.html then look down to item #7 about how to post your code. It will be formatted in a scrolling window that makes it easier to read.

Can you please post a copy of your circuit, in CAD or a picture of a hand drawn circuit in jpg, png?

Thanks.. Tom.. :)

Hi I solved 2 analog read and work well circuit is simple a0 a1 2 analog imput who reag 2 analog sensors but I tried to ad hx711 weight sensor and I must learn to use him and I need to ad an imput for TAR of the weight sensor This project must be a refrigerant recovery unit

Many thanks for all help