horse power calculator

LandonW:
I changed to the

((mvoltValue*d)/e)lcd.print (voltValuec);

still no change

No surprise there.

LandonW:
I changed to the

((mvoltValue*d)/e)lcd.print (voltValuec);

still no change

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

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.

any clue on how to make it calculate correctly??

The calculation is probably correct, it's just that you're not calculating what you think you are.lcd.print ((voltValue*c)*(mvoltValue*d)/e);

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

Throw in some float casts and see how things develop

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.. :slight_smile:

Hi,
Try this;

/*
  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;
float c = 200.0;
float d = 80.0;
float e = 700.0;
int voltValue;
int mvoltValue;
float sum;

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);
  lcd.print("        ");
  lcd.setCursor(0, 1);
  // horse power calculation
  voltValue = analogRead (voltPin);
  mvoltValue = analogRead (mvoltPin);
  sum = (((float)voltValue * c * (float)mvoltValue * d) / e);
  lcd.print (sum);
  delay(1700);
}

It compiles but I haven't run it.

Do not forget your analog values mvoltValue and voltValue will be from 0 to 1023, not the voltage on the input pin.

Tom... :slight_smile:

I'm trying to make calculations off of two analog inputs and for some reason the lcd print is way off.

my equation in (x200)(y*80)/700=? x = 0-5vdc y = mVdc

horsePWR_calculator.ino (1.88 KB)

And how big might y get? What types are x and y, and what type are you placing the result in? An Arduino's 'int' can only be as large as 32,767. After that, things get "interesting". You may need to define things as 'long', or do some strategic type-casting in your formula.

For those playing on phones and such:

/* 
 *  im using the arduino mega..
Trying to calculate horse power and display on lcd and turn on LED's depending on 
final calculation.

the forumla that i need is (x*200)*(y*80)/700

x<=5VDC  y=mVdc (both are on analog inputs)

for example (4vdc*200)*(32mVdc*80) / 700 = 3000

i built two variable voltage circuits to control analog inputs.
im using 4vdc and 70mVdc. the math shows about 6400. 
however the lcd is showing over 170,000
   
 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 ledG = 28;
  int ledY = 30;
  int ledR = 32;
  int voltPin = A1;
  int mvoltPin = A7;
  int c = 200;
  int d = 80;
  int e = 700;
  float voltValue= 0;
  float mvoltValue= 0;

void setup() {
  // set up the LCD's number of columns and rows:
  lcd.begin(16, 2);
  
  // Print a message to the LCD.
    lcd.print("    Welcome");
  delay(5000);


}



void loop()
{
/*  This note section is a copy paste area only, 
 *   its for different codes that i've tried.
  //(voltValue*c)*(mvoltValue*d)/(e); 
  */
   // set up the LCD's number of columns and rows:
  lcd.begin(16, 2);
  // Print a message to the LCD.
  
  lcd.print("Horse Power"); 
 // 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);


  pinMode (ledG, OUTPUT);
  pinMode (ledY, OUTPUT);
  pinMode (ledR, OUTPUT);
  
  
if 
  ( ((mvoltPin*d*voltPin*c)/e) >=2900);
  digitalWrite (ledG , HIGH);

if 
  ( ((mvoltPin*d*voltPin*c)/e) >=3050);
  digitalWrite (ledY , HIGH);

if
  ( ((mvoltPin*d*voltPin*c)/e) >=3150);
  digitalWrite (ledR , HIGH);
  

return;
}

analogRead() returns a value from 0-1023. You haven't converted x and y to the "real world" values that you are expecting them to be before doing your maths.

jaholmes:
And how big might y get? What types are x and y, and what type are you placing the result in? An Arduino's 'int' can only be as large as 32,767. After that, things get "interesting". You may need to define things as 'long', or do some strategic type-casting in your formula.

They are floats. It's right there in the code posted.

He's already asked this in horse power calculator - Programming Questions - Arduino Forum

Pete

@LandonW, do not cross-post. Threads merged.

If analog1 = 1 volt, what does that represent? If analog2 = 100mV, what does that represent?

756E6C:
If analog1 = 1 volt, what does that represent? If analog2 = 100mV, what does that represent?

If it is horse power then one must be a voltage and the other a current.

Hi,

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

What do the input values represent?
Can you give us an example of what two input values are and what the resulting "horsepower" should be?
In fact a couple of examples will be good.

Thanks.. Tom.. :slight_smile:

Tom,
the input voltages will be taken off test points on a locomotive high voltage system.

the volts on the locomotive will go up to 1000VDC but I built a voltage drop circuit to make it a 5 volt max to the Arduino. (hints the *200 for volts)

the millivolt reading is taken off a high voltage shunt on the locomotive where the spec for that is 1mVdc across the shunt = 80 amps. usually maxing at 40mV off the shunt.

so essentially I'm trying to find HP from the watts by /700, in know its supposed to be 746 but the railroad world uses 700.

since I don't have access to a locomotive at home, I built two voltage reduction circuits starting with 5vdc and using pots and resistors.
A1 receiving 4vdc and A7 receiving about 50mVdc.

Do these two voltages have a common reference point? Are they isolated?

This is why we ask you for a schematic.

Hi,
As Grumpy_Mike has pointed out, a schematic is very important.
Especially the mV shunt connection due to gnd considerations.

Tom... :slight_smile:

Hi,
Do you have an amplifier on the shunt?
Some simple maths.
Analog input maximum is 5V this is represented by a count of 1023 from the Arduino AtoD.
So a single count = 5/1023 = 0.0048Volts = 4.8mV

So 1 count = 4.8 * 80 = 391A though the shunt.

This means you have a current resolution of 391A. Not particularly good.
That is you are measuring current in 391A steps, in fact under 391A will be zero current as far as the Arduino is concerned.

You need to amplify the mV signal to Volts to get decent resolution and hence power readings.
Is this a commercial or industrial application, you can get converters the can convert mV to Volts and provide isolation between the shunt and Arduino.

I am using a converter currently in the development of a 4000A injection test jig for railway circuit breakers, 75mA = 2000A shunt.

Tom... :slight_smile: