sohotcall

HX711 Load Cell Sensor Arduino

Jul 23rd, 2018
127
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. #define DOUT_PIN PB12
  2. #define PD_SCK_PIN PB13
  3.  
  4. void setup() {
  5.   pinMode(DOUT_PIN, INPUT);
  6.   pinMode(PD_SCK_PIN, OUTPUT);
  7.   digitalWrite(PD_SCK_PIN, LOW);
  8.  
  9.   Serial.begin(9600);
  10.  
  11.   delay(100);
  12.   digitalWrite(PD_SCK_PIN, HIGH);
  13.   delayMicroseconds(100);
  14.   digitalWrite(PD_SCK_PIN, LOW);
  15.   delay(1);
  16. }
  17.  
  18. long result = 0;
  19. void loop() {
  20.   result = 0;
  21.   while (digitalRead(DOUT_PIN) == HIGH){}
  22.   for (uint8_t i = 0; i < 25; i++){
  23.     delayMicroseconds(1);
  24.     digitalWrite(PD_SCK_PIN, HIGH);
  25.     delayMicroseconds(1);
  26.     digitalWrite(PD_SCK_PIN, LOW);
  27.     result <<= 1;
  28.     result |= digitalRead(DOUT_PIN);
  29.   }
  30.   result >>= 1;
  31.  
  32.   // to convert to kilograms it will be result * something + something
  33.   Serial.println(result);
  34.  
  35.   delay(1000);
  36. }
RAW Paste Data