Arduino Back Scratcher Plotter


1. Arduino Uno
2. Bluetooth Module
3. (2) Servos
4. Motor
5. Cardboard
6. String
7. Masking Tape
8. Power Supply
9. Pulley
10. MIT App Inventor


  1. // Back Scratcher Plotter
  2. // pkvi
  3. #include <Servo.h>
  4. #include <Stepper.h>
  5. // Scratcher
  6. const int stepsrev = 32;
  7. Stepper scratch(stepsrev, 2, 4, 3, 5);
  8. // For Bluetooth Data
  9. String readString, xaxisdata, yaxisdata;
  10. // X Axis
  11. Servo xaxis;
  12. // Y Axis
  13. Servo yaxis;
  14. int xpos = 90;
  15. int ypos = 90; // Stall
  16. int stall = 90;
  17. int yup = 75;
  18. int ydown = 105;
  19. int pos = 90;
  20. void setup() {
  21. Serial.begin(9600);
  22. // Max(?) Speed
  23. scratch.setSpeed(800);
  24. xaxis.attach(6);
  25. yaxis.attach(7);
  26. xaxis.write(xpos);
  27. yaxis.write(ypos);
  28. }
  29. void loop() {
  30. // Bluetooth Data X-Y Axis String?
  31. while (Serial.available()) {
  32. delay(10);
  33. if (Serial.available() > 0) {
  34. char c = Serial.read();
  35. readString += c;
  36. }
  37. }
  38. if (readString.length() > 0) {
  39. // Serial.println(readString);
  40. // X-Y Axis Combined Sent (ex. 368124)
  41. // First 3 Digits
  42. xaxisdata = readString.substring(0, 3);
  43. // Next 3 Digits
  44. yaxisdata = readString.substring(4, 6);
  45. // Convert String to Int
  46. int prexpos = xaxisdata.toInt();
  47. int preypos = yaxisdata.toInt();
  48. // X-Y Based on 480x800 Phone Dimension & MIT App
  49. // X 100 to 350 High 170 to 320 Low
  50. // Y 220 to 560
  51. // Map X to xPos (Actual)
  52. xpos = map(prexpos, 100, 350, 120, 60);
  53. // Map Y to yPos (Delay)
  54. ypos = map(preypos, 220, 560, 0, 6300);
  55. }
  56. // Final Routine
  57. if (readString.length() > 0) {
  58. if (xpos > 90) {
  59. for (pos = 90; pos <= xpos; pos += 1) {
  60. xaxis.write(pos);
  61. delay(40);
  62. }
  63. }
  64. else if (xpos < 90) {
  65. for (pos = 90; pos >= xpos; pos -= 1) {
  66. xaxis.write(pos);
  67. delay(40);
  68. }
  69. }
  70. yaxis.write(yup);
  71. delay(ypos);
  72. yaxis.write(stall);
  73. // Scratch 2048 Steps = 1 Revolution (2 Up/Down)
  74. // Used Stepper bcz Spare Parts -- Sigh!
  75. // 2048 x 7 Seconds = 14336 Steps
  76. scratch.step(14336);
  77. // Return to Start
  78. if (xpos > 90) {
  79. for (pos = xpos; pos >= xpos; pos -= 1) {
  80. xaxis.write(pos);
  81. delay(40);
  82. }
  83. }
  84. else if (xpos < 90) {
  85. for (pos = xpos; pos <= xpos; pos += 1) {
  86. xaxis.write(pos);
  87. delay(40);
  88. }
  89. }
  90. yaxis.write(ydown);
  91. delay(ypos);
  92. yaxis.write(stall);
  93. }
  94. // Reset
  95. readString = "";
  96. }

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