Skip to content

Week 7

Assignment

  • Connect a new output device that you haven’t used before.
  • Design a program that integrates at least one input and one output device.
  • Measure the power consumption of an output device.

Input device

I've had a TTP223 capacitive sensor lying around for a while, and I finally decided to try it out. I can also use it in my final project, but that's still in decision process.

Output device

For an output device, I chose a stepper motor, since it is necessary in my final project. I need at least five of those motors in my final project, but they are quite expensive, so I disassembled my old Creality 3D printer and used their Creality 42-40. I could not find any datasheet for this model, but I expected it to behave the same way as any other Nema 17 stepper.

I am still kinda new to electronics, so I don't get how voltages and current work in steppers. The stepper I used is supposed to have these parameters.

Specification Value
Step Angle 1.8°
Steps per Revolution 200
Nominal Voltage 4.83V
Current Rating 1.5A
Rated Speed 1-1000 RPM
Rated Torque 0.4 Nm

But I've read somewhere, that the voltage might not matter? I don't get it. I supplied 12 volts, prayed for the best, and it worked.

Stepper consumption

I followed this tutorial for A4988 driver. and measured the current using this method: Circuit diagram

I measured 0.5 amps. The stepper has rated current 1.5A, but I did not have the recommended capacitor for stepper power supply, so I thought this setting would prevent the voltage spikes. Current measurement

Code

#include <AccelStepper.h>

#define SENSOR_LEFT 12
#define SENSOR_RIGHT 11

#define DIR_PIN 2
#define STEP_PIN 3

#define MOTOR_INTERFACE_TYPE 1

const int stepsPerRevolution = 200;

AccelStepper myStepper(MOTOR_INTERFACE_TYPE, STEP_PIN, DIR_PIN);

void setup() {
    myStepper.setMaxSpeed(4000);
    myStepper.setAcceleration(4000);
    pinMode(SENSOR_LEFT, INPUT);
    pinMode(SENSOR_RIGHT, INPUT);
}

void loop() {
    static bool leftPrev = false;
    static bool rightPrev = false;

    bool leftTouched = digitalRead(SENSOR_LEFT) == HIGH;
    bool rightTouched = digitalRead(SENSOR_RIGHT) == HIGH;

    if (!leftPrev && leftTouched) {
        myStepper.move(-stepsPerRevolution / 4);
    }
    if (!rightPrev && rightTouched) {
        myStepper.move(stepsPerRevolution / 4);
    }

    leftPrev = leftTouched;
    rightPrev = rightTouched;

    while (myStepper.distanceToGo() != 0) {
        myStepper.run();
    }
}

Schema

Current measurement

Result

Future work

The joint that connects the stepper and the Rubik's cube is too loose. I need to design it with little to no tolerance in order for the cube to have proper 90° rotations.