Tacobot


Arduino Uno
A4988 Motor Controllers (3)
TIP120 (2) or Dual Replay Module
HC-05 Bluetooth Module
Nema 17 Stepper Motor (2)
28BYJ-48 Stepper Motor
MG996R Servo
MG90S Servo (2)
5V Liquid Pump (2)
One Way Value (2)
Photoresistor
220 Resistor (2)
Lever Switch
Neopixels
12V to 5V Voltage Divider (2)
12V 30W Power Supply
Ball Bearings
Scavenged 3D printer parts






  1. /*
  2. tacobot (0.2)
  3. pkvi
  4. 0 TX BT
  5. 1 RX BT
  6. 2 Sleep
  7. 3 (8) Servo Disp
  8. 4 (7) Neopixel Disp
  9. 5 (6) Servo Flip
  10. 6 Dir Y-Axis (14->A0)
  11. 7 (4) Servo Rotate
  12. 8 (3) Neopixel Plate
  13. 9 TIP120 1 (Sauce 1)
  14. 10 TIP120 2 (Sauce 2)
  15. 11 (2) Coms (AG 0) -->
  16. 12 (1) Coms (AG 1) -->
  17. 13 (0) Limit Plate
  18. A0 (5) Light Sensor
  19. 15 Step Y-Axis
  20. 16 Dir X-Axis
  21. 17 Step X-Axis
  22. 18 Dir Disp
  23. 19 Step Disp
  24. new_order[start(1), shell(1|2), order(1-9]
  25. 86 cancel
  26. 68 fire
  27. 77 add-on
  28. 99 repeat
  29. */
  30. #include <AccelStepper.h>
  31. #include <VarSpeedServo.h>
  32. #include <FastLED.h>
  33. // stepper data
  34. // (driver, step, dir)
  35. AccelStepper disp_step(1, 19, 18);
  36. AccelStepper plate_x(1, 17, 16);
  37. AccelStepper plate_y(1, 15, 6);
  38. const int sleep = 2;
  39. const int limit_plate = 13;
  40. // long disp_homing = -1;
  41. long plate_homing = -1;
  42. // 1/4 steps 1600 2400
  43. int disp_pos[9] = {0, 0, 400, 800, 1200, 1600, 2000, 2400, 2800};
  44. // 1/4 1600 2400
  45. const long plate_tort_one = 4250;
  46. const long plate_feed = 3500;
  47. const long plate_disp = 0;
  48. // 1/4 13000 20000
  49. const long plate_in = 0;
  50. const long plate_out = 13500;
  51. // servo data
  52. VarSpeedServo servo_disp;
  53. VarSpeedServo servo_rotate;
  54. VarSpeedServo servo_flip;
  55. const int servo_disp_pin = 3;
  56. const int servo_rotate_pin = 7;
  57. const int servo_flip_pin = 5;
  58. const int s_r_forward = 107;
  59. const int s_r_turn = 12;
  60. const int s_f_down = 158;
  61. const int s_f_up = 115;
  62. const int s_d_top = 6;
  63. const int s_d_bottom = 179;
  64. const int sauce_one = 9;
  65. const int sauce_two = 10;
  66. const int s_d_sauce_one = 300;
  67. const int s_d_sauce_two = 300;
  68. int servo_disp_pos = 0;
  69. // sensor data
  70. const int light = A0;
  71. const int light_covered = 380;
  72. const int light_uncovered = 250;
  73. // display data
  74. #define num_leds_disp 7
  75. CRGB leds_disp[num_leds_disp];
  76. #define leds_pin_disp 4
  77. #define num_leds_plate 2
  78. CRGB leds_plate[num_leds_plate];
  79. #define leds_pin_plate 8
  80. // communication
  81. int bt_int;
  82. int start = 0;
  83. int shell = 0;
  84. int new_order[16];
  85. int last_order[16];
  86. int array_pos = 0;
  87. int where = 0;
  88. int when = 0;
  89. int addon = 0;
  90. const int com_one = 11;
  91. const int com_two = 12;
  92. void setup() {
  93. Serial.begin(9600);
  94. Serial.println("Tacobot: Loading");
  95. // prevent a4988 float
  96. pinMode(sleep, OUTPUT);
  97. digitalWrite(sleep, LOW);
  98. digitalWrite(15, LOW);
  99. digitalWrite(17, LOW);
  100. digitalWrite(19, LOW);
  101. delay(500);
  102. pinMode(limit_plate, INPUT_PULLUP);
  103. pinMode(sauce_one, OUTPUT);
  104. pinMode(sauce_two, OUTPUT);
  105. digitalWrite(sauce_one, HIGH);
  106. digitalWrite(sauce_two, HIGH);
  107. pinMode(com_one, OUTPUT);
  108. pinMode(com_two, OUTPUT);
  109. digitalWrite(com_one, LOW);
  110. digitalWrite(com_two, LOW);
  111. Serial.println("Tacobot: Zeroing");
  112. FastLED.addLeds<WS2812B, leds_pin_disp, RGB>(leds_disp, num_leds_disp);
  113. FastLED.addLeds<WS2812B, leds_pin_plate, RGB>(leds_plate, num_leds_plate);
  114. setAll_plate(0, 0, 0xff);
  115. colorWipe(0, 0, 0xff, 100);
  116. // home servos
  117. // zero steppers
  118. homing();
  119. setAll_plate(0, 0, 0);
  120. Serial.println("Tacobot: Ready");
  121. }
  122. void loop() {
  123. // waiting display
  124. colorWipe(0, 0, 0xff, 200);
  125. colorWipe(0, 0, 0, 200);
  126. // listen
  127. if (Serial.available() > 0) {
  128. bt_int = Serial.parseInt();
  129. }
  130. // add items until '68'
  131. if (shell != 0 && bt_int != 0) {
  132. // escape = 86
  133. if (bt_int == 86) {
  134. // clear array
  135. for (byte p = 0; p < 16; p++) {
  136. new_order[p] = 0;
  137. }
  138. // reset values
  139. bt_int = 0;
  140. shell = 0;
  141. start = 0;
  142. addon = 0;
  143. where = 0;
  144. when = 0;
  145. array_pos = 0;
  146. Serial.println("Tacobot: 86'd");
  147. }
  148. // fire order = 68
  149. if (bt_int == 68) {
  150. Serial.println("Tacobot: Fired");
  151. fire_order();
  152. // copy to last_order
  153. memmove(last_order, new_order, 15);
  154. // flush new_order
  155. for (byte p = 0; p < 16; p++) {
  156. new_order[p] = 0;
  157. }
  158. bt_int = 0;
  159. shell = 0;
  160. start = 0;
  161. addon = 0;
  162. where = 0;
  163. when = 0;
  164. array_pos = 0;
  165. }
  166. // com add-on = 77
  167. if (bt_int == 77) {
  168. addon = 1;
  169. }
  170. if (bt_int > 0 && bt_int < 15) {
  171. Serial.println(bt_int);
  172. new_order[array_pos] = bt_int;
  173. array_pos++;
  174. }
  175. }
  176. // repeat = 99
  177. if (bt_int == 99) {
  178. Serial.print("Tacobot: Reorder");
  179. // copy last to new
  180. memmove(new_order, last_order, 15);
  181. fire_order();
  182. // copy to last_order
  183. memmove(last_order, new_order, 15);
  184. // flush new_order
  185. for (byte p = 0; p < 16; p++) {
  186. new_order[p] = 0;
  187. }
  188. bt_int = 0;
  189. shell = 0;
  190. start = 0;
  191. addon = 0;
  192. where = 0;
  193. when = 0;
  194. array_pos = 0;
  195. }
  196. // actions reversed due to if sequence
  197. // 1 = soft
  198. // 2 = hard
  199. if (start == 1 && shell == 0) {
  200. if (bt_int == 1 || bt_int == 2) {
  201. shell = bt_int;
  202. if (bt_int == 1) {
  203. Serial.println("Soft Shell");
  204. } else if (bt_int == 2) {
  205. Serial.println("Hard Shell");
  206. }
  207. }
  208. }
  209. // initiate process
  210. // bt_int = 1
  211. if (new_order[0] == 0 && start == 0 && bt_int == 1) {
  212. start = 1;
  213. Serial.println("Tacobot: Ordering");
  214. }
  215. // flush
  216. bt_int = 0;
  217. delay(1);
  218. }
  219. void fire_order() {
  220. colorWipe(0, 0, 0, 100);
  221. // signal shell
  222. // soft now only
  223. digitalWrite(com_one, HIGH);
  224. delay(750);
  225. digitalWrite(com_one, LOW);
  226. // turn plate
  227. servo_rotate.attach(servo_rotate_pin);
  228. servo_flip.attach(servo_flip_pin);
  229. servo_disp.attach(servo_disp_pin);
  230. delay(50);
  231. servo_rotate.write(s_r_turn, 60, true);
  232. // move to rail
  233. digitalWrite(sleep, HIGH);
  234. setAll_plate(0, 0, 0xff);
  235. plate_x.moveTo(plate_tort_one);
  236. while (plate_x.distanceToGo() != 0) {
  237. plate_x.run();
  238. }
  239. // extend plate
  240. plate_y.moveTo(plate_out);
  241. while (plate_y.distanceToGo() != 0) {
  242. plate_y.run();
  243. }
  244. digitalWrite(sleep, LOW);
  245. // wait for light sensor
  246. while (analogRead(light) < light_covered) {
  247. // ...
  248. }
  249. digitalWrite(sleep, HIGH);
  250. delay(10);
  251. // retract plate
  252. plate_y.moveTo(plate_in);
  253. while (plate_y.distanceToGo() != 0) {
  254. plate_y.run();
  255. }
  256. // move back
  257. plate_x.moveTo(plate_feed);
  258. while (plate_x.distanceToGo() != 0) {
  259. plate_x.run();
  260. }
  261. // turn and flip
  262. servo_flip.write(s_f_up, 60, false);
  263. servo_rotate.write(s_r_forward, 60, true);
  264. delay(10);
  265. // move to disp
  266. plate_x.moveTo(plate_disp);
  267. while (plate_x.distanceToGo() != 0) {
  268. plate_x.run();
  269. }
  270. colorWipe(0, 0, 0xff, 100);
  271. // cycle order
  272. for (int q = 0; q < 15; q++) {
  273. where = new_order[q];
  274. // 0 = null
  275. // 5 = sauce 1
  276. // 10 = sauce 2 -> when = 5
  277. if (where > 0 && where != 5 && where != 10) {
  278. when = disp_pos[where];
  279. disp_step.moveTo(when);
  280. while (disp_step.distanceToGo() != 0) {
  281. disp_step.run();
  282. }
  283. delay(750);
  284. servo_drop_food();
  285. delay(750);
  286. } else if (where == 5 || where == 10) {
  287. when = disp_pos[5];
  288. disp_step.moveTo(when);
  289. while (disp_step.distanceToGo() != 0) {
  290. disp_step.run();
  291. }
  292. delay(800);
  293. servo_drop_sauce(where);
  294. delay(800);
  295. }
  296. delay(50);
  297. }
  298. // reset disp pos
  299. disp_step.moveTo(0);
  300. while (disp_step.distanceToGo() != 0) {
  301. disp_step.run();
  302. }
  303. colorWipe(0, 0, 0, 100);
  304. setAll_plate(0, 0, 0xff);
  305. // move tray back
  306. plate_x.moveTo(plate_feed);
  307. while (plate_x.distanceToGo() != 0) {
  308. plate_x.run();
  309. }
  310. // add on?
  311. if (addon == 1) {
  312. digitalWrite(com_two, HIGH);
  313. delay(1000);
  314. digitalWrite(com_two, LOW);
  315. }
  316. // extend tray
  317. plate_y.moveTo(plate_out);
  318. while (plate_y.distanceToGo() != 0) {
  319. plate_y.run();
  320. }
  321. delay(10);
  322. digitalWrite(sleep, LOW);
  323. // wait for light sensor
  324. while (analogRead(light) > light_uncovered) {
  325. // ...
  326. }
  327. // flip down
  328. servo_flip.write(s_f_down, 60, true);
  329. digitalWrite(sleep, HIGH);
  330. delay(10);
  331. // retract tray
  332. plate_y.moveTo(plate_in);
  333. while (plate_y.distanceToGo() != 0) {
  334. plate_y.run();
  335. }
  336. digitalWrite(sleep, LOW);
  337. servo_disp.detach();
  338. servo_flip.detach();
  339. servo_rotate.detach();
  340. }
  341. void servo_drop_food() {
  342. if (servo_disp_pos == 0) {
  343. servo_disp.write(s_d_bottom, 200, true);
  344. servo_disp_pos = 1;
  345. } else if (servo_disp_pos == 1) {
  346. servo_disp.write(s_d_top, 200, true);
  347. servo_disp_pos = 0;
  348. }
  349. }
  350. void servo_drop_sauce(int which) {
  351. if (which == 5) {
  352. digitalWrite(sauce_one, LOW);
  353. delay(s_d_sauce_one);
  354. digitalWrite(sauce_one, HIGH);
  355. } else if (which == 10) {
  356. digitalWrite(sauce_two, LOW);
  357. delay(s_d_sauce_two);
  358. digitalWrite(sauce_two, HIGH);
  359. }
  360. }
  361. void showStrip() {
  362. FastLED.show();
  363. }
  364. // neo disp
  365. void setPixel_disp(int Pixel_disp, byte red_disp, byte green_disp, byte blue_disp) {
  366. leds_disp[Pixel_disp].r = red_disp;
  367. leds_disp[Pixel_disp].g = green_disp;
  368. leds_disp[Pixel_disp].b = blue_disp;
  369. }
  370. void setAll_disp(byte red_disp, byte green_disp, byte blue_disp) {
  371. for (int i = 0; i < num_leds_disp; i++ ) {
  372. setPixel_disp(i, red_disp, green_disp, blue_disp);
  373. }
  374. showStrip();
  375. }
  376. void colorWipe(byte red_disp, byte green_disp, byte blue_disp, int SpeedDelay_disp) {
  377. for (uint16_t i = 0; i < num_leds_disp; i++) {
  378. setPixel_disp(i, red_disp, green_disp, blue_disp);
  379. showStrip();
  380. delay(SpeedDelay_disp);
  381. }
  382. }
  383. // neo plate
  384. void setPixel_plate(int Pixel_plate, byte red_plate, byte green_plate, byte blue_plate) {
  385. leds_plate[Pixel_plate].r = red_plate;
  386. leds_plate[Pixel_plate].g = green_plate;
  387. leds_plate[Pixel_plate].b = blue_plate;
  388. }
  389. void setAll_plate(byte red_plate, byte green_plate, byte blue_plate) {
  390. for (int j = 0; j < num_leds_plate; j++ ) {
  391. setPixel_plate(j, red_plate, green_plate, blue_plate);
  392. }
  393. showStrip();
  394. }
  395. void homing() {
  396. // home servos
  397. servo_disp.attach(servo_disp_pin);
  398. servo_rotate.attach(servo_rotate_pin);
  399. servo_flip.attach(servo_flip_pin);
  400. delay(100);
  401. servo_disp.write(s_d_top, 200, true);
  402. servo_rotate.write(s_r_forward, 60, true);
  403. servo_flip.write(s_f_down, 60, true);
  404. delay(500);
  405. servo_disp.detach();
  406. servo_flip.detach();
  407. delay(1000);
  408. Serial.println("Servos Adjusted");
  409. // home disp
  410. colorWipe(0, 0xff, 0, 100);
  411. digitalWrite(sleep, HIGH);
  412. delay(500);
  413. disp_step.setCurrentPosition(0);
  414. disp_step.setMaxSpeed(1600);
  415. disp_step.setAcceleration(2400);
  416. disp_step.moveTo(disp_pos[4]);
  417. while (disp_step.distanceToGo() != 0) {
  418. disp_step.run();
  419. }
  420. delay(500);
  421. disp_step.moveTo(0);
  422. while (disp_step.distanceToGo() != 0) {
  423. disp_step.run();
  424. }
  425. digitalWrite(sleep, LOW);
  426. colorWipe(0, 0, 0, 100);
  427. delay(500);
  428. // home plate
  429. setAll_plate(0, 0xff, 0);
  430. plate_x.setMaxSpeed(400.0);
  431. plate_x.setAcceleration(400.0);
  432. digitalWrite(sleep, HIGH);
  433. delay(100);
  434. while (digitalRead(limit_plate)) {
  435. plate_x.moveTo(plate_homing);
  436. plate_homing--;
  437. plate_x.run();
  438. }
  439. plate_x.setCurrentPosition(0);
  440. plate_x.setMaxSpeed(400.0);
  441. plate_x.setAcceleration(400.0);
  442. plate_homing = 1;
  443. while (!digitalRead(limit_plate)) {
  444. plate_x.moveTo(plate_homing);
  445. plate_x.run();
  446. plate_homing++;
  447. }
  448. plate_x.setCurrentPosition(0);
  449. plate_x.setMaxSpeed(1600);
  450. plate_x.setAcceleration(2400);
  451. plate_feed_pos();
  452. servo_rotate.write(s_r_forward, 60, true);
  453. delay(250);
  454. servo_rotate.detach();
  455. plate_y.setCurrentPosition(0);
  456. plate_y.setMaxSpeed(13000);
  457. plate_y.setAcceleration(20000);
  458. }
  459. void plate_feed_pos() {
  460. digitalWrite(sleep, HIGH);
  461. plate_x.moveTo(plate_feed);
  462. while (plate_x.distanceToGo() != 0) {
  463. plate_x.run();
  464. }
  465. delay(50);
  466. digitalWrite(sleep, LOW);
  467. }

Menu
Index
Engineering
Entertainment
Literature
Miscellaneous
Contact
Search
tiktok.com/@pkvi.xyz
buymeacoffee.com/pkvi
scored.co/u/-pkvi-
Miter
Why Ayh?
Miter
@pkvi
"...may not meet professional standards."
13 miters
122 tenons
Subscribe