Go Down

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

TomGeorge

#15
Mar 18, 2017, 08:29 am Last Edit: Mar 18, 2017, 08:32 am by TomGeorge
Hi,
Try this;
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;
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... :)
Everything runs on smoke, let the smoke out, it stops running....

LandonW

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

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

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.

saximus

#18
Mar 21, 2017, 02:22 am Last Edit: Mar 21, 2017, 02:23 am by saximus
For those playing on phones and such:

Code: [Select]
/*
 *  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.

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.

el_supremo

Don't send me technical questions via Private Message.

Coding Badly


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


756E6C

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

Grumpy_Mike

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.

TomGeorge

#23
Mar 21, 2017, 10:29 am Last Edit: Mar 21, 2017, 10:55 am by TomGeorge
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.. :)
Everything runs on smoke, let the smoke out, it stops running....

LandonW

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.


Grumpy_Mike

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

This is why we ask you for a schematic.

TomGeorge

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

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

TomGeorge

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... :)
Everything runs on smoke, let the smoke out, it stops running....

Groove

#28
Mar 21, 2017, 08:54 pm Last Edit: Mar 21, 2017, 08:54 pm by Groove
Quote
So a single count = 5/1023
Strictly, that is 1024, but close enough.
Per Arduino ad Astra

Go Up