Touchless Flush Sink Activator Add-On


Arduino Nano
Obstacle Detector Module (x2)
MG995S Servos (x3)
9G Servos (x2)
1000 uf Capacitor
330 ohm Resistor
1K ohm Resistor
5V 4A Power Supply


  1. // sink starter
  2. // pkvi
  3. // updated with button restore
  4. // updated with touchless flush + sink
  5. #include "FastLED.h"
  6. #include <VarSpeedServo.h>
  7. #define NUM_LEDS 90
  8. #define LED_TYPE WS2812B
  9. #define COLOR_ORDER GRB
  10. CRGB leds[NUM_LEDS];
  11. int data = 255;
  12. int r = 0;
  13. int g = 0;
  14. int b = 255;
  15. int j = 0;
  16. int k = 0;
  17. int red_ran;
  18. int blue_ran;
  19. int green_ran;
  20. VarSpeedServo left;
  21. VarSpeedServo l_lift;
  22. VarSpeedServo right;
  23. VarSpeedServo r_lift;
  24. VarSpeedServo toilet_flush;
  25. //pins
  26. const int toilet_pin = 2;
  27. const int left_pin = 3;
  28. const int l_lift_pin = 5;
  29. const int right_pin = 7;
  30. const int r_lift_pin = 9;
  31. const int motion = 11;
  32. const int toilet_motion = 14;
  33. #define PIN 16
  34. const int button = 18;
  35. const int rldown = 100;
  36. const int lldown = 80;
  37. const int rlup = 6;
  38. const int llup = 180;
  39. const int lup = 10;
  40. const int rup = 170;
  41. const int ldown_second = 92;
  42. const int rdown_second = 100;
  43. const int toilet_up = 55;
  44. const int toilet_down = 10;
  45. int sink_moved;
  46. int toilet_moved;
  47. void setup() {
  48. pinMode(motion, INPUT);
  49. pinMode(toilet_motion, INPUT);
  50. pinMode(button, INPUT);
  51. FastLED.addLeds<LED_TYPE, PIN, COLOR_ORDER>(leds, NUM_LEDS).setCorrection( TypicalLEDStrip );
  52. // wait for user activation
  53. // power outage safety
  54. while (digitalRead(button) == LOW) {
  55. neoshow(255, 0, 0, 150);
  56. delay(500);
  57. neoshow(0, 0, 0, 150);
  58. delay(500);
  59. }
  60. l_lift.attach(l_lift_pin);
  61. r_lift.attach(r_lift_pin);
  62. delay(1000); // default error fix
  63. right.attach(right_pin);
  64. left.attach(left_pin);
  65. delay(500);
  66. l_lift.write(lldown, 255, false);
  67. r_lift.write(rldown, 255, true);
  68. delay(1000);
  69. left.write(lup, 100, false);
  70. right.write(rup, 100, true);
  71. delay(1000);
  72. l_lift.write(llup, 180, false);
  73. r_lift.write(rlup, 180, true);
  74. delay(500);
  75. toilet_flush.attach(toilet_pin);
  76. delay(500);
  77. toilet_flush.write(toilet_down, 180, true);
  78. delay(500);
  79. l_lift.detach();
  80. r_lift.detach();
  81. left.detach();
  82. right.detach();
  83. toilet_flush.detach();
  84. colorWipe(0x00, 0x00, 0xff, 50);
  85. neoshow(0, 0, 255, 220);
  86. }
  87. void loop() {
  88. // if motion
  89. sink_moved = digitalRead(motion);
  90. if (sink_moved == LOW) {
  91. doit();
  92. }
  93. toilet_moved = digitalRead(toilet_motion);
  94. if (toilet_moved == LOW) {
  95. poopie();
  96. doit();
  97. }
  98. }
  99. void doit() {
  100. // reconnect pins
  101. l_lift.attach(l_lift_pin);
  102. r_lift.attach(r_lift_pin);
  103. right.attach(right_pin);
  104. left.attach(left_pin);
  105. // give it a chance
  106. delay(100);
  107. // lift down first
  108. l_lift.write(lldown, 255, false);
  109. r_lift.write(rldown, 255, true);
  110. delay(500);
  111. // push
  112. left.write(ldown_second, 200, false);
  113. right.write(rdown_second, 200, true);
  114. delay(500);
  115. // return
  116. left.write(lup, 200, false);
  117. right.write(rup, 200, true);
  118. delay(500);
  119. // lift
  120. l_lift.write(llup, 100, false);
  121. r_lift.write(rlup, 100, true);
  122. delay(500);
  123. // disconnect pins
  124. l_lift.detach();
  125. r_lift.detach();
  126. left.detach();
  127. right.detach();
  128. // pavlov
  129. lightshow();
  130. }
  131. void poopie() {
  132. toilet_flush.attach(toilet_pin);
  133. delay(100);
  134. toilet_flush.write(toilet_up, 180, true);
  135. delay(3000);
  136. toilet_flush.write(toilet_down, 180, true);
  137. delay(100);
  138. toilet_flush.detach();
  139. }
  140. void lightshow() {
  141. j = random(1, 3);
  142. if (j == 1) {
  143. for (k = 0; k < 4; k++) {
  144. TwinkleRandom(20, 100, false);
  145. }
  146. } else if (j == 2) {
  147. for (k = 0; k < 1; k++) {
  148. rainbowCycle(20);
  149. }
  150. } else if (j == 3) {
  151. for (k = 0; k < 2; k++) {
  152. red_ran = random(255);
  153. green_ran = random(255);
  154. blue_ran = random(255);
  155. if (red_ran > 200 && green_ran > 200 && blue_ran > 200) {
  156. red_ran = random(0, 80);
  157. }
  158. colorWipe(red_ran, green_ran, blue_ran, 50);
  159. colorWipe(0, 0, 0, 50);
  160. }
  161. }
  162. red_ran = random(255);
  163. green_ran = random(255);
  164. blue_ran = random(255);
  165. if (red_ran > 200 && green_ran > 200 && blue_ran > 200) {
  166. red_ran = random(0, 80);
  167. }
  168. colorWipe(0, 0, 0, 50);
  169. colorWipe(red_ran, green_ran, blue_ran, 50);
  170. neoshow(red_ran, green_ran, blue_ran, 200);
  171. }
  172. void neoshow(int r, int g, int b, int brightness) {
  173. FastLED.setBrightness(brightness);
  174. for (int i = 0; i < NUM_LEDS; i++ )
  175. {
  176. leds[i] = CRGB(r, g, b);
  177. }
  178. FastLED.show();
  179. }
  180. void showStrip() {
  181. #ifdef ADAFRUIT_NEOPIXEL_H
  182. // NeoPixel
  183. strip.show();
  184. #endif
  185. #ifndef ADAFRUIT_NEOPIXEL_H
  186. // FastLED
  187. FastLED.show();
  188. #endif
  189. }
  190. void setPixel(int Pixel, byte red, byte green, byte blue) {
  191. #ifdef ADAFRUIT_NEOPIXEL_H
  192. // NeoPixel
  193. strip.setPixelColor(Pixel, strip.Color(red, green, blue));
  194. #endif
  195. #ifndef ADAFRUIT_NEOPIXEL_H
  196. // FastLED
  197. leds[Pixel].r = red;
  198. leds[Pixel].g = green;
  199. leds[Pixel].b = blue;
  200. #endif
  201. }
  202. void setAll(byte red, byte green, byte blue) {
  203. for (int i = 0; i < NUM_LEDS; i++ ) {
  204. setPixel(i, red, green, blue);
  205. }
  206. showStrip();
  207. }
  208. void rainbowCycle(int SpeedDelay) {
  209. byte *c;
  210. uint16_t i, j;
  211. for (j = 0; j < 256 * 5; j++) { // 5 cycles of all colors on wheel
  212. for (i = 0; i < NUM_LEDS; i++) {
  213. c = Wheel(((i * 256 / NUM_LEDS) + j) & 255);
  214. setPixel(i, *c, *(c + 1), *(c + 2));
  215. }
  216. showStrip();
  217. delay(SpeedDelay);
  218. }
  219. }
  220. byte * Wheel(byte WheelPos) {
  221. static byte c[3];
  222. if (WheelPos < 85) {
  223. c[0] = WheelPos * 3;
  224. c[1] = 255 - WheelPos * 3;
  225. c[2] = 0;
  226. } else if (WheelPos < 170) {
  227. WheelPos -= 85;
  228. c[0] = 255 - WheelPos * 3;
  229. c[1] = 0;
  230. c[2] = WheelPos * 3;
  231. } else {
  232. WheelPos -= 170;
  233. c[0] = 0;
  234. c[1] = WheelPos * 3;
  235. c[2] = 255 - WheelPos * 3;
  236. }
  237. return c;
  238. }
  239. void TwinkleRandom(int Count, int SpeedDelay, boolean OnlyOne) {
  240. setAll(0, 0, 0);
  241. for (int i = 0; i < Count; i++) {
  242. setPixel(random(NUM_LEDS), random(0, 255), random(0, 255), random(0, 255));
  243. showStrip();
  244. delay(SpeedDelay);
  245. if (OnlyOne) {
  246. setAll(0, 0, 0);
  247. }
  248. }
  249. delay(SpeedDelay);
  250. }
  251. void colorWipe(byte red, byte green, byte blue, int SpeedDelay) {
  252. for (uint16_t i = 0; i < NUM_LEDS; i++) {
  253. setPixel(i, red, green, blue);
  254. showStrip();
  255. delay(SpeedDelay);
  256. }
  257. }

Menu
Index
Engineering
Entertainment
Literature
Miscellaneous
Contact
Search
tiktok.com/@pkvi.xyz
Why Ayh?
Miter
Miter
@pkvi
"...may not meet professional standards."
2,363 miters
123 tenons
Subscribe
0.00506