Hey guys! I would like to thank anyone beforehand for any help they can give me. This is my first attempt at using Arduino or programming in general. I will try my best to be as descriptive as possible.
Before I state my problem I'd like to describe what it is I am doing. I want to create a simple PID lopp using Arduino's PID LIBRARY and control a 12v DC FAN motor. I have the fan connected to a motor shied (model in link) that I want to adjust the speed of the fan using the pid loop. I have a Hall effect sensor connected to the bottom of a arm that is blown by the fan. The pid loop has a setpoint that puts a magnetic as close to the Hall sensor as possible. I will enclose a picture of the setup for reference:
I know everything is connected correctly because I see the sensor readings in the Serial Monitor Pane:
Here is a pic of my desktop with the Serial Monitor Open:
On the right is the Output from the PID Loop and the left is the analog Hall Effect Sensor:
I also know the motor works correctly because when I use the sample code from the AFmotor library called MotorTest the fan spools up.
Here is my Code that I'm working on:
/********************************************************
* PID Basic Example
* Reading analog input 0 to control analog PWM output 3
********************************************************/
//Library packages required
#include <PID_v1.h>
#include <AFMotor.h>
//define the variable, PIN_OUTPUT 3 may not be needed?
#define PIN_INPUT A5
#define PIN_OUTPUT 3
AF_DCMotor motor(4);
//Define Variables we'll be connecting to
double Setpoint, Input, Output;
//Specify the links and initial tuning parameters
double Kp=.5, Ki=.05, Kd=.05;
PID myPID(&Input, &Output, &Setpoint, Kp, Ki, Kd, REVERSE);
void setup()
{
motor.setSpeed(200);
motor.run(RELEASE);
//initialize the variables we're linked to
Input = analogRead(PIN_INPUT);
Setpoint = 10;
Serial.begin(9600);
//turn the PID on
myPID.SetMode(AUTOMATIC);
//Setup the Serial Monitor Output correctly
Serial.print("Input");
Serial.print("\t");
Serial.print("Output");
}
//initiate PID LOOP
void loop()
{
// READ analog values from Hall Effect Sensor
Input = analogRead(PIN_INPUT)-388;
//Send the Value to the Serial Monitor for debugging
Serial.println();
Serial.print(Input);
Serial.print("\t");
//Allow the PID LIBRARY to compute the values,
myPID.Compute();
// The output value from the my.PID.Compute function will now be put into the motor.setSpeed command
motor.setSpeed(Output);
//Tell the motor to turn on and spin up using the value from the seSpeed command
motor.run(REVERSE);
// Print the PID Output to Serial Monitor for debugging
Serial.print(Output);
}
Any help would be greatly appreciated, Here is a link to a youtube video describing what Im trying to do in more detail.