Go Down

Topic: horse power calculator (Read 616 times) previous topic - next topic

LandonW

Mar 17, 2017, 10:34 pm Last Edit: Mar 21, 2017, 03:48 am by Coding Badly
Looking for help writing a code to calculate and display a horse power calculation. This is the formula I need to use

 (analog1*200) * (analog2"*80) /700 =????    analog1 is 0-5 VDC... analog2 is mVdc.

The display does not match the math. its over double what it should be.

I used the example sketch for "hello world" to wire lcd

I built two variable voltage circuits to control the analog inputs.

Here's my code. Please help, I'm new to coding but not new to electrical/electronic theory/practice

Code: [Select]


/*
Trying to calculate horse power and display on lcd

 http://www.arduino.cc/en/Tutorial/LiquidCrystal
 */

// include the library code:
#include <LiquidCrystal.h>

// initialize the library with the numbers of the interface pins
LiquidCrystal lcd(12, 11, 5, 4, 3, 2);
 
  int  voltPin = A1;
  int mvoltPin = A7;
  int c = 200;
  int d = 80;
  int e = 700;
  float voltValue = 0;
  float mvoltValue = 0;
  float sum = ((voltValue*c*mvoltValue*d)/e);
void setup() {
  // set up the LCD's number of columns and rows:
  lcd.begin(16, 2);
  // Print a message to the LCD.
  lcd.print("Horse Power");
}


void loop()
{

  //(voltValue*c)*(mvoltValue*d)/e;
 
 // set the cursor to column 0, line 1
  // (note: line 1 is the second row, since counting begins with 0):
  lcd.setCursor(0,1);
  // horse power calculation
voltValue = analogRead (voltPin);
mvoltValue = analogRead (mvoltPin);
  lcd.print (voltValue*c)*(mvoltValue*d)/e;
  delay(1700);

return;
}



Moderator edit: [code] [/code] tags added.


Groove

Code: [Select]
lcd.print (voltValue*c)*(mvoltValue*d)/e;The compiler didn't like that line, did it?
Per Arduino ad Astra

LandonW

Actually it didn't give me any errors

jremington

Then you posted the wrong program. Post the entire program, using code tags.

If you don't know what those are, read and follow the directions in the "How to use this forum" post.

Groove

Actually it didn't give me any errors
I do believe you may be correct, but it still isn't semantically correct.
Per Arduino ad Astra

jremington

#5
Mar 17, 2017, 11:18 pm Last Edit: Mar 17, 2017, 11:18 pm by jremington
Quote
I do believe you may be correct, but it still isn't semantically correct.
Hmmm...

I don't have access to an Arduino to test, but perhaps this line:

Code: [Select]
lcd.print (voltValue*c)*(mvoltValue*d)/e;

is equivalent to multiplying the return value from lcd.print() by something, and ignoring the result:

Code: [Select]
((mvoltValue*d)/e)*lcd.print (voltValue*c);

Groove

Hmmm...

I don't have access to an Arduino to test, but perhaps this line:

Code: [Select]
lcd.print (voltValue*c)*(mvoltValue*d)/e;

is equivalent to multiplying the return value from lcd.print() by something, and ignoring the result:

Code: [Select]
((mvoltValue*d)/e)*lcd.print (voltValue*c);
Yup...that's what I read second time I looked at it.
Syntax correct, flakey semantics.
Per Arduino ad Astra

LandonW

I changed to the

 ((mvoltValue*d)/e)*lcd.print (voltValue*c);

still no change

Groove

I changed to the

 ((mvoltValue*d)/e)*lcd.print (voltValue*c);

still no change

No surprise there.
Per Arduino ad Astra

Grumpy_Mike

I changed to the

 ((mvoltValue*d)/e)*lcd.print (voltValue*c);

still no change

Funnest thing I have read all year.  :)  :)  :)

You rearrange something that is wrong into something that is equivalent and are surprised that it is still wrong.

Now if you still don't understand it is wrong after all you have been told, then say what you don't understand about what you have been told.

LandonW

any clue on how to make it calculate correctly??

Groove

The calculation is probably correct, it's just that you're not calculating what you think you are.
Code: [Select]
lcd.print ((voltValue*c)*(mvoltValue*d)/e);
Per Arduino ad Astra

LandonW

I've tried writing that way too. still doesn't add up like it should or like it does when done on a calculator

Groove

Throw in some float casts and see how things develop
Per Arduino ad Astra

TomGeorge

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.

Thanks.. Tom.. :)
Everything runs on smoke, let the smoke out, it stops running....

Go Up