0% found this document useful (0 votes)
8 views1 page

Control Proporcional Código

The document contains code for a temperature control system that uses a temperature sensor and potentiometer to control a heater and fan based on a target temperature set by the potentiometer. The code initializes pins, reads the sensor and potentiometer, calculates temperature from resistance, and uses PID control to set the heater output and turn the fan on if temperature exceeds the target.

Uploaded by

Karla Perez
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as TXT, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
8 views1 page

Control Proporcional Código

The document contains code for a temperature control system that uses a temperature sensor and potentiometer to control a heater and fan based on a target temperature set by the potentiometer. The code initializes pins, reads the sensor and potentiometer, calculates temperature from resistance, and uses PID control to set the heater output and turn the fan on if temperature exceeds the target.

Uploaded by

Karla Perez
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as TXT, PDF, TXT or read online on Scribd
You are on page 1/ 1

#include <math.

h>
float consigna=0;
const int Pin = A0;
const int Pot= A1;
const float Kp=1000;
float Y;
const int R = 10000;
const int Vcc =5;
float A= 8.0e-3;;
float B= -9.34e-4;;
float C= 5.05e-6;;
const int calefaccion=3;
const int ventilador=4;

void setup(){
pinMode (calefaccion,OUTPUT);
pinMode (ventilador,OUTPUT);
Serial.begin(9600);
Serial.println("calefaccion\tventilador\tPot");

void loop()
{
float sensor = analogRead(Pin);
Y=analogRead(Pot);
consigna=map(Y,0,1023,0,50);
float V=sensor/1023*Vcc;
float RT=(R*V)/(Vcc-V);
float logR=log(RT);
float T1=1/(A+B*logR+C*logR*logR*logR);
float Celcius=T1-273.15;
float error=consigna-Celcius;
float control=Kp*error;
Serial.print(Celcius);
Serial.print(",");
Serial.println(consigna);

if(control>255){
control=255;
}
if(control<0){
control=0;
}
analogWrite(calefaccion,control);
if (Celcius>consigna+5)
{
digitalWrite(ventilador,1);
}
else{
digitalWrite(ventilador,0);
}
delay(1000);

You might also like