Arduino servo savukaasuille

#include <LiquidCrystal.h>
#include <Servo.h>
Servo myservo;
LiquidCrystal lcd(7, 8, 9, 10, 11, 12);

int tolerance = 10;
int potpin = A1;
int val;

const float vf0 = 381.60;   //k
const float vf0d = 610.61;
int i;    //k
int ii;
float dtemp, dtemp_avg, tempk;   //k
float dtempd, dtempd_avg, td;

void setup(){
  lcd.begin(16, 2);  // intialise the LCD
  pinMode(A0,INPUT);
  pinMode(A1,INPUT);

  Serial.begin(9600);
  myservo.attach(3);
}

void loop(){
  delay(3);

  int temp = tempk+td;
 
  dtemp_avg = 0;
  for (i = 0; i < 1024; i++) {
    float temp_k = analogRead(A0) * (5070.00 / 1023.000);   //k
    dtemp = (temp_k - vf0)/3.00;
    dtemp_avg = dtemp_avg + dtemp ;
}

  tempk = dtemp_avg / 1024;

    dtempd_avg = 0;
    for (ii = 0; ii < 1024; ii++) {
    float temp_d = analogRead(A3) * (5070.00 / 1023.000);
    dtempd = (vf0d - temp_d) * 0.4545454;
    dtempd_avg = dtempd_avg + dtempd;
}
  td = dtempd_avg / 1024;

  Serial.println(tempk);
  Serial.println(temp);
 
  val = analogRead(potpin);            // reads the value of the potentiometer (value between 0 and 1023)
  val = map(val, 0, 1023, 30, 160);     // scale it to use it with the servo (value between 0 and 180)
  myservo.write((temp/3.3)+val); 

   lcd.clear();
   lcd.print("Savukaasu=");
   lcd.print(temp);
   lcd.print(" C  ");
   lcd.setCursor(0, 1);
   lcd.print(td);
   lcd.print(", ");
   lcd.print (val);
   lcd.print(", ");
   lcd.print (temp+val);
 
}

Kommentit

Tämän blogin suosituimmat tekstit

TaloLoggerPi > Ubuntu Bionic

pulssien luentaa