kozubovskyy

Untitled

Mar 18th, 2024
41
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.67 KB | None | 0 0
  1. /**
  2. * Complete project details at https://RandomNerdTutorials.com/arduino-load-cell-hx711/
  3. *
  4. * HX711 library for Arduino - example file
  5. * https://github.com/bogde/HX711
  6. *
  7. * MIT License
  8. * (c) 2018 Bogdan Necula
  9. *
  10. **/
  11.  
  12. #include <Arduino.h>
  13. #include "HX711.h"
  14.  
  15. // HX711 circuit wiring
  16. const int LOADCELL_DOUT_PIN = 4;
  17. const int LOADCELL_SCK_PIN = 5;
  18.  
  19. const int pin2 = 2;
  20. const int pin3 = 3;
  21.  
  22. const int pin6 = 6;
  23. const int pin7 = 7;
  24.  
  25. const int pin8 = 8;
  26. const int pin9 = 9;
  27.  
  28. HX711 scale;
  29. HX711 scale2;
  30. HX711 scale3;
  31. HX711 scale4;
  32.  
  33.  
  34.  
  35.  
  36.  
  37.  
  38.  
  39. void setup() {
  40. Serial.begin(57600);
  41.  
  42.  
  43. scale.begin(LOADCELL_DOUT_PIN, LOADCELL_SCK_PIN);
  44. scale2.begin(pin2, pin3) ;
  45. scale3.begin(pin6, pin7) ;
  46. scale4.begin(pin8, pin9) ;
  47.  
  48.  
  49. scale.set_scale(18.86);
  50. scale2.set_scale(18.86);
  51. scale3.set_scale(18.86);
  52. scale4.set_scale(18.86);
  53.  
  54. scale.tare();
  55. scale2.tare();
  56. scale3.tare();
  57. scale4.tare();
  58.  
  59.  
  60. //vitale
  61. pinMode (12, INPUT); //triggerpin
  62. pinMode (13, OUTPUT); //echopin
  63.  
  64.  
  65.  
  66.  
  67. }
  68.  
  69. void loop() {
  70.  
  71.  
  72. digitalWrite (13, LOW);
  73. digitalWrite (13, HIGH);
  74. delay (10);
  75. digitalWrite (13, LOW);
  76. long durata = pulseIn(12, HIGH);
  77. long distanza = 0.034 * durata / 2;
  78. int altezza = 200 - distanza;
  79. Serial.print("altezza:");
  80. Serial.println(altezza);
  81.  
  82.  
  83.  
  84. //Serial.println(scale2.get_units(10), 5);
  85.  
  86. long lettura = ((scale.get_units(5) + scale2.get_units(5) + scale3.get_units(5) + scale4.get_units(5))/4) ;
  87. /// Serial.println(lettura);
  88. String stringOne = String(lettura) ;
  89. stringOne = stringOne + "g" ;
  90. Serial.println(stringOne);
  91.  
  92.  
  93.  
  94.  
  95.  
  96.  
  97.  
  98.  
  99.  
  100.  
  101.  
  102.  
  103. }
Advertisement
Add Comment
Please, Sign In to add comment