• aditya mehrotra.

filament updates: thermistors and bang-bang control [updates]

So this evening, the resistors came, and I started looking through this arduino tutorial to get them working: https://learn.adafruit.com/thermistor/using-a-thermistor



So we wired our system a little differently than the tutorial but that's OK because it doesn't really matter if we read the voltage across the thermistor directly or calculate it by reading the voltage across the 10K resistor we were using. And then we convert that voltage to know what the resistance at any time of the thermistor is. Here's our circuit and the formulas along.

Now let's note the actual specifications of the thermistor so, once we know the resistance, we can actually figure out what the temperature is. So this thermistor sits happily at 100K at room temperature of 25 degC, and every degree Celsius increase is a -2-5% decrease in resistance. So here's the formula:


RESISTANCE = 100000.0*(1-0.02)^(TEMPERATURE-25.0)


Now comes the code, and the code we tested and wrote today did a few simple things. First, it reads from each of the thermistors (indirectly) what their resistance is at any point in time. Then it calculates, for a desired temperature what we can expect the resistance to be, and then it controls the relay with bang-bang control to heat the coil and the tip to the target temperature.


#define T1_PIN A3
#define T1_PIN A4
#define relay_pin 3
 
void setup() {
  // put your setup code here, to run once:
  pinMode(A3, INPUT);
  pinMode(A4, INPUT);
 
  //relay setup code for the system  
  pinMode(relay_pin, OUTPUT);
  digitalWrite(relay_pin, HIGH);
 
  Serial.begin(9600);
}
 
void loop() {
  // put your main code here, to run repeatedly:
  double nozzle = analogRead(A3);  //tip thermistor
  double body = analogRead(A4);  //body thermistor
 
  nozzle = ((1023 / nozzle)  - 1);     // VOLTAGE of the 10K
  double r_nozzle = 50000.0/nozzle-10000.0; //resistance of thermistor
 
  body = ((1023 / body)  - 1);     // VOLTAGE of the 10K
  double r_body = 50000.0/body-10000.0; //resistance of thermistor
 
  //we also know the resistance decreases 2-5% for every degree celcius so 
  //let's do -3.5% for every deg C
 
  double t_target = 100.0;
  double r_target = 100000.0*pow((1-0.02), (t_target-25.0));
 
  Serial.println(r_body);
  Serial.println(r_target);
 
  //A3 is the thermistor for the nozzle
  //at room temperature it reads 83 or 82 -- so let's see what happens when we turn on that relay
 
  //resistance will DECREASE over time!
 
  if(r_nozzle>=r_target) {
    if(r_body>=r_target){
      digitalWrite(relay_pin, LOW);
    }
    else {
      digitalWrite(relay_pin, HIGH);
    }
  }
  else{
    digitalWrite(relay_pin, HIGH);
  }
}
  

#updates #omgrobots #filament_one

0 views0 comments
© copyright 2019 | aditya mehrotra