Last active
September 27, 2023 18:14
-
-
Save nobodyguy/ac286f8ccba23211c27a604f6a0f8af9 to your computer and use it in GitHub Desktop.
Arduino PID controller with relay and DS18B20
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#include <PID_v1.h> | |
// Libraries for the DS18B20 sensor | |
#include <OneWire.h> | |
#include <DallasTemperature.h> | |
// DS18B20 on PIN 6 on the Arduino | |
#define ONE_WIRE_BUS 6 | |
//Solid state relay on PIN 5 on the Arduino | |
#define RELAY_PIN 5 | |
OneWire oneWire(ONE_WIRE_BUS); | |
DallasTemperature sensors(&oneWire); | |
//Define Variables we'll be connecting to | |
double Setpoint, Input, Output; | |
//Specify the links and initial tuning parameters | |
double Kp=5, Ki=3, Kd=3; | |
PID myPID(&Input, &Output, &Setpoint, Kp, Ki, Kd, DIRECT); | |
int WindowSize = 10000; | |
unsigned long windowStartTime; | |
void setup() | |
{ | |
pinMode(RELAY_PIN, OUTPUT); | |
digitalWrite(RELAY_PIN, LOW); | |
Serial.begin(115200); | |
Serial.println("Starting"); | |
windowStartTime = millis(); | |
//initialize the variables we're linked to | |
Setpoint = 68; | |
//tell the PID to range between 0 and the full window size | |
myPID.SetOutputLimits(0, WindowSize); | |
//turn the PID on | |
myPID.SetMode(AUTOMATIC); | |
} | |
void loop() | |
{ | |
sensors.requestTemperatures(); | |
Input = sensors.getTempCByIndex(0); | |
Serial.print("Temperature: "); | |
Serial.println(Input); | |
myPID.Compute(); | |
/************************************************ | |
* turn the output pin on/off based on pid output | |
************************************************/ | |
if (millis() - windowStartTime > WindowSize) | |
{ | |
//time to shift the Relay Window | |
windowStartTime += WindowSize; | |
} | |
if (Output < millis() - windowStartTime) | |
digitalWrite(RELAY_PIN, HIGH); | |
else | |
digitalWrite(RELAY_PIN, LOW); | |
} |
@tamasdravai13 Install Arduino PID Library via library manager.
Its sources are here: https://github.com/br3ttb/Arduino-PID-Library
thank you
nobodyguy ***@***.***> ezt írta (időpont: 2022. aug. 10.,
Sze, 13:56):
… ***@***.**** commented on this gist.
------------------------------
@tamasdravai13 <https://github.com/tamasdravai13> Install Arduino PID
Library via library manager.
Its sources are here: https://github.com/br3ttb/Arduino-PID-Library
—
Reply to this email directly, view it on GitHub
<https://gist.github.com/ac286f8ccba23211c27a604f6a0f8af9#gistcomment-4262269>,
or unsubscribe
<https://github.com/notifications/unsubscribe-auth/AJCS2AHKWUAMUG2I5IB43ADVYOKG5ANCNFSM56EGTJPA>
.
You are receiving this because you were mentioned.Message ID:
***@***.***>
--
Drávai Tamás László
Pannon Egyetem
Mechatronikai mérnök hallgató
tel:06 30 9274 400
***@***.***
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Hy. where can i find PID_v1. h file?