Simone Slouchy


1. Arduino Uno
2. Stepper Motor (28BYJ-48)
3. Stepper Driver (ULN2003)
4. Ultrasonic Sensor (HC-SR04)
5. (2) Servos (High Torque)
6. Cardboard
7. Spite


  1. // Simone Slouchy (3)
  2. // pkvi
  3. #include <Servo.h>
  4. #include <Stepper.h>
  5. // Hand
  6. const int stepsPerRevolution = 64;
  7. Stepper hander(stepsPerRevolution, 19, 17, 18, 16);
  8. // Shoulder
  9. Servo shoulder;
  10. // Elbow (
  11. Servo elbow;
  12. // Sensor
  13. #define trigPin 2
  14. #define echoPin 3
  15. // Servo Position
  16. int pos = 30;
  17. // What Action Next?
  18. int state = 0;
  19. // Distance Adjust (Version 2)
  20. // int newdis = 0;
  21. // Serial For Testing
  22. char incom = 0;
  23. void setup() {
  24. Serial.begin(9600);
  25. shoulder.attach(12);
  26. elbow.attach(5);
  27. pinMode(trigPin, OUTPUT);
  28. pinMode(echoPin, INPUT);
  29. // Set Start Position (Servo)
  30. shoulder.write(15);
  31. elbow.write(30);
  32. // Stepper Starts 0
  33. }
  34. void loop() {
  35. // Sensor Sequence
  36. long duration, distance;
  37. digitalWrite(trigPin, LOW);
  38. delayMicroseconds(2);
  39. digitalWrite(trigPin, HIGH);
  40. delayMicroseconds(10);
  41. digitalWrite(trigPin, LOW);
  42. duration = pulseIn(echoPin, HIGH);
  43. // Centimeter Conversion
  44. distance = (duration / 2) / 29.1;
  45. // Print for Testing
  46. Serial.print(distance); Serial.println(" cm");
  47. // IF Slouching || > 5cm
  48. // But Not NOT In Chair || < 40cm
  49. if (distance > 5 && distance < 40) {
  50. if (state == 0) {
  51. tap();
  52. // Change State
  53. state = 1;
  54. }
  55. else if (state == 1) {
  56. grab();
  57. state = 2;
  58. }
  59. else if (state == 2) {
  60. assault();
  61. // Reset
  62. state = 0;
  63. }
  64. }
  65. delay(5000);
  66. // Serial For Testing
  67. // if (Serial.available() > 0) {
  68. // incom = Serial.read();
  69. // if (incom == '1') {
  70. // tap();
  71. // }
  72. // else if (incom == '2') {
  73. // grab();
  74. // }
  75. // else if (incom == '3') {
  76. // assault();
  77. // }
  78. // }
  79. // Reset Value (Else)
  80. incom = 0;
  81. }
  82. void tap() {
  83. // Map Distance for Extension (Coming Soon)
  84. // newdis = map(distance, 5, 20, 70, 110);
  85. // Extend Shoulder and Forearm
  86. // Open Hand
  87. for (int i = 0; i <= 600; i++) {
  88. hander.step(-1);
  89. Serial.println("Open");
  90. }
  91. for (pos = 15; pos <= 30; pos += 1) {
  92. shoulder.write(pos);
  93. delay(20);
  94. }
  95. for (pos = 30; pos <= 90; pos += 1) {
  96. shoulder.write(pos);
  97. elbow.write(pos);
  98. delay(20);
  99. }
  100. for (pos = 90; pos <= 145; pos += 1) {
  101. elbow.write(pos);
  102. delay(20);
  103. }
  104. for (pos = 90; pos <= 110; pos += 1) {
  105. shoulder.write(pos);
  106. delay(20);
  107. }
  108. delay(1000);
  109. // Tap
  110. for (pos = 145; pos >= 110; pos -= 1) {
  111. elbow.write(pos);
  112. delay(10);
  113. }
  114. for (pos = 110; pos <= 145; pos += 1) {
  115. elbow.write(pos);
  116. delay(10);
  117. }
  118. for (pos = 145; pos >= 110; pos -= 1) {
  119. elbow.write(pos);
  120. delay(10);
  121. }
  122. for (pos = 110; pos <= 145; pos += 1) {
  123. elbow.write(pos);
  124. delay(10);
  125. }
  126. // Fold Back
  127. for (pos = 110; pos >= 70; pos -= 1) {
  128. shoulder.write(pos);
  129. delay(50);
  130. }
  131. delay(750);
  132. for (pos = 145; pos >= 70; pos -= 1) {
  133. elbow.write(pos);
  134. delay(20);
  135. }
  136. for (pos = 70; pos >= 30; pos -= 1) {
  137. shoulder.write(pos);
  138. elbow.write(pos);
  139. delay(30);
  140. }
  141. for (pos = 30; pos >= 15; pos -= 1) {
  142. shoulder.write(pos);
  143. delay(30);
  144. }
  145. for (int i = 0; i <= 600; i++) {
  146. hander.step(1);
  147. Serial.println("Close");
  148. }
  149. }
  150. void grab() {
  151. // Open Hand
  152. for (int i = 0; i <= 600; i++) {
  153. hander.step(-1);
  154. Serial.println("Open");
  155. }
  156. for (pos = 15; pos <= 30; pos += 1) {
  157. shoulder.write(pos);
  158. delay(20);
  159. }
  160. for (pos = 30; pos <= 90; pos += 1) {
  161. shoulder.write(pos);
  162. elbow.write(pos);
  163. delay(20);
  164. }
  165. for (pos = 90; pos <= 145; pos += 1) {
  166. elbow.write(pos);
  167. delay(20);
  168. }
  169. for (pos = 90; pos <= 110; pos += 1) {
  170. shoulder.write(pos);
  171. delay(20);
  172. }
  173. delay(1000);
  174. // Close Hand
  175. for (int i = 0; i <= 250; i++) {
  176. hander.step(1);
  177. Serial.println("Close");
  178. }
  179. // Lower On Sloucher
  180. for (pos = 145; pos >= 115; pos -= 1) {
  181. elbow.write(pos);
  182. delay(30);
  183. }
  184. // Pull Back
  185. for (pos = 115; pos >= 80; pos -= 1) {
  186. shoulder.write(pos);
  187. elbow.write(pos);
  188. delay(30);
  189. }
  190. // Open Hand
  191. for (int i = 0; i <= 250; i++) {
  192. hander.step(-1);
  193. Serial.println("Open");
  194. }
  195. // Extend Forearm
  196. for (pos = 80; pos <= 145; pos += 1) {
  197. elbow.write(pos);
  198. delay(30);
  199. }
  200. // Fold Back
  201. for (pos = 80; pos >= 50; pos -= 1) {
  202. shoulder.write(pos);
  203. delay(40);
  204. }
  205. for (pos = 145; pos >= 50; pos -= 1) {
  206. elbow.write(pos);
  207. delay(30);
  208. }
  209. for (pos = 50; pos >= 30; pos -= 1) {
  210. elbow.write(pos);
  211. shoulder.write(pos);
  212. delay(40);
  213. }
  214. for (pos = 30; pos >= 15; pos -= 1) {
  215. shoulder.write(pos);
  216. delay(40);
  217. }
  218. // Close Hand
  219. for (int i = 0; i <= 600; i++) {
  220. hander.step(1);
  221. Serial.println("Close");
  222. }
  223. }
  224. void assault() {
  225. for (int i = 0; i <= 600; i++) {
  226. hander.step(-1);
  227. Serial.println("Open");
  228. }
  229. for (pos = 15; pos <= 30; pos += 1) {
  230. shoulder.write(pos);
  231. delay(20);
  232. }
  233. for (pos = 30; pos <= 90; pos += 1) {
  234. shoulder.write(pos);
  235. elbow.write(pos);
  236. delay(20);
  237. }
  238. for (pos = 90; pos <= 145; pos += 1) {
  239. elbow.write(pos);
  240. delay(20);
  241. }
  242. for (pos = 90; pos <= 110; pos += 1) {
  243. shoulder.write(pos);
  244. delay(20);
  245. }
  246. delay(1000);
  247. for (int i = 0; i <= 250; i++) {
  248. hander.step(1);
  249. Serial.println("Close");
  250. }
  251. for (pos = 145; pos >= 115; pos -= 1) {
  252. elbow.write(pos);
  253. delay(30);
  254. }
  255. for (pos = 115; pos >= 60; pos -= 1) {
  256. shoulder.write(pos);
  257. elbow.write(pos);
  258. delay(30);
  259. }
  260. for (int i = 0; i <= 250; i++) {
  261. hander.step(-1);
  262. Serial.println("Open");
  263. }
  264. for (pos = 60; pos <= 80; pos += 1) {
  265. elbow.write(pos);
  266. delay(30);
  267. }
  268. delay(1500);
  269. for (pos = 60; pos <= 80; pos += 1) {
  270. shoulder.write(pos);
  271. delay(20);
  272. }
  273. for (pos = 80; pos <= 115; pos += 1) {
  274. shoulder.write(pos);
  275. elbow.write(pos);
  276. delay(5);
  277. }
  278. for (pos = 115; pos <= 135; pos += 1) {
  279. elbow.write(pos);
  280. delay(5);
  281. }
  282. delay(500);
  283. for (pos = 115; pos >= 80; pos -= 1) {
  284. shoulder.write(pos);
  285. delay(10);
  286. }
  287. for (pos = 135; pos <= 80; pos += 1) {
  288. elbow.write(pos);
  289. delay(30);
  290. }
  291. for (pos = 80; pos >= 30; pos -= 1) {
  292. shoulder.write(pos);
  293. elbow.write(pos);
  294. delay(40);
  295. }
  296. for (pos = 30; pos >= 15; pos -= 1) {
  297. shoulder.write(pos);
  298. delay(40);
  299. }
  300. for (int i = 0; i <= 600; i++) {
  301. hander.step(1);
  302. Serial.println("Close");
  303. }
  304. }

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