AntiGuide: ArduinoThermistor2fils



PagePrincipale :: DerniersChangements :: ParametresUtilisateur :: Vous êtes 216.73.216.115 :: Signaler un abus :: le: 20250816 20:41:05

projet: C:\Users\adminpo\Desktop\ARDUINO\arduino-1.0.5 - 2016\examples\Po\ThermometreThermistor2FilsPullUpIntOuExt?

connexion 2 fils avec internaltrue
jaune à Gnd
orange à A0

testé ok le 20170108 sur mega2650
sur WemosD1Mini:
/*
 
 
 The circuit:
 * LED attached from pin 13 to ground (internal)
 * themistor 10K A0 & Grnd

 * Note: on most Arduinos there is already an LED on the board
 attached to pin 13.
 
 
 created 20160210 antiguide
  
  */

// constants won't change. They're used here to 
// set pin numbers:
const int resistorPin = A0;     // the number of the pushbutton pin
const int ledPin =  13;      // the number of the LED pin


const bool internal=true;

float ohmsPullUp =10000.0;

void setup() {
   if (internal) {ohmsPullUp = 38000.0;}
   Serial.begin(115200);

  // initialize the LED pin as an output:
  pinMode(ledPin, OUTPUT);      
  // initialize the resistor pin as an input:
  pinMode(resistorPin, INPUT); 
  if (internal) digitalWrite(resistorPin, HIGH);  // set pullup on analog pin 0   
}

double Thermistor(int RawADC) {
 double Temp;
 Temp         =log(ohmsPullUp/(1024.0/RawADC-1)); // for pull-up configuration
 Temp = 1 / (0.001129148 + (0.000234125 + (0.0000000876741 * Temp * Temp ))* Temp );
 Temp = Temp - 273.15;            // Convert Kelvin to Celcius
 return Temp;
}
void loop(){
 delay(1000); 

  // read the state of analogic pin:
   digitalWrite(ledPin, !digitalRead(ledPin));    // turn the LED On/off 

   float reading=analogRead(resistorPin);
   float ratio=reading/(1023-reading);
   float R=ohmsPullUp*ratio;
    Serial.print("\nRaw value: ");
    Serial.print(reading);
    Serial.print("  V: ");
    Serial.print(5.0*reading/1023);
    Serial.print("  ratio: ");
    Serial.print(ratio);
     Serial.print("  R: ");
    Serial.print(R);
      Serial.print("  temperature: : ");
    Serial.print(Thermistor(reading));
    
 
 }