Respected all,
as of now i am having very little time to interface because of some urgent emergencies, I need help for my project regarding store data for compare with sensor value , and here i am using sensor as weightstone bridge for weighing machine using hx711 amplifier and also calibration done, so i want to check my sensor value with my input value which will come from my keypad and for display im using 16x2 lcd I2C connection with my arduino MEGA, here is my code: I have copied from the forum :How to use decimal places with keypad entry - Programming Questions - Arduino Forum
#include <Keypad.h>
#include <LiquidCrystal.h>
#include <HX711.h>
LiquidCrystal lcd(2,3,4,5,6,7);
#define calibration_factor -9752.0 //This value is obtained using the SparkFun_HX711_Calibration sketch
#define LOADCELL_DOUT_PIN 9
#define LOADCELL_SCK_PIN 8
HX711 scale;
const byte ROWS = 4; //four rows
const byte COLS = 4; //four columns
char keys[ROWS][COLS] = {
{'1', '2', '3', 'A'},
{'4', '5', '6', 'B'},
{'7', '8', '9', 'C'},
{'*', '0', '#', 'D'}
};
byte rowPins[ROWS] = { 14, 15, 16, 17 }; //connect to the row pinouts of the keypad
byte colPins[COLS] = { 18, 19, 20, 21 }; //connect to the column pinouts of the keypad
Keypad keypad = Keypad( makeKeymap(keys), rowPins, colPins, ROWS, COLS );
void setup()
{
lcd.begin(16, 2);
Serial.begin(9600);
pinMode(13, OUTPUT);
digitalWrite(13, LOW);
scale.begin(LOADCELL_DOUT_PIN, LOADCELL_SCK_PIN);
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()
{
float myValueFromKeypad1 = getKeypadFloat();
float myValueFromKeypad2 = getKeypadFloat();
Serial.println(" ");
Serial.print("I received ");
Serial.print(myValueFromKeypad1, 4);
Serial.print(", and then I received ");
Serial.println(myValueFromKeypad2, 4);
float S_val = myValueFromKeypad1;
lcd.setCursor(0, 0);
lcd.print("S_val = "); //keypad value
lcd.print(S_val,4);
char M_val = (scale.get_units(), 4);
lcd.setCursor(0, 1);
lcd.print("M_Val = ");
lcd.print(scale.get_units(), 4);
Serial.print(" unit"); //You can change this to kg but you'll need to refactor the calibration_factor
Serial.println();
}//loop
float getKeypadFloat()
{
int debug = 1;
float beforeDecimal = 0; // the number accumulator
float afterDecimal = 0;
byte howManyDecimals = 0;
float finalValue;
int keyval; // the key press
int isNum;
int isStar;
int isHash;
Serial.println("Enter digits, * as decimal point, then decimals, # to end");
if (debug)Serial.print("So far: ");
// accumulate the part before the decimal
do
{
keyval = keypad.getKey(); // input the key
isNum = (keyval >= '0' && keyval <= '9'); // is it a digit?
if (isNum)
{
if (debug)Serial.print(keyval - '0');
beforeDecimal = beforeDecimal * 10 + keyval - '0'; // accumulate the input number
}
isStar = (keyval == '*');
if (debug)if (isStar) Serial.print(".");
//display but ignore illegal presses
/* if (debug)
{
if (keyval == 'A' || keyval == 'B' || keyval == 'C' || keyval == 'D' || keyval == '#')
Serial.print("?");
}
*/
} while (!isStar || !keyval); // until a * or while no key pressed
// accumulate the part after the decimal
do
{
keyval = keypad.getKey(); // input the key
isNum = (keyval >= '0' && keyval <= '9'); // is it a digit?
if (isNum)
{
if (debug)Serial.print(keyval - '0');
afterDecimal = afterDecimal * 10 + keyval - '0'; // accumulate the input number
howManyDecimals++; // increment for later use
}
isHash = (keyval == '#');
//display but ignore illegal presses
if (debug)
{
if (keyval == 'A' || keyval == 'B' || keyval == 'C' || keyval == 'D' || keyval == '*')
Serial.print("?");
}
} while (!isHash || !keyval); // until # or while no key pressed
finalValue = beforeDecimal + (afterDecimal / pow(10, howManyDecimals));
if (debug)Serial.println(" ");
if (debug)Serial.print("Returning ");
if (debug)Serial.println(finalValue, howManyDecimals);
return finalValue;
}//getKeypadFloat
Here is my code but i need to compare S_val with M_val , here S_val will come from keypad entry and M_val will come from weighing bridge load cell sensor.
so when S_val will be manually typed from keypad , it will then compare with value of Measured value from sensor if the measured value from sensor is lower then S_val then the LED_pin 13 will go low or else it will go high but measured value will be comes around the S_val like plus minus 0.2 decimals then it is acceptable how to solve this kindly guide me as i am having less time to interface.
Thank you so much.