Components and supplies
Grove - WS2813 RGB LED Strip Waterproof - 60 LED/m - 1m
Arduino Nano R3
SparkFun Load Cell Amplifier - HX711
BD 135 Transistor
Linear Regulator (7805)
Resistor 10k ohm
Tools and machines
Soldering iron (generic)
3D Printer (generic)
Project description
Code
HX711_full_example.ino
arduino
1/** 2 * 3 * HX711 library for Arduino - example file 4 * https://github.com/bogde/HX711 5 * 6 * MIT License 7 * (c) 2018 Bogdan Necula 8 * 9**/ 10#include "HX711.h" 11 12 13// HX711 circuit wiring 14const int LOADCELL_DOUT_PIN = 2; 15const int LOADCELL_SCK_PIN = 3; 16 17 18HX711 scale; 19 20void setup() { 21 Serial.begin(38400); 22 Serial.println("HX711 Demo"); 23 pinMode(9,OUTPUT); 24 pinMode(10,OUTPUT); 25 pinMode(11,OUTPUT); 26 27 Serial.println("Initializing the scale"); 28 29 // Initialize library with data output pin, clock input pin and gain factor. 30 // Channel selection is made by passing the appropriate gain: 31 // - With a gain factor of 64 or 128, channel A is selected 32 // - With a gain factor of 32, channel B is selected 33 // By omitting the gain factor parameter, the library 34 // default "128" (Channel A) is used here. 35 scale.begin(LOADCELL_DOUT_PIN, LOADCELL_SCK_PIN); 36 37 Serial.println("Before setting up the scale:"); 38 Serial.print("read: \ \ "); 39 Serial.println(scale.read()); // print a raw reading from the ADC 40 41 Serial.print("read average: \ \ "); 42 Serial.println(scale.read_average(20)); // print the average of 20 readings from the ADC 43 44 Serial.print("get value: \ \ "); 45 Serial.println(scale.get_value(5)); // print the average of 5 readings from the ADC minus the tare weight (not set yet) 46 47 Serial.print("get units: \ \ "); 48 Serial.println(scale.get_units(5), 1); // print the average of 5 readings from the ADC minus tare weight (not set) divided 49 // by the SCALE parameter (not set yet) 50 51 scale.set_scale(2280.f); // this value is obtained by calibrating the scale with known weights; see the README for details 52 scale.tare(); // reset the scale to 0 53 54 Serial.println("After setting up the scale:"); 55 56 Serial.print("read: \ \ "); 57 Serial.println(scale.read()); // print a raw reading from the ADC 58 59 Serial.print("read average: \ \ "); 60 Serial.println(scale.read_average(20)); // print the average of 20 readings from the ADC 61 62 Serial.print("get value: \ \ "); 63 Serial.println(scale.get_value(5)); // print the average of 5 readings from the ADC minus the tare weight, set with tare() 64 65 Serial.print("get units: \ \ "); 66 Serial.println(scale.get_units(5), 1); // print the average of 5 readings from the ADC minus tare weight, divided 67 // by the SCALE parameter set with set_scale 68 69 Serial.println("Readings:"); 70} 71 72void loop() { 73 Serial.print("one reading:\ "); 74 Serial.print(10*scale.get_units(), 1); 75 Serial.print("\ | average:\ "); 76 Serial.println(10*scale.get_units(10), 1); 77 78 79 80 81 82if(10*scale.get_units()<185) 83{ 84 analogWrite(9,255); 85 analogWrite(10,0); 86 analogWrite(11,0); 87 } 88 else if(10*scale.get_units()<220) 89 { 90 analogWrite(9,255); 91 analogWrite(10,0); 92 analogWrite(11,100); 93 } 94 else if(10*scale.get_units()<270) 95 { 96 analogWrite(9,0); 97 analogWrite(10,0); 98 analogWrite(11,200); 99 } 100 else if(10*scale.get_units()<320) 101 { 102 analogWrite(9,0); 103 analogWrite(10,255); 104 analogWrite(11,0); 105 } 106 else{ 107 analogWrite(9,100); 108 analogWrite(10,200); 109 analogWrite(11,200);} 110 111 112 113 114 115 116 117 118 119 scale.power_down(); 120 delay(5); 121 scale.power_up(); 122} 123
HX711_full_example.ino
arduino
1/** 2 * 3 * HX711 library for Arduino - example file 4 * https://github.com/bogde/HX711 5 6 * 7 * MIT License 8 * (c) 2018 Bogdan Necula 9 * 10**/ 11#include "HX711.h" 12 13 14// 15 HX711 circuit wiring 16const int LOADCELL_DOUT_PIN = 2; 17const int LOADCELL_SCK_PIN 18 = 3; 19 20 21HX711 scale; 22 23void setup() { 24 Serial.begin(38400); 25 26 Serial.println("HX711 Demo"); 27 pinMode(9,OUTPUT); 28 pinMode(10,OUTPUT); 29 30 pinMode(11,OUTPUT); 31 32 Serial.println("Initializing the scale"); 33 34 35 // Initialize library with data output pin, clock input pin and gain factor. 36 37 // Channel selection is made by passing the appropriate gain: 38 // - With a 39 gain factor of 64 or 128, channel A is selected 40 // - With a gain factor of 41 32, channel B is selected 42 // By omitting the gain factor parameter, the library 43 44 // default "128" (Channel A) is used here. 45 scale.begin(LOADCELL_DOUT_PIN, 46 LOADCELL_SCK_PIN); 47 48 Serial.println("Before setting up the scale:"); 49 50 Serial.print("read: \ \ "); 51 Serial.println(scale.read()); // print 52 a raw reading from the ADC 53 54 Serial.print("read average: \ \ "); 55 56 Serial.println(scale.read_average(20)); // print the average of 20 readings 57 from the ADC 58 59 Serial.print("get value: \ \ "); 60 Serial.println(scale.get_value(5)); // 61 print the average of 5 readings from the ADC minus the tare weight (not set yet) 62 63 64 Serial.print("get units: \ \ "); 65 Serial.println(scale.get_units(5), 1); // 66 print the average of 5 readings from the ADC minus tare weight (not set) divided 67 // 68 by the SCALE parameter (not set yet) 69 70 scale.set_scale(2280.f); // 71 this value is obtained by calibrating the scale with known weights; see the README 72 for details 73 scale.tare(); // reset the scale to 0 74 75 Serial.println("After 76 setting up the scale:"); 77 78 Serial.print("read: \ \ "); 79 Serial.println(scale.read()); 80 // print a raw reading from the ADC 81 82 Serial.print("read 83 average: \ \ "); 84 Serial.println(scale.read_average(20)); // print 85 the average of 20 readings from the ADC 86 87 Serial.print("get value: \ \ "); 88 89 Serial.println(scale.get_value(5)); // print the average of 5 readings from 90 the ADC minus the tare weight, set with tare() 91 92 Serial.print("get units: 93 \ \ "); 94 Serial.println(scale.get_units(5), 1); // print the average 95 of 5 readings from the ADC minus tare weight, divided 96 // by the SCALE 97 parameter set with set_scale 98 99 Serial.println("Readings:"); 100} 101 102void 103 loop() { 104 Serial.print("one reading:\ "); 105 Serial.print(10*scale.get_units(), 106 1); 107 Serial.print("\ | average:\ "); 108 Serial.println(10*scale.get_units(10), 109 1); 110 111 112 113 114 115if(10*scale.get_units()<185) 116{ 117 analogWrite(9,255); 118 119 analogWrite(10,0); 120 analogWrite(11,0); 121 } 122 else if(10*scale.get_units()<220) 123 124 { 125 analogWrite(9,255); 126 analogWrite(10,0); 127 analogWrite(11,100); 128 129 } 130 else if(10*scale.get_units()<270) 131 { 132 analogWrite(9,0); 133 134 analogWrite(10,0); 135 analogWrite(11,200); 136 } 137 else if(10*scale.get_units()<320) 138 139 { 140 analogWrite(9,0); 141 analogWrite(10,255); 142 analogWrite(11,0); 143 144 } 145 else{ 146 analogWrite(9,100); 147 analogWrite(10,200); 148 analogWrite(11,200);} 149 150 151 152 153 154 155 156 157 158 159 scale.power_down(); 160 delay(5); 161 scale.power_up(); 162} 163
Downloadable files
hx71112222_kb1dYR9i2M.png
hx71112222_kb1dYR9i2M.png
ilk_devreeee_7r9m5FaDs4.png
ilk_devreeee_7r9m5FaDs4.png
hx71112222_kb1dYR9i2M.png
hx71112222_kb1dYR9i2M.png
Comments
Only logged in users can leave comments