When i try to change the callibration factor, the torque wont show on my lcd.
Code:
#include <LiquidCrystal.h>
LiquidCrystal lcd(8, 9, 4, 5, 6, 7);
#include "HX711.h"
#define calibration_factor 2150.0 //This value is obtained using the SparkFun_HX711_Calibration sketch
#define DOUT 26
#define CLK 27
HX711 scale(DOUT, CLK);
const int irPin = A8;
int triggers = 0;
unsigned long elapsedTime;
int laststate =0;
const unsigned long sampleTime = 1000;
int rpmMax=0;
void setup()
{
lcd.begin(16, 2); // start the library
lcd.setCursor(0,0);
lcd.print("MaxRpm:");
lcd.setCursor(0,1);
lcd.print("Torque:");
pinMode(irPin, INPUT);
Serial.begin(9600);
scale.set_scale(calibration_factor); //This value is obtained by using the SparkFun_HX711_Calibration sketch
scale.tare(); //Assuming there is no weight on the scale at start up, reset the scale to 0
}
void loop()
{
int rpm=rpmGet();
if (rpm > rpmMax)
{
rpmMax = rpm;
}
lcd.setCursor(8,0);
lcd.print(" ");
lcd.setCursor(8,0);
lcd.print(rpm);
lcd.print(" rpm");
torque();
}
int torque()
{
lcd.setCursor(8,1); // move cursor to second line "1" and 9 spaces over
lcd.print(" ");
lcd.setCursor(8,1); // move cursor to second line "1" and 9 spaces over
float force = ((scale.get_units())/100);
float arm = (28);
int torque = (force * arm) ;
lcd.print(torque); // display seconds elapsed since power-up
lcd.print(" Nmm");
Serial.println(scale.get_units()); //scale.get_units() returns a float
}
int rpmGet()
{
unsigned long currentTime = 0;
unsigned long startTime = millis();
while (currentTime <= sampleTime)
{
int val = digitalRead(irPin);
if(!val)
{
if(laststate){
triggers++;
laststate=0;
}
}
else
{
laststate = 1;
}
currentTime = millis() - startTime;
}
int countRpm = int(60000/float(sampleTime))*(triggers/2);
triggers=0;
return countRpm;
}
changed the callibration factor from 2150 to 265050