// // Loadcell Program Ver 1.0 // Licence: Attribution-ShareAlike CC BY-SA // Created by Michael Graham, www.EngineerDog.com // // This program operates the loadcell & LCD Readout // Button control is not in use here. // // The Circuit: // A0 = load cell input // D4-D10 = LCD screen input // // //____LCD DECLATRATIONS___________________________________________________________________________________________ #include //#include LiquidCrystal lcd(8, 13, 9, 4, 5, 6, 7); //Defined LCD, (digital pins used by LCD) //____LOAD CELL DECLATRATIONS______________________________________________________________________________________ const int LoadPin = 0; // select the input pin for the loadcell, default is pin 0 float LoadOffset = 0; // Load added to measured load to offset it to zero, lbs float Load = 0; // Sensed load force, lbs. float Disp = 0; // Sensed displacement in inches const int DelayTime = 200; // delay X millisec to control data acquisition rate: (1000 = 1Hz, 200 = 5 Hz, 20 = 50Hz, 10 = 100Hz) double LoadScale = 2.295; // lb/V, calculated as a function of nominal load, gain, & sensitivity float SpringRate = 5.1; // lb/in //____LCD SETUP___________________________________________________________________________________________________ void setup() { Serial.begin(9600); // initialize serial communication at 9600 baud. The serial monitor is used for data collection. lcd.begin(16, 2); lcd.clear(); lcd.setCursor(0,0); lcd.print("LOAD CELL PROG"); lcd.setCursor(0,1); lcd.print(" System Reset! "); delay(2200); //____LOADCELL SETUP_______________________________________________________________________________________________ LoadOffset = -analogRead(LoadPin)*.0048828125*LoadScale; // Raw loadcell reading * Voltage Input Range divided by bit resolution (5v/1024) * Load cell scale factor. 'LoadOffset' is for setting the 'Load' to zero. } //____LOOP__________________________________________________________________________________________________________ void loop() { CollectData(); delay (DelayTime); PrintSerial(); lcd.clear(); PrintLCD(); } //____Function Assignment_____________________________________________________________________________________________ int CollectData() //This function collects all available data { Load = abs(analogRead(LoadPin)*.0048828125*LoadScale+LoadOffset+.00001); // The abs & .00001 prevent the negative sign from showing at 0 lbs. Disp = Load/SpringRate; } int PrintSerial() //This function prints all available data to the serial monitor { Serial.print(millis()); // print the time in milliseconds since the program started Serial.print(','); // print a comma Serial.print(Load,6); // print the load to serial Serial.print(','); // print a comma Serial.print(Disp,6); // print the displacement to serial } int PrintLCD() //This function prints all available data to the LCD { lcd.setCursor(0,0); lcd.print("LOAD, DISTANCE"); //Header Line which is always showing lcd.setCursor(0,3); lcd.print(Load,3); //Current force to 3 decimal place lcd.print(" "); lcd.print(Disp,3); //Current displacementr to 3 decimal places }