Arduino Forum

Using Arduino => Programming Questions => Topic started by: 00VIII on Apr 22, 2015, 12:47 pm

Title: 0-5V linear sensors Display in percentage
Post by: 00VIII on Apr 22, 2015, 12:47 pm

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.
Title: Re: 0-5V linear sensors Display in percentage
Post by: PaulS on Apr 22, 2015, 12:51 pm
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.
Title: Re: 0-5V linear sensors Display in percentage
Post by: UKHeliBob on Apr 22, 2015, 01:09 pm
Have you managed to display anything on the LCD ?
Post any code that you have tried, whether it worked or not.
Title: Re: 0-5V linear sensors Display in percentage
Post by: JimboZA on Apr 22, 2015, 01:29 pm
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() (http://www.arduino.cc/en/Reference/Map) command.

Title: Re: 0-5V linear sensors Display in percentage
Post by: 00VIII on Apr 22, 2015, 01:44 pm
I certainly dont want this done for me as i wont learn that way.

For the second one, have a look at the map() (http://www.arduino.cc/en/Reference/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?
Title: Re: 0-5V linear sensors Display in percentage
Post by: AWOL on Apr 22, 2015, 01:52 pm
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 " ?
Title: Re: 0-5V linear sensors Display in percentage
Post by: JimboZA on Apr 22, 2015, 01:53 pm
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 %.
Title: Re: 0-5V linear sensors Display in percentage
Post by: 00VIII on Apr 22, 2015, 02:00 pm
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.