Attiny analog voltmeter problems

Hi
I've got a project the has a attiny linked directly to a vid29 stepper motor and there is a lot twitching on the needle. There is no noise on the pin of the tiny that senses the voltage but there is noise on the 4 pins that control the motor.

Is there anything that i could try to rectify this issue

Post code and wiring.

A voltmeter has 2 cables, how did you measure what?
Which power supply?
Post a photo of your project and where you connect the VM.

Using the ear, one is enough? Joking.

I have attached the code and the schematic for the circuit.

The gauge reads between 9v and 17v. The gauge is powered from a car battery.

#include <Stepper.h>
#define STEPS 720
#define COIL1 A3
#define COIL2 A2
#define COIL3 0
#define COIL4 1

#define voltIn A1

Stepper stepper (STEPS, COIL1, COIL2, COIL3, COIL4);

int pos;

void setup()
{
  stepper.setSpeed(30);
  stepper.step(180);
  pos = 0;
}

void loop()
{

  int vin = analogRead(voltIn);
  float target = (0.000943 * vin * vin) - (0.80102 * vin) + 161.168;
  int t = constrain(target, 0, 180);

  if (abs(t - pos) > 2)
  {
    if (t > pos)
    {
      stepper.step(-1);
      pos++;
    }
    else
    {
      stepper.step(1);
      pos--;
    }
  }
  
}

Voltmeter.PDF (14.4 KB)

You know that the ADC is a ratio meter?

9V to 17V is common in a car supply. Peaks can go much higher, over 50V.

The analogRead() result is never perfectly stable. It will often vary +/- 2. Taking 32 or 64 samples and averaging the total works wonders to get it more stable.

No code comments will lead you to "what the...????" at some future time.

When i scope the input voltage it is pretty stable. The needle on motor is jumping around more than 5v volts at time. Without the needle on the motor the motor can turn 360° which it's not suppose to do

Are you sure your wiring is correct - your voltage input not only connected to A1 but with an actually working wire? (do measure the voltage at the pin - where it's soldered onto the PCB of the Arduino itself - to confirm).

Another thing you should do is print the analog readings to the Serial console, to see whether the values you see there make sense. When you're at it, also print the values of pos and target.

UPDATE

I've read the analog input values on pin A1 and everything is stable and as expected.

I changed the program to use the map function and the motor moves stable but is not accurate.

So the question is what could be causing the problem in the code and how would the rest of you have wrote the code as this is the limit of what i have learned so far

Thank you

I still don't understand anything, what "needle on motor", what "accurate" motor...???

Did you look into a forum section of your language?

Why is there a second order equation to go from ADC reading to motor/needle position in your original code? What does the map() purport to do instead?

Did you already try to look at the actual, continuous stream of values for both the target position of the motor and the actual position, and if so what does it look like?

In order for me to look at serial data i need to remove the motor. I'm using a attiny85 and all pins are used on the micro.

The equation was what i had previously used on another project for reading analog input reading and it worked very well. It was worked out by another forum user.

Are there any better way to read the data

DrDiettrich:
I still don't understand anything, what "needle on motor", what "accurate" motor...???

The vid29 is a precision stepper designed for moving a needle on an analog gauge, such as you may find on the dashboard of a car. OP could have posted some images to make that clear.
Code is apparently updated but OP didn't post it; still no schematics; oh well. Wild guesses can be fun, too.

wvmarle:
Code is apparently updated but OP didn't post it; still no schematics; oh well.

I posted the schematic in a pdf file with my original code.
I've not updated the code. I'm still stuck with the code i posted. All I've done is added software serial to read the analog input on pin A1 but to do that i had to remove the output to the stepper motor.
From all my testing in seams the motor moving randomly is something in the code.

wvmarle:
Wild guesses can be fun, too.

Not for me with a poster incapable of describing his project in any meaningful way after several invitations.

DrDiettrich:
Not for me with a poster incapable of describing his project in any meaningful way after several invitations.

Sorry if i didn't explain myself properly in my first post. What more would you like to know

This topic was automatically closed 120 days after the last reply. New replies are no longer allowed.