Components and supplies
Arduino Nano R3
Standard LCD - 16x2 White on Blue
HX 711 scale module
Tools and machines
Saw
3D Printer (generic)
Apps and platforms
Arduino IDE
Project description
Code
The code
c_cpp
This code might be not the best written one, but please remember that this was one of my very first projects!
1#include <LiquidCrystal_I2C.h> 2#include <HX711.h> 3 4HX711 scale(A1, A0); 5LiquidCrystal_I2C lcd(0x3F,16,2); 6 7 8// 9volatile float newWeight; 10volatile float prevWeight; 11volatile float money; 12volatile float item; 13volatile float change; 14volatile float flag; 15volatile int show = 1; 16volatile float itemWeight; 17volatile int amount; 18 19int tara = 4; 20unsigned long int lastTime; 21 22int up = 2; 23int down = 3; 24volatile int pos = 1; 25 26 27void setup() { 28 lcd.init(); // 29 lcd.backlight(); // 30 scale.set_scale(-1537.34); // ( ) 31 scale.tare(); // 32 prevWeight = 0; // 33 scale.power_up(); 34 35 Serial.begin(9600); 36 37 pinMode(tara, INPUT); 38 pinMode(up, INPUT); 39 attachInterrupt(0, dec, RISING); 40 pinMode(down, INPUT); 41 attachInterrupt(1, inc, RISING); 42 43} 44 45void myClear() { 46 lcd.setCursor(0,0); 47 lcd.print(" "); 48 lcd.setCursor(0,1); 49 lcd.print(" "); 50 lcd.setCursor(0,0); 51 } 52 53void reload() { 54 prevWeight = 0; 55 newWeight = 0; 56 money = 0; 57 item = 0; 58 change = 0; 59 show = 1; 60} 61 62void dec() { 63 reload(); 64 if (pos > 1) { 65 pos -= 1; 66 } 67 else { 68 pos = 4; 69 } 70} 71 72void inc() { 73 reload(); 74 if (pos < 4) { 75 pos += 1; 76 } 77 else { 78 pos = 1; 79 } 80} 81 82void analysis() { 83 if (change > 1.00 && change < 2.40) { // 1c 84 money += 1; 85 flag = 1.25; 86 } 87 else if (change > 2.80 && change < 3.15) { // 2c 88 money += 2; 89 flag = 2.50; 90 } 91 else if (change > 3.70 && change < 3.99) { // 5c 92 money += 5; 93 flag = 3.80; 94 } 95 else if (change > 4.00 && change < 4.15) { // 10c 96 money += 10; 97 flag = 4; 98 } 99 else if (change > 5.50 && change < 6.80) { // 20c 100 money += 20; 101 flag = 6; 102 } 103 else if (change > 7.60 && change < 7.95) { // 50c 104 money += 50; 105 flag = 7.80; 106 } 107 else if (change > 7.30 && change < 7.50) { // 1E 108 money += 100; 109 flag = 7.40; 110 } 111 else if (change > 8.20 && change < 9.00) { // 2E 112 money += 200; 113 flag = 8.50; 114 } 115} 116 117// : 118void standard() { 119 lcd.setCursor(0,0); 120 lcd.print(" Standard mode! "); 121 lcd.setCursor(0,1); // 1 2 ! 122 lcd.print("Weight: "); 123 if (prevWeight != round(scale.get_units(10)) ) { // , 124 newWeight = scale.get_units(10); // 125 } 126 lcd.setCursor(9,1); 127 if (newWeight < 0) { scale.tare(); } 128 else { lcd.print(newWeight); } 129 prevWeight = newWeight; // 130 131} 132/////////////////////////////////// 133 134void multiMoney() { 135 lcd.setCursor(0,0); 136 lcd.print(" Money multi! "); 137 lcd.setCursor(0,1); 138 lcd.print("Euro: "); 139 if (prevWeight != round(scale.get_units(10)) ) { 140 newWeight = scale.get_units(10); 141 change = newWeight - prevWeight; 142 analysis(); 143 lcd.setCursor(6,1); 144 lcd.print(money / 100.00); 145 prevWeight = newWeight; 146 } 147} 148////////////////////////////////////////// 149 150void massMoney() { 151 if (prevWeight != round(scale.get_units(20)) ) { 152 newWeight = scale.get_units(20); 153 change = newWeight - prevWeight; 154 prevWeight = newWeight; 155 if (change > 1) { 156 lcd.setCursor(0,1); 157 lcd.print("C:"); 158 lcd.setCursor(2,1); 159 lcd.print(show); 160 lcd.setCursor(7,1); 161 lcd.print("A:"); 162 lcd.setCursor(10,1); 163 lcd.print(show * money / 100); 164 show = show + round(change / flag); 165 } 166 } 167} 168////////////////////////////////////// 169 170void itemsMass() { 171 if (prevWeight != round(scale.get_units(10)) ) { 172 newWeight = scale.get_units(10); 173 change = newWeight - prevWeight; 174 amount = round(change / itemWeight); 175 lcd.setCursor(0,1); 176 lcd.print("Items: "); 177 lcd.print(amount); 178 lcd.setCursor(9,1); 179 lcd.print("W:"); 180 lcd.print(newWeight); 181 } 182} 183////////////////////////////////////////// 184 185 186void loop() { 187 if (millis() - lastTime > 100) { 188 if (digitalRead(tara) == 1) { 189 reload(); 190 scale.tare(); 191 } 192 lastTime = millis(); 193 } 194 195 if (pos == 1) { 196 myClear(); 197 lcd.setCursor(4,0); 198 lcd.print("Standard"); 199 delay(1000); 200 myClear(); 201 while (pos == 1) { 202 standard(); 203 } 204 } 205 206 else if (pos == 2) { 207 myClear(); 208 lcd.setCursor(3,0); 209 lcd.print("Money multi"); 210 delay(1000); 211 myClear(); 212 while (pos == 2) { 213 multiMoney(); 214 } 215 } 216 217 else if (pos == 3) { 218 myClear(); 219 lcd.setCursor(3,0); 220 lcd.print("Money mass"); 221 delay(1000); 222 myClear(); 223 lcd.print("Place ONE coin!"); 224 while (money == 0) { 225 if (prevWeight != round(scale.get_units(10)) ) { 226 newWeight = scale.get_units(10); 227 change = newWeight - prevWeight; 228 analysis(); 229 lcd.setCursor(0,1); 230 lcd.print(money / 100); 231 prevWeight = newWeight; 232 } 233 } 234 myClear(); 235 lcd.print("Counting "); 236 if (money < 100) { 237 lcd.setCursor(10,0); 238 lcd.print(money); 239 lcd.print("c"); 240 } 241 else { 242 lcd.setCursor(10,0); 243 if (money == 100) { lcd.print("1 Euro"); } 244 else { lcd.print("2 Euro"); } 245 } 246 prevWeight = 0; 247 newWeight = 0; 248 change = 0; 249 while (pos == 3) { 250 massMoney(); 251 } 252 } 253 254 255 else if (pos == 4) { 256 myClear(); 257 lcd.setCursor(3,0); 258 lcd.print("Items mass"); 259 delay(1000); 260 myClear(); 261 myClear(); 262 lcd.print("Place ONE item!"); 263 while (newWeight < 1) { 264 if (prevWeight != round(scale.get_units(10)) ) { 265 newWeight = scale.get_units(10); 266 itemWeight = newWeight - prevWeight; 267 } 268 } 269 itemWeight = newWeight - prevWeight; 270 lcd.setCursor(0,0); 271 lcd.print("Item weight:"); 272 lcd.print(itemWeight); 273 while (pos == 4) { 274 itemsMass(); 275 } 276 } 277} 278
The code
c_cpp
This code might be not the best written one, but please remember that this was one of my very first projects!
1#include <LiquidCrystal_I2C.h> 2#include <HX711.h> 3 4HX711 scale(A1, A0); 5LiquidCrystal_I2C lcd(0x3F,16,2); 6 7 8// 9volatile float newWeight; 10volatile float prevWeight; 11volatile float money; 12volatile float item; 13volatile float change; 14volatile float flag; 15volatile int show = 1; 16volatile float itemWeight; 17volatile int amount; 18 19int tara = 4; 20unsigned long int lastTime; 21 22int up = 2; 23int down = 3; 24volatile int pos = 1; 25 26 27void setup() { 28 lcd.init(); // 29 lcd.backlight(); // 30 scale.set_scale(-1537.34); // ( ) 31 scale.tare(); // 32 prevWeight = 0; // 33 scale.power_up(); 34 35 Serial.begin(9600); 36 37 pinMode(tara, INPUT); 38 pinMode(up, INPUT); 39 attachInterrupt(0, dec, RISING); 40 pinMode(down, INPUT); 41 attachInterrupt(1, inc, RISING); 42 43} 44 45void myClear() { 46 lcd.setCursor(0,0); 47 lcd.print(" "); 48 lcd.setCursor(0,1); 49 lcd.print(" "); 50 lcd.setCursor(0,0); 51 } 52 53void reload() { 54 prevWeight = 0; 55 newWeight = 0; 56 money = 0; 57 item = 0; 58 change = 0; 59 show = 1; 60} 61 62void dec() { 63 reload(); 64 if (pos > 1) { 65 pos -= 1; 66 } 67 else { 68 pos = 4; 69 } 70} 71 72void inc() { 73 reload(); 74 if (pos < 4) { 75 pos += 1; 76 } 77 else { 78 pos = 1; 79 } 80} 81 82void analysis() { 83 if (change > 1.00 && change < 2.40) { // 1c 84 money += 1; 85 flag = 1.25; 86 } 87 else if (change > 2.80 && change < 3.15) { // 2c 88 money += 2; 89 flag = 2.50; 90 } 91 else if (change > 3.70 && change < 3.99) { // 5c 92 money += 5; 93 flag = 3.80; 94 } 95 else if (change > 4.00 && change < 4.15) { // 10c 96 money += 10; 97 flag = 4; 98 } 99 else if (change > 5.50 && change < 6.80) { // 20c 100 money += 20; 101 flag = 6; 102 } 103 else if (change > 7.60 && change < 7.95) { // 50c 104 money += 50; 105 flag = 7.80; 106 } 107 else if (change > 7.30 && change < 7.50) { // 1E 108 money += 100; 109 flag = 7.40; 110 } 111 else if (change > 8.20 && change < 9.00) { // 2E 112 money += 200; 113 flag = 8.50; 114 } 115} 116 117// : 118void standard() { 119 lcd.setCursor(0,0); 120 lcd.print(" Standard mode! "); 121 lcd.setCursor(0,1); // 1 2 ! 122 lcd.print("Weight: "); 123 if (prevWeight != round(scale.get_units(10)) ) { // , 124 newWeight = scale.get_units(10); // 125 } 126 lcd.setCursor(9,1); 127 if (newWeight < 0) { scale.tare(); } 128 else { lcd.print(newWeight); } 129 prevWeight = newWeight; // 130 131} 132/////////////////////////////////// 133 134void multiMoney() { 135 lcd.setCursor(0,0); 136 lcd.print(" Money multi! "); 137 lcd.setCursor(0,1); 138 lcd.print("Euro: "); 139 if (prevWeight != round(scale.get_units(10)) ) { 140 newWeight = scale.get_units(10); 141 change = newWeight - prevWeight; 142 analysis(); 143 lcd.setCursor(6,1); 144 lcd.print(money / 100.00); 145 prevWeight = newWeight; 146 } 147} 148////////////////////////////////////////// 149 150void massMoney() { 151 if (prevWeight != round(scale.get_units(20)) ) { 152 newWeight = scale.get_units(20); 153 change = newWeight - prevWeight; 154 prevWeight = newWeight; 155 if (change > 1) { 156 lcd.setCursor(0,1); 157 lcd.print("C:"); 158 lcd.setCursor(2,1); 159 lcd.print(show); 160 lcd.setCursor(7,1); 161 lcd.print("A:"); 162 lcd.setCursor(10,1); 163 lcd.print(show * money / 100); 164 show = show + round(change / flag); 165 } 166 } 167} 168////////////////////////////////////// 169 170void itemsMass() { 171 if (prevWeight != round(scale.get_units(10)) ) { 172 newWeight = scale.get_units(10); 173 change = newWeight - prevWeight; 174 amount = round(change / itemWeight); 175 lcd.setCursor(0,1); 176 lcd.print("Items: "); 177 lcd.print(amount); 178 lcd.setCursor(9,1); 179 lcd.print("W:"); 180 lcd.print(newWeight); 181 } 182} 183////////////////////////////////////////// 184 185 186void loop() { 187 if (millis() - lastTime > 100) { 188 if (digitalRead(tara) == 1) { 189 reload(); 190 scale.tare(); 191 } 192 lastTime = millis(); 193 } 194 195 if (pos == 1) { 196 myClear(); 197 lcd.setCursor(4,0); 198 lcd.print("Standard"); 199 delay(1000); 200 myClear(); 201 while (pos == 1) { 202 standard(); 203 } 204 } 205 206 else if (pos == 2) { 207 myClear(); 208 lcd.setCursor(3,0); 209 lcd.print("Money multi"); 210 delay(1000); 211 myClear(); 212 while (pos == 2) { 213 multiMoney(); 214 } 215 } 216 217 else if (pos == 3) { 218 myClear(); 219 lcd.setCursor(3,0); 220 lcd.print("Money mass"); 221 delay(1000); 222 myClear(); 223 lcd.print("Place ONE coin!"); 224 while (money == 0) { 225 if (prevWeight != round(scale.get_units(10)) ) { 226 newWeight = scale.get_units(10); 227 change = newWeight - prevWeight; 228 analysis(); 229 lcd.setCursor(0,1); 230 lcd.print(money / 100); 231 prevWeight = newWeight; 232 } 233 } 234 myClear(); 235 lcd.print("Counting "); 236 if (money < 100) { 237 lcd.setCursor(10,0); 238 lcd.print(money); 239 lcd.print("c"); 240 } 241 else { 242 lcd.setCursor(10,0); 243 if (money == 100) { lcd.print("1 Euro"); } 244 else { lcd.print("2 Euro"); } 245 } 246 prevWeight = 0; 247 newWeight = 0; 248 change = 0; 249 while (pos == 3) { 250 massMoney(); 251 } 252 } 253 254 255 else if (pos == 4) { 256 myClear(); 257 lcd.setCursor(3,0); 258 lcd.print("Items mass"); 259 delay(1000); 260 myClear(); 261 myClear(); 262 lcd.print("Place ONE item!"); 263 while (newWeight < 1) { 264 if (prevWeight != round(scale.get_units(10)) ) { 265 newWeight = scale.get_units(10); 266 itemWeight = newWeight - prevWeight; 267 } 268 } 269 itemWeight = newWeight - prevWeight; 270 lcd.setCursor(0,0); 271 lcd.print("Item weight:"); 272 lcd.print(itemWeight); 273 while (pos == 4) { 274 itemsMass(); 275 } 276 } 277} 278
Downloadable files
The connection of the HX711 module
The connection of the HX711 module
The connection of the HX711 module
The connection of the HX711 module
HX711 Library
HX711 Library
Documentation
The 3d model, altough it is just a prototype.
The 3d model, altough it is just a prototype.
The 3d model, altough it is just a prototype.
The 3d model, altough it is just a prototype.
Comments
Only logged in users can leave comments