i am new in coding or even arduino overall, and so i need help to write my code
i am attaching a stepper motor to a valve to control steam flow. the input would be temperature from a thermocouple. i would need some PID as to make my valve able to control the flow proportionally.
i've read some PID libraries, but it states that i need to define only 1 pin as an output. from what i know, stepper motor needs 2 pins as their input, which is the Pulse pin, and the Direction pin.
i also has downloaded accelstepper to help me control the motor, and so i know that i can control the motor by using mystepper.step (number of steps), am i able to use this variable to be the output of the PID library ?
this might be the thing that i need, but still i don't know how to make the output of this library to be the input of my stepper motor.
/********************************************************
* PID Basic Example
* Reading analog input 0 to control analog PWM output 3
********************************************************/
#include <PID_v1.h>
#define PIN_INPUT 0
#define PIN_OUTPUT 3
//Define Variables we'll be connecting to
double Setpoint, Input, Output;
//Specify the links and initial tuning parameters
double Kp=2, Ki=5, Kd=1;
PID myPID(&Input, &Output, &Setpoint, Kp, Ki, Kd, DIRECT);
void setup()
{
//initialize the variables we're linked to
Input = analogRead(PIN_INPUT);
Setpoint = 100;
//turn the PID on
myPID.SetMode(AUTOMATIC);
}
void loop()
{
Input = analogRead(PIN_INPUT);
myPID.Compute();
analogWrite(PIN_OUTPUT, Output);
}
i do know that i can control the max and min PID output, as to limit my stepper motor movement, but yet to know how to make it as an input for my stepper motor. thanks for the help guys, really meant something for me ![]()