About Programming
#include <PID_v1.h>
float Kp = 2.5; // İlk Oransal Kazanç
float Ki = 0; // İlk İntegral Kazanc
float Kd = 1.1; //İlk Türev Kazancı
int alt_limit = 100;
int zaman;
int rpm;
double Setpoint, Input, Output, ServoOutput;
PID myPID(&Input, &Output, &Setpoint, Kp, Ki, Kd, DIRECT);
int oku = 5;
int adim = 0;
#include <LiquidCrystal.h>
LiquidCrystal lcd(13, 12, 11, 10, 9, 8);
int motor_volt;
int kalkis = 100;
int motor_hiz = 3;
int ileri = 6;
int geri = 2;
bool tamam = false;
int hiz;
int hiz_pin = A0;
int tur;
int tur_pin = A1;
int volt;
float okunan_volt;
float m_volt;
int volt_pin = A3;
int atilan_tur = 0;
int hizimiz = 0;
int tur_say = 0;
int buton = 0;
void setup() {
lcd.begin(16, 2);
Serial.begin(9600);
Input = 0;
myPID.SetMode(AUTOMATIC);
myPID.SetOutputLimits(100, 255); // -80 ile 80 derece arası
pinMode(motor_hiz, OUTPUT);
pinMode(ileri, OUTPUT);
pinMode(geri, OUTPUT);
pinMode(A2, INPUT);
pinMode(oku, INPUT);
lcd.clear();
}
void loop() {
// lcd.clear();
Serial.println(analogRead(A3));
volt = analogRead(volt_pin);
volt = map(abs(volt), 0, 750, 0, 120);
okunan_volt = volt / 10.0;
tur = analogRead(tur_pin);
tur = map(abs(tur), 0, 1024, 0, 1002);
hiz = analogRead(hiz_pin);
hiz = map(abs(hiz), 0, 1024, 100, 256);
if (tur > 1000) tur = 1000;
lcd.setCursor(0, 0);
lcd.print("TUR= ");
if (tur < 10) lcd.print("000");
else if (tur > 9 && tur < 100) lcd.print("00");
else if (tur > 99 && tur < 1000) lcd.print("0");
lcd.print(tur);
lcd.print(" V=");
if (okunan_volt < 10) lcd.print("0");
lcd.print(okunan_volt);
lcd.setCursor(0, 1);
lcd.print("HIZ= ");
lcd.print(hiz);
digitalWrite(ileri, LOW);
digitalWrite(geri, LOW);
buton = digitalRead(A2);
if (buton == 1) {
while (buton == 1) {
buton = digitalRead(A2);
}
while (digitalRead(oku) == 0) {
lcd.setCursor(0, 0);
lcd.print("<<<<<<<<<<<<<<<<");
analogWrite(motor_hiz, 150);
digitalWrite(ileri, LOW);
digitalWrite(geri, HIGH);
}
digitalWrite(ileri, LOW);
digitalWrite(geri, LOW);
delay(100);
tamam = true;
kalkis = alt_limit;
myPID.SetOutputLimits(alt_limit, hiz);
analogWrite(motor_hiz, 150);
while (kalkis < hiz) {
digitalWrite(ileri, HIGH);
digitalWrite(geri, LOW);
if (tur > 1000) tur = 1000;
lcd.setCursor(0, 0);
lcd.print("TUR= ");
if (tur < 10) lcd.print("000");
else if (tur > 9 && tur < 100) lcd.print("00");
else if (tur > 99 && tur < 1000) lcd.print("0");
lcd.print(tur);
lcd.print(" /");
if (adim < 10) lcd.print("000");
else if (adim > 9 && adim < 100) lcd.print("00");
else if (adim > 99 && adim < 1000) lcd.print("0");
lcd.print(adim);
say();
kalkis++;
motor_volt = map(abs(kalkis), 0, 255, 0, volt);
m_volt = motor_volt / 10.0;
analogWrite(motor_hiz, kalkis);
lcd.setCursor(0, 1);
lcd.print("V");
if (m_volt < 10) lcd.print("0");
lcd.print(m_volt, 1);
lcd.print(" H=");
lcd.print(hiz);
lcd.print("/0");
if (kalkis < 10) lcd.print("00");
else if (kalkis > 9 && kalkis < 100) lcd.print("0");
lcd.print(kalkis);
}
while (tamam == true) {
Setpoint = tur; // olması gereken deger
Input = adim; // güncel deger
myPID.Compute();
ServoOutput = Output; //ayar için değişken değer
analogWrite(motor_hiz, Output);
digitalWrite(ileri, HIGH);
digitalWrite(geri, LOW);
motor_volt = map(abs(Output), 0, 255, 0, volt);
m_volt = motor_volt / 10.0;
say();
if (tur > 1000) tur = 1000;
lcd.setCursor(0, 0);
lcd.print("TUR= ");
if (tur < 10) lcd.print("000");
else if (tur > 9 && tur < 100) lcd.print("00");
else if (tur > 99 && tur < 1000) lcd.print("0");
lcd.print(tur);
lcd.print(" /");
if (adim < 10) lcd.print("000");
else if (adim > 9 && adim < 100) lcd.print("00");
else if (adim > 99 && adim < 1000) lcd.print("0");
lcd.print(adim);
lcd.setCursor(0, 1);
lcd.print("V");
if (m_volt < 10) lcd.print("0");
lcd.print(m_volt, 1);
lcd.print(" H=");
lcd.print(hiz);
lcd.print("/0");
if (Output < 10) lcd.print("00");
else if (Output > 9 && Output < 100) lcd.print("0");
lcd.print(Output);
}
lcd.clear();
}
}
void say() {
while (digitalRead(A2) == 1) {
Serial.print(digitalRead(A2));
Serial.print(" sewnsor ");
Serial.println(digitalRead(5));
digitalWrite(ileri, LOW);
digitalWrite(geri, LOW);
lcd.setCursor(0, 0);
lcd.print("DURDURMA BUTONA ");
lcd.setCursor(0, 1);
lcd.print("BASILDI !!! . ");
delay(100);
lcd.setCursor(0, 0);
lcd.print("DURDURMA BUTONA ");
lcd.setCursor(0, 1);
lcd.print("BASILDI !!! .. ");
delay(100);
lcd.setCursor(0, 0);
lcd.print("DURDURMA BUTONA ");
lcd.setCursor(0, 1);
lcd.print("BASILDI !!! ...");
delay(100);
}
if (atilan_tur <= tur * 5) {
if (digitalRead(oku) == 1) {
atilan_tur++;
while (digitalRead(oku) == 1) {
Serial.print(" sewnsor ");
Serial.println(digitalRead(5));
}
}
}
adim = atilan_tur / 5;
if (atilan_tur > tur * 5) {
digitalWrite(ileri, LOW);
digitalWrite(geri, LOW);
tamam = false;
hizimiz = 0;
atilan_tur = 0;
delay(5000);
lcd.clear();
}
//delay(200);
}