Power usage display

I am using code to move a step motor.

What I am trying to understand is how to print out the power usage required when doing the work.
3 volts and 1 amp was required to move the motor.

When I hold the motor on the 2nd time it moves, and force the amperage to go up to spin the motor, I would like to capture that power increase and print it out. I am not sure where to start with getting that data.

Thanks in advanced for any help.


// constants won't change. Used here to 
// set pin numbers:
const int ledPin =  13;      // the number of the LED pin

// Variables will change:
int ledState = LOW;             // ledState used to set the LED
long previousMillis = 0;        // will store last time LED was updated

// the follow variables is a long because the time, measured in miliseconds,
// will quickly become a bigger number than can be stored in an int.
long interval = 1000;           // interval at which to blink (milliseconds)

// reading sound information
int echoPin = 4;
int trigPin = 5;

#include <Stepper.h>

int stepIN1Pin = 8;
int stepIN2Pin = 9;
int stepIN3Pin = 10;
int stepIN4Pin = 11;
int stpspeed = 20;
int stepsPerRevolution = 2048;

Stepper myStepper(stepsPerRevolution, stepIN1Pin, stepIN3Pin, stepIN2Pin, stepIN4Pin);

void setup() {
  // set the digital pin as output:
  pinMode(ledPin, OUTPUT);   

  // set up serial
  // set the pinmode on our ultrasonic echo, and tric pins
  pinMode(echoPin, INPUT);
  pinMode(trigPin, OUTPUT);  
      // set the RPM

void loop() {
    float distanceCentimeters;
    int pulseLenMicroseconds;

    // bit-bang a small square wave
    // on the trig pin to start the range
    // finder
    digitalWrite(trigPin, LOW);
    digitalWrite(trigPin, HIGH);
    digitalWrite(trigPin, LOW);

    // measure the pulse length from the echo pin
    pulseLenMicroseconds = pulseIn(echoPin, HIGH);

    // calculate the distance using the speed of sound
    distanceCentimeters = pulseLenMicroseconds / 29.387 / 2;

    // print it out over serial
    if ( distanceCentimeters <= 5 && distanceCentimeters >= 0 ) {
      Serial.println("Move Slide Out until MAX distance is reached: ");
      ledState = HIGH;
      digitalWrite(ledPin, ledState);
          // step one revolution in one direction
      // wait a second
    } else if ( distanceCentimeters >= 5 && distanceCentimeters <= 10 ) {
      ledState = LOW;
      digitalWrite(ledPin, ledState);
      Serial.println("Slide is in Stop Max Distance reached.");
      //Serial.println("Slide is Out until Max Distance reached.");
    } else if (distanceCentimeters <= 0 || distanceCentimeters >= 10) {
      Serial.println("Slide is in Stop Max Distance reached.");

this kind of power, Power Calculator (rapidtables.com)?

Yes. I would like to print that information as the motor runs.

Did you try using the words "arduino measure motor current" in a internet search thingy?

yes, i didn't find anything.

you didn't find this?

There is a problem that a stepper motor takes pulses of current with each step, that current will vary during the step ( motors are inductive )
So measuring at the right time instant within the step is difficult - you really need to take several measurements in each step .
If this is just a “ nice to do “ aspect , I wouldn’t attempt it .

I need to attempt it for what i want to do...
I am here to learn how to do things like this, so for me, it is important to understand how to do it...

I did read this, but it doesn't tell me how to get the information.
a good example:

to get voltage on what you are working on... you read the voltage used by the serial port and get that by doing the following:

    // step one revolution in one direction
      volt = analogRead(13);
      Serial.println("Voltage: ");

If you were to do that sketch but substitute current “measurement” for voltage , the motor would step , then the current would fall to zero , then you would measure it , and it would be zero .

I would not know how to do it, it needs to read current whilst the step is in progress , and , as I said , the current won’t be a steady value during the duration of the step .

I want to go back in time and buy a lottery ticket , but I can’t do that either, but my reasons for wanting to do that are obvious .

I have done that, and the voltage has never been zero.
That said...
I have found a solution to what i am looking for...


To help close the thread, can you tell us your solution?

Thanks.. Tom.. :grinning: :+1: :coffee: :australia:

I have another board that i am using to monitor the draw and report the amp usage. (basically made a multi-meter).

The voltage remains , the current doesn’t !

Thanks for valuable input and shared ideas of how to accomplish the task at hand. It helped to move the conversation forward.