Codigo de Programacion de Pid en Arduino
Codigo de Programacion de Pid en Arduino
Codigo de Programacion de Pid en Arduino
#include <PID_v1.h>
#include <LiquidCrystal_I2C.h>
#include <Ultrasonic.h>
LiquidCrystal_I2C lcd(0x27, 2, 1, 0, 4, 5, 6, 7, 3, POSITIVE); // Addr, En, Rw, Rs, d4, d5, d6, d7,
backlighpin, polarity
Ultrasonic ultrasonic(13,12);
///////////////////////////////////
int du;
int du1;
int ep;
long Error0;
long Error1;
long de;
long de1;
double aux=255;
double aux1;
double aux3;
boolean aux2;
const int a = 0;
///////////////////////////////
int p=A1;
int i=A2;
int d=A3;
void setup()
lcd.begin(16,2);
Serial.begin(9600);
//Input = analogRead(0);
//Setpoint = 200;
myPID.SetMode(AUTOMATIC);
void loop()
Setpoint=analogRead(0)/4;
du1=map(du,90,580,0,255);
Input = du1;
lcd.setCursor(0, 0);
lcd.setCursor(0, 1);
lcd.print(du);
lcd.setCursor(13, 1);
lcd.print(ep);
double gap = abs(Setpoint-Input); //distance away from setpoint
if(gap<10)
else
myPID.Compute();
analogWrite(3,Output);
Serial.print(p);
Serial.print(" ");
Serial.print(i);
Serial.print(" ");
Serial.print(d);
Serial.print(" ");
Serial.print(Setpoint);
Serial.print(" ");
Serial.print(Input);
Serial.print(" ");
Serial.print(Output);
Serial.print(" ");
Serial.print(du1);
Serial.print(" ");
Serial.println(du);
Serial.print(" ");
}