Arduino Plasma Toilet Air Freshener


Arduino Nano
9G Servos (2) 360 deg (1) 180 deg
5V Relay Module
Neopixel Strips (2)
1000 uf Capacitor
47 ohm Resistor
Mercury Tilt Switch
Florescent Light Ballast
Television Transformers (2)
Steel Wool




  1. // Arduino Plasma Toilet Air Freshener
  2. // pkvi
  3. #include <FastLED.h>
  4. #include <Servo.h>
  5. // Neopixel
  6. #define DATA_PIN 2
  7. #define LED_TYPE WS2812
  8. #define COLOR_ORDER GRB
  9. #define NUM_LEDS 3
  10. #define BRIGHTNESS 100
  11. #define FRAMES_PER_SECOND 120
  12. CRGB leds[NUM_LEDS];
  13. // Servos
  14. Servo gyro;
  15. Servo riser;
  16. Servo level;
  17. // Gyro
  18. int gyro_pos = 95;
  19. int gyro_stop = 95;
  20. int rotate = 77;
  21. int timer_rotate_initial = 3000;
  22. int timer_rotate = 9150;
  23. // hall sensor in next version
  24. // Riser
  25. int rise = 105;
  26. int lower = 75;
  27. int riser_stop = 91;
  28. int timer_riser_up = 20;
  29. int timer_riser_down = 20;
  30. // Level
  31. int level_pos = 125;
  32. int up = 93;
  33. int down = 125;
  34. // Relay
  35. int relay = 3;
  36. // Trigger
  37. // Mercury Switch
  38. int trigger = 7;
  39. int led = 8;
  40. int state = 0;
  41. int hold_state = 0;
  42. void setup() {
  43. Serial.begin(9600);
  44. pinMode(trigger, INPUT);
  45. pinMode(led, OUTPUT);
  46. pinMode(relay, OUTPUT);
  47. digitalWrite(relay, LOW);
  48. gyro.attach(5);
  49. gyro.write(gyro_stop);
  50. riser.attach(6);
  51. riser.write(riser_stop);
  52. level.attach(4);
  53. level.write(down);
  54. FastLED.addLeds<LED_TYPE, DATA_PIN, COLOR_ORDER>(leds, NUM_LEDS).setCorrection(TypicalLEDStrip);
  55. FastLED.setBrightness(BRIGHTNESS);
  56. // Alert Active
  57. colorFWD(0x00, 0x00, 0xff, 100);
  58. colorFWD(0x00, 0x00, 0x00, 100);
  59. colorFWD(0x00, 0x00, 0xff, 100);
  60. colorFWD(0x00, 0x00, 0x00, 100);
  61. }
  62. void loop() {
  63. // Clear Strip
  64. colorFWD(0x00, 0x00, 0x00, 100);
  65. // Read Button
  66. state = digitalRead(trigger);
  67. // Lid Down
  68. if (state == LOW) {
  69. digitalWrite(led, LOW);
  70. // Lid Down After Open Then..
  71. if (hold_state == 1) {
  72. delay(5000);
  73. freshen();
  74. hold_state = 0; // reset
  75. }
  76. // Lid Open
  77. } else if (state == HIGH) {
  78. hold_state = 1;
  79. digitalWrite(led, HIGH);
  80. }
  81. // Testing
  82. if (Serial.available() > 0)
  83. {
  84. int cmd = Serial.parseInt();
  85. Serial.println(cmd);
  86. if (cmd == 1) {
  87. rise_up();
  88. } else if (cmd == 2) {
  89. go_down();
  90. } else if (cmd == 3) {
  91. turn_gyro();
  92. } else if (cmd == 4) {
  93. freshen();
  94. }
  95. }
  96. delay(1);
  97. }
  98. // Whole Shabang
  99. void freshen() {
  100. rise_up();
  101. delay(2000);
  102. turn_gyro();
  103. delay(2000);
  104. go_down();
  105. }
  106. void rise_up() {
  107. for (int x = 0; x < timer_riser_up; x += 1) {
  108. riser.write(rise);
  109. track_led();
  110. // Convert to Leveler Servo
  111. level_pos = map(x, 0, timer_riser_up, down, up);
  112. level_pos = round(level_pos);
  113. level.write(level_pos);
  114. delay(500);
  115. }
  116. riser.write(riser_stop);
  117. }
  118. void go_down() {
  119. for (int x = 0; x < timer_riser_down; x += 1) {
  120. riser.write(lower);
  121. track_led();
  122. level_pos = map(x, 0, timer_riser_down, up, down);
  123. level_pos = round(level_pos);
  124. level.write(level_pos);
  125. delay(500);
  126. }
  127. riser.write(riser_stop);
  128. }
  129. void turn_gyro() {
  130. // Spin Up Gyro
  131. for (gyro_pos = gyro_stop; gyro_pos >= rotate; gyro_pos -= 1) {
  132. gyro.write(gyro_pos);
  133. delay(50);
  134. }
  135. delay(timer_rotate_initial);
  136. // Activate Spark
  137. digitalWrite(relay, HIGH);
  138. delay(timer_rotate);
  139. digitalWrite(relay, LOW);
  140. gyro.write(gyro_stop);
  141. }
  142. void track_led() {
  143. colorFWD(0x00, 0x00, 0xff, 100);
  144. colorFWD(0x00, 0x00, 0x00, 100);
  145. }
  146. void colorFWD(byte red, byte green, byte blue, int SpeedDelay) {
  147. for (uint16_t i = 0; i < NUM_LEDS; i++) {
  148. setPixel(i, red, green, blue);
  149. showStrip();
  150. delay(SpeedDelay);
  151. }
  152. }
  153. void showStrip() {
  154. #ifdef ADAFRUIT_NEOPIXEL_H
  155. // NeoPixel
  156. strip.show();
  157. #endif
  158. #ifndef ADAFRUIT_NEOPIXEL_H
  159. // FastLED
  160. FastLED.show();
  161. #endif
  162. }
  163. void setPixel(int Pixel, byte red, byte green, byte blue) {
  164. #ifdef ADAFRUIT_NEOPIXEL_H
  165. // NeoPixel
  166. strip.setPixelColor(Pixel, strip.Color(red, green, blue));
  167. #endif
  168. #ifndef ADAFRUIT_NEOPIXEL_H
  169. // FastLED
  170. leds[Pixel].r = red;
  171. leds[Pixel].g = green;
  172. leds[Pixel].b = blue;
  173. #endif
  174. }

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.01642