Go Down

Topic: 0-5V linear sensors Display in percentage (Read 742 times) previous topic - next topic

00VIII


I have 2 sensors which are both 0-5V linear sensors.

I would like to display one of the readings as a percentage (0V=0% to 5V=100%)

The other i would like to display as a temperature. (0V= -40 to 5V= 125 °C)

Would like to display them on a LCD 16x2 display.

I am savvy with the wire up and connections however the programming behind this i cannot get my head around.

Any help/guidance would be appreciated.

PaulS

Quote
however the programming behind this i cannot get my head around.
What have you tried? What happened?

If you are looking for someone to write the code for you, this isn't the place. Gigs and Collaboration is. Expect this to be a paid gig.
The art of getting good answers lies in asking good questions.

UKHeliBob

Have you managed to display anything on the LCD ?
Post any code that you have tried, whether it worked or not.
Please do not send me PMs asking for help.  Post in the forum then everyone will benefit from seeing the questions and answers.

JimboZA

Leave the display out of it to start, and display the answers in the serial monitor for simplicity. Make sure your sums work, then you only have to deal with one type of problem at a time.

For the first part, take your reading which is between 0 and 1023, and divide by 1023 and times by 100; effectively divide by 10.23. That would be the percentage.

For the second one, have a look at the map() command.

Johannesburg hams call me: ZS6JMB on Highveld rep 145.7875 (-600 & 88.5 tone)
Dr Perry Cox: "Help me to help you, help me to help you...."
Your answer may already be here: https://forum.arduino.cc/index.php?topic=384198.0

00VIII

I certainly dont want this done for me as i wont learn that way.

For the second one, have a look at the map() command.

void loop()
{
  int val = analogRead(0);
  val = map(val, 0, 5, -40, 125);
}

From what i understand of the map function AnalogRead(0) is input A0 (sensor input)

and im telling it that the values it should expect is between 0 and 5V but i would like it displayed as -40 to 125

Will the LCD stage be where i assign what units it is in? Im used to using siemens plcs but this is very different in terms of language.

could i not do another map function for the percentage but 0-100 as the new low high?

AWOL

Quote
and im telling it that the values it should expect is between 0 and 5V but i would like it displayed as -40 to 125
Did you mean "the values it should expect is between 0 and 1023 " ?
"Pete, it's a fool (who) 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.
I speak for myself, not Arduino.

JimboZA

I'm not sure what you mean by assign its units, but yep at display time is where I'd display the units, just stick a "%" or whatever on the end.

Yep I'm sure you could use map to scale it from 0-100 as a %.
Johannesburg hams call me: ZS6JMB on Highveld rep 145.7875 (-600 & 88.5 tone)
Dr Perry Cox: "Help me to help you, help me to help you...."
Your answer may already be here: https://forum.arduino.cc/index.php?topic=384198.0

00VIII

Did you mean "the values it should expect is between 0 and 1023 " ?
Yes

I'm not sure what you mean by assign its units, but yep at display time is where I'd display the units, just stick a "%" or whatever on the end.

Yep I'm sure you could use map to scale it from 0-100 as a %.
exactly how you explained it, if i have the sensor input range changed to the numbers i want i can then add the units to the end of the string on the display.

So like you said % on the end of the 0-100 scaled input.

Ok i need to write this and check out how it reads.

Go Up