Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <HX711_ADC.h> // https://github.com/olkal/HX711_ADC
- #include <Wire.h>
- #include <LiquidCrystal_I2C.h> // LiquidCrystal_I2C library
- //Initialize the pins for the motor
- #define ENABLE 9
- #define DIRA 10
- #define DIRB 11
- HX711_ADC LoadCell(4, 5); // parameters: dt pin, sck pin<span data-mce-type="bookmark" style="display: inline-block; width: 0px; overflow: hidden; line-height: 0;" class="mce_SELRES_start"></span>
- LiquidCrystal_I2C lcd(0x27,16,2); // 0x27 is the i2c address of the LCM1602 IIC v1 module (might differ)
- void setup() {
- LoadCell.begin(); // start connection to HX711
- LoadCell.start(2000); // load cells gets 2000ms of time to stabilize
- LoadCell.setCalFactor(400); // calibration factor for load cell => strongly dependent on your individual setup
- lcd.begin(); // begins connection to the LCD module
- lcd.backlight(); // turns on the backlight
- //---set pin direction for motors
- pinMode(ENABLE, OUTPUT);
- pinMode(DIRA, OUTPUT);
- pinMode(DIRB, OUTPUT);
- }
- void loop() {
- LoadCell.update(); // retrieves data from the load cell
- float i = LoadCell.getData(); // get output value
- lcd.setCursor(0, 0); // set cursor to first row
- lcd.print("Weight[g]:"); // print out to LCD
- lcd.setCursor(0, 1); // set cursor to secon row
- lcd.print(i); // print out the retrieved value to the second row
- if (i > 13.00) { // weight is greater than 13g
- digitalWrite(ENABLE, HIGH);
- digitalWrite(DIRA, HIGH);
- digitalWrite(DIRB, LOW);
- } else {
- digitalWrite(ENABLE, LOW);
- digitalWrite(DIRA, HIGH);
- digitalWrite(DIRB, LOW);
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement