Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <PID_v1.h>
- #include <LiquidCrystal.h>
- #define PTC_PIN A0
- #define POT_PIN A1
- #define LCD_ROW 2
- #define LCD_COL 16
- #define OUT_PIN 6
- // <+5V> --- <R1 150 Ohm> --- <PTC> --- <GND>
- // |
- // Analog Vin
- // 35.0°C In 275
- // 36.7°C In 278
- // 50.2°C In 297
- // 48.7°C In 278
- // 95.0°C In 360
- // 36.7°C In 278
- //Define Variables we'll be connecting to
- double Setpoint, Input, Output;
- int OutBar = 0;
- //Specify the links and initial tuning parameters
- double Kp=1, Ki=0.1, Kd=0.5;
- PID myPID(&Input, &Output, &Setpoint, Kp, Ki, Kd, DIRECT);
- // initialize the library with the numbers of the interface pins
- LiquidCrystal lcd(12, 11, 10, 5, 4, 3, 2);
- byte barElement[8] = {
- B00000,
- B00000,
- B10101,
- B10101,
- B10101,
- B10101,
- B10101,
- B10101,
- };
- //int sensorValue, setPoint = 0;
- void setup() {
- Serial.begin(9600);
- //turn the PID on
- myPID.SetMode(AUTOMATIC);
- analogReference(INTERNAL);
- lcd.createChar(0, barElement);
- // set up the LCD's number of columns and rows:
- lcd.begin(LCD_COL, LCD_ROW);
- // Print a message to the LCD.
- lcd.print("Hello World!");
- delay(500);
- // set up Timer 4 for PWM 38095 Khz (ATmega32U4)
- /*
- TCCR4A = ((1<<COM4A0) | (1<<WGM40));
- TCCR4B = (1<<CS40);
- OCR4A = 105;
- */
- }
- void loop() {
- // read the value from the sensor:
- Input = analogRead(PTC_PIN);
- Setpoint = map(analogRead(POT_PIN), 0, 1024, 0, 500);
- myPID.Compute();
- analogWrite(OUT_PIN, Output);
- // Print setpoint value to LCD
- clearRow(0);
- lcd.setCursor(0, 0);
- lcd.print("In; ");
- lcd.print((int)Input);
- lcd.print(" Set");
- lcd.print((int)Setpoint);
- // Print out status value to LCD
- clearRow(1);
- lcd.setCursor(0, 1);
- OutBar = map(Output, 0, 255, 0, 16);
- for(int bar = 0; bar <= OutBar-1; bar++){
- lcd.write(byte(0));
- }
- Serial.println(OutBar);
- delay(200);
- }
- void clearRow(int row){
- lcd.setCursor(0, row);
- for(int Column = 0; Column <LCD_COL; Column++)
- lcd.print(" ");
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement