├── .gitattributes ├── LICENSE ├── README.md └── TrashEatingRobot └── TrashEatingRobot.ino /.gitattributes: -------------------------------------------------------------------------------- 1 | # Auto detect text files and perform LF normalization 2 | * text=auto 3 | -------------------------------------------------------------------------------- /LICENSE: -------------------------------------------------------------------------------- 1 | BSD 3-Clause License 2 | 3 | Copyright (c) 2018, happythingsmaker 4 | All rights reserved. 5 | 6 | Redistribution and use in source and binary forms, with or without 7 | modification, are permitted provided that the following conditions are met: 8 | 9 | * Redistributions of source code must retain the above copyright notice, this 10 | list of conditions and the following disclaimer. 11 | 12 | * Redistributions in binary form must reproduce the above copyright notice, 13 | this list of conditions and the following disclaimer in the documentation 14 | and/or other materials provided with the distribution. 15 | 16 | * Neither the name of the copyright holder nor the names of its 17 | contributors may be used to endorse or promote products derived from 18 | this software without specific prior written permission. 19 | 20 | THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" 21 | AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE 22 | IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE 23 | DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE 24 | FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL 25 | DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR 26 | SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER 27 | CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, 28 | OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE 29 | OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | # TrashEatingRobot 2 | 3 | ## https://youtu.be/KfP_LfUiwdc 4 | ## http://youtube.com/EunchanPark 5 | 6 | project documentation 7 | https://eunchan.me/Hungry-Robot-1bac36202aae469e806f882e0308ce18 8 | -------------------------------------------------------------------------------- /TrashEatingRobot/TrashEatingRobot.ino: -------------------------------------------------------------------------------- 1 | // Welcome to the source code of "Hungry Robot" 2 | 3 | // YouTube Instruction 4 | // 3d printer version: https://youtu.be/KfP_LfUiwdc 5 | // paper version: https://youtu.be/3qnU8uD0utM 6 | 7 | // Documentation 8 | // https://eunchan.me/Hungry-Robot-1bac36202aae469e806f882e0308ce18 9 | 10 | // Select Arduino nano / ATmega328P (Old Bootloader) 11 | 12 | // in order to use servo motor, we need to include a library file 13 | #include 14 | 15 | // let's make an instance of Servo 16 | Servo armServo; 17 | 18 | // this function automatically runs only once when the Arduino's power up 19 | void setup() { 20 | 21 | // we use pin number 12 for control the robot. 22 | armServo.attach(12); 23 | // move the motor to default angle 24 | armServo.write(90); 25 | 26 | // pin A7 is for the distance sensor 27 | pinMode(A7, INPUT); 28 | 29 | // these 3 pins (pin0, pin1, pin13) are for turning on LEDs 30 | // Arduino nano already has 3 LEDs on these pins. 31 | pinMode(13, OUTPUT); 32 | pinMode(0, OUTPUT); 33 | pinMode(1, OUTPUT); 34 | } 35 | 36 | // in order to check coming hand, 37 | // we will keep the sensor value these variables 38 | int sensorValue = 0; 39 | int prevSensorValue = 0; 40 | 41 | // When the sensor value is hight than the THRESHOLD value, 42 | // The code will call action(); 43 | const int THRESHOLD = 360; 44 | 45 | void loop() { 46 | 47 | // read A7's analog value and asign the value into sensorValue 48 | sensorValue = analogRead(A7); 49 | 50 | // these two lines means that some object has come 51 | // from outside of Threshold to inside of it. 52 | if (prevSensorValue <= THRESHOLD) { 53 | if (sensorValue > THRESHOLD) { 54 | // It's time to action 55 | action(); 56 | } 57 | } 58 | 59 | // regardless the action, save current sensor value prevSensorValue 60 | // so that we can check the direction 61 | prevSensorValue = sensorValue; 62 | 63 | // this delay controls how often this loop is running 64 | // without this delay, this loop runs too fast 65 | // then, the differences between previous and current sensor value 66 | // can not be meaningful. 67 | delay(10); 68 | } 69 | 70 | 71 | void action() { 72 | // call this function for turning on three LEDs all together 73 | led(true); 74 | 75 | // eating sequence 76 | // wait 1000ms (1 second) 77 | delay(1000); 78 | 79 | // let's use pin12 for motor control 80 | armServo.attach(12); 81 | // let's move the motor to degree '10' (move the arm up) 82 | armServo.write(10); 83 | 84 | // wait 300 ms 85 | delay(300); 86 | 87 | // let's move the motor to degree '70' (move the arm down) 88 | armServo.write(70); 89 | delay(500); 90 | 91 | // after ate 92 | delay(100); 93 | armServo.write(50); 94 | delay(250); 95 | armServo.write(70); 96 | delay(250); 97 | armServo.write(50); 98 | delay(250); 99 | armServo.write(70); 100 | delay(250); 101 | armServo.write(50); 102 | delay(250); 103 | armServo.write(70); 104 | delay(250); 105 | armServo.write(50); 106 | delay(250); 107 | armServo.write(90); 108 | delay(250); 109 | 110 | // release arm's torque 111 | armServo.detach(); 112 | 113 | // call this function for turning off three LEDs all together 114 | led(false); 115 | } 116 | 117 | void led(bool onOff) { 118 | // pin 13's LED turns on when it is high 119 | // pin 0, 1's LED turn on when it is low 120 | if (onOff) { 121 | digitalWrite(13, HIGH); 122 | digitalWrite(0, LOW); 123 | digitalWrite(1, LOW); 124 | } else { 125 | digitalWrite(13, LOW); 126 | digitalWrite(0, HIGH); 127 | digitalWrite(1, HIGH); 128 | } 129 | } 130 | 131 | --------------------------------------------------------------------------------