FINAL PROJECT:Pour For Dalao

make a water dispenser

the idea comes from a emoji in our comunication

the principle is after checking the water level in the cap, the dispenser will pour the water until the cap is full.

>the components are water sensor and step motor.

here comes the draft

design it in Rhinoceros

it is the part of 3D print

it is the part of laser curter.

after the prototype finished, here is a problem that the holder of sensor will fall when changing the height of holder

so I change the design

here is the final product

here is the arduino code

#include
        const int stepsPerRevolution = 500;
        int sensor= A0;
        int val = 0;
        int data = 0;
        int mark = 0;   
        // 初始化步进电机要使用的Arduino的引脚编号
        Stepper myStepper(stepsPerRevolution, 8, 9, 10, 11);
 
        void setup()
        {
                // 设置转速,单位r/min
                myStepper.setSpeed(30);
 
                // 初始化串口
                Serial.begin(9600);
        }
 
        void loop()
        {
                val = analogRead(sensor);
                if(val >150 and mark == 1){
                // 顺时针一次旋转
                Serial.println("counterclockwise");
                myStepper.step(-stepsPerRevolution);
                mark = 0;
                delay(300);
                }
                if(val <150 and mark == 0){
                // 逆时针一次旋转
                Serial.println("clockwise");
                myStepper.step(stepsPerRevolution);
                mark = 1;
                delay(300);
                }
                data = val;
                Serial.println(data);
                delay(300);
        }