Menu
Index
Engineering
Entertainment
Literature
Miscellaneous
Contact
Search
tiktok.com/@pkvi.xyz
scored.co/u/pkvi_mv
Why Ayh?
Miter
Miter
@pkvi
"...may not meet professional standards."
1767 miters
123 tenons
Subscribe
0.01385
Garbage Gauge


  1. // Garbage Gauge
  2. // pkvi
  3. #ifdef SPARK
  4. #include "ThingSpeak/ThingSpeak.h"
  5. #else
  6. #include "ThingSpeak.h"
  7. #endif
  8. #ifdef SPARK
  9. TCPClient client;
  10. #define VOLTAGE_MAX 3.3
  11. #define VOLTAGE_MAXCOUNTS 4095.0
  12. #endif
  13. // ThingSpeak
  14. unsigned long myChannelNumber = CHANNEL;
  15. const char * myWriteAPIKey = "APIKEY";
  16. // Input
  17. int scale = A5;
  18. // Variables
  19. int current = 0;
  20. int tare = 0;
  21. int preweight = 0;
  22. int adjust = 0;
  23. int week = 0;
  24. int total = 0;
  25. int wait = 10800; // 3 Hours
  26. void setup() {
  27. Serial.begin(9600);
  28. ThingSpeak.begin(client);
  29. // Calm Down Power-Up Fluctuation
  30. delay(5000);
  31. // Empty Garbage Bin Weight
  32. tare = analogRead(scale);
  33. delay(5000);
  34. }
  35. void loop() {
  36. // Read Pot
  37. current = analogRead(scale);
  38. // Convert to Pounds
  39. // Pot Turn Limitation 254 Pounds
  40. // Particle Photon is 0 to 4095
  41. preweight = map(current, 0, 4095, 0, 254);
  42. // Subtract Tare
  43. adjust = preweight - tare;
  44. if (adjust < week && preweight < tare) {
  45. // No Barrel? Ignore
  46. }
  47. else if (adjust < week && preweight > tare) {
  48. // Barrel Emptied? Reset Week
  49. week = adjust;
  50. }
  51. else if (adjust == week) {
  52. // No Change? Ignore
  53. }
  54. else if (adjust > week) {
  55. // Remove Previous Week Addition
  56. total = total - week;
  57. // Adjust Week
  58. week = adjust;
  59. // Add to Total
  60. total = total + week;
  61. }
  62. // Total Amount
  63. ThingSpeak.writeField(myChannelNumber, 1, total, myWriteAPIKey);
  64. // Amount Since Emptying
  65. ThingSpeak.writeField(myChannelNumber, 2, week, myWriteAPIKey);
  66. // Low Power During Delay
  67. System.sleep(wait);
  68. delay(wait);
  69. // Allow WIFI Recovery
  70. delay(10000);
  71. }