Modifications

Sauter à la navigation Sauter à la recherche
3 612 octets ajoutés ,  3 octobre 2018 à 21:37
Ligne 30 : Ligne 30 :  
* [http://www.analog.com/en/mems-sensors/digital-temperature-sensors/tmp36/products/product.html TMP36 datasheet] (''analog.com'', html)
 
* [http://www.analog.com/en/mems-sensors/digital-temperature-sensors/tmp36/products/product.html TMP36 datasheet] (''analog.com'', html)
   −
=== how to measure the temperature ===
+
=== How to measure the temperature ===
{{traduction}}
+
It will be necessary to convert the analogue voltage intro degree. As the TMP36 can also measure negative temperature, the 0 degree Celcius is placed at 500 mV offset. So, any voltage under 0.5 Volt is a negative temperature.
Comment calculer la température Il faut donc convertir la tension analogique en degré. Comme le TMP36 permet de mesurer des température négatives, le 0 degré Celsius est placé à une offset de 500 milliVolts. Ainsi, toute mesure inférieur à 500 mv correspondra à une température négative.
      
[[Fichier:TMP36-Graph.png]]
 
[[Fichier:TMP36-Graph.png]]
   −
La formule est la suivante pour le TMP36:
+
Here is the formula to use with a TMP36 powered at 3.3v:
   −
Temp en °C = ( Tension_de_sortie_en_milliVolts - 500) / 10
+
Temp in °C = ( output_voltage_in_mV - 500) / 10
   −
Donc, si la tension de sortie est de 1 Volts, la température correspondante est de
+
So, if we do have an output voltage of exactly 1 Volt (1000 mV) then the temperature would be
(1000 - 500)/10
     −
Soit 50 degrés Celcius.
+
temp = (1000 - 500)/10
   −
si vous utilisez un LM35 ou similaire, la température se calcule comme suit (utiliser la ligne 'a' sur le graphique):
+
So 50 Celcius degrees.
   −
  Temp en °C = ( Tension_de_sortie_en_millivolts) / 10
+
== Wiring ==
 +
To use the TMP36, connect:
 +
* The pin 1 (on the left) to a power source (3.3V),
 +
* The pin 3 (the the right droite) to the ground/GND.
 +
* The pin 2 (middle one) to the A3 analogue input.
 +
 
 +
[[Fichier:ENG-CANSAT-TMP36-01.png|480px]]
 +
 
 +
The TMP36 output voltage would range from 0V @ -50°C to 1.75V @ 125°C. So no risk for our 3V based microcontroler.
 +
 
 +
== Testing the sensor ==
 +
In the both case show here under, the measured temperature would be identical.
 +
 
 +
{{ambox|text=However, if your project does need a high resolution analog reads then it may be appropriate to explore the "High Resolution Reading" example.}}
 +
 
 +
By default, the Arduino's {{fname|analogRead()}} use a 10 bit coding. So the range of possible value return by {{fname|analogRead()}} is 0 to 1024 (for 0 to 3.3v). This means that the accuracy of reading is 3.3 / 1024 = 0.0032 Volts, so 3.2 mV.
 +
 
 +
As the M0 does have an ADC (''Analog-to-Digital Converter'') with a precision of 12 bits, we could also use the {{fname|analogReadResolution( 12 )}} to upgrade the {{fname|analogRead()}} resolution to 12 bits. In such case, the range of possible value return by {{fname|analogRead()}} is 0 to 4095 (for 0 to 3.3v). As we have a real 12bit ADC, we can rely on that accuracy (it is not a 10 bits ADC storing the data into a 12 bits integer).
 +
with 12bits we have an reading accuracy of 3.3 / 4095 = 0.000805 Volts, so 0.805 mV.
 +
   
 +
=== Low resolution reading ===
 +
 
 +
<syntaxhighlight lang="c">
 +
// where is wired the TMP36
 +
const int temperaturePin = A3; // analogue input
 +
 
 +
// Executed once when starting the microcontroler
 +
void setup() {
 +
  // start serial connexion with the computer
 +
  Serial.begin(9600);
 +
}
 +
 
 +
// Executed again and again
 +
void loop() {
 +
  // read the voltage of TMP36
 +
  float voltage = getVoltage(temperaturePin);
 +
  Serial.print( "Voltage : " );
 +
  Serial.print( voltage );
 +
  Serial.println( " Volts" );
 +
  // convert voltage to temperature
 +
  //  Degrees = (voltage - 500mV) multiplied by 100
 +
  float temperature = (voltage - .5) *100;
 +
  Serial.print( "Temperature: " );
 +
  Serial.print(temperature);
 +
  Serial.println( " °C" );
 +
  Serial.println( " " );
 +
  delay(1000); // wait 1 second
 +
}
 +
 
 +
/*
 +
* getVoltage() - return the voltage of an analog pin
 +
*/
 +
float getVoltage(int pin){
 +
  // AS the sketch does not call the analogReadResolution()
 +
  //    function to change the analog reading resolution
 +
  // THEN Arduino use the defaut 12 bits resolution!
 +
  // Under 12 bits resolution, the analogRead() returns
 +
  //    a value between 0 & 1024.
 +
  //
 +
  // Convert digital value between 0 & 1024 to
 +
  //    voltage between 0 & 3.3 volts.
 +
  //    (each unit equal 3.3 / 1024 = 3.2 millivolts)
 +
  return (analogRead(pin) * .0032);
 +
}
 +
</syntaxhighlight>
 +
 
 +
Once the sketch uploaded to the board, you can start the Serial Monitor
 +
 
 +
[[Fichier:ENG-CANSAT-BMP280-04.png]]
 +
 
 +
Which produce the following result on the Serial Monitor
 +
 
 +
[[Fichier:ENG-CANSAT-TMP36-60.png|640px]]
 +
 
 +
{{ENG-CANSAT-TRAILER}}
   −
== Wiring ==
+
=== High resolution reading ===
 +
 
 +
<syntaxhighlight lang="c">
 +
// where is wired the TMP36
 +
const int temperaturePin = A3; // analogue input
 +
 
 +
// Executed once when starting the microcontroler
 +
void setup() {
 +
  // start serial connexion with the computer
 +
  Serial.begin(9600);
 +
  // Upgrade the ADC resolution from 10 to 12 bits.
 +
  analogReadResolution( 12 );
 +
}
 +
 
 +
// Executed again and again
 +
void loop() {
 +
  // read the voltage of TMP36
 +
  float voltage = getVoltage(temperaturePin);
 +
  Serial.print( "Voltage : " );
 +
  Serial.print( voltage );
 +
  Serial.println( " Volts" );
 +
  // convert voltage to temperature
 +
  //  Degrees = (voltage - 500mV) multiplied by 100
 +
  float temperature = (voltage - .5) *100;
 +
  Serial.print( "Temperature: " );
 +
  Serial.print(temperature);
 +
  Serial.println( " °C" );
 +
  Serial.println( " " );
 +
  delay(1000); // wait 1 second
 +
}
   −
Pour l'utiliser, connectez simplement la broche 1 (gauche) à une source d'alimentation (entre 2.7 et 5.5V), la broche 3 (droite) à la masse (gnd) et finalement la broche 2 (au milieu) sur une entrée analogique de votre microcontroleur.
+
/*
 +
* getVoltage() - return the voltage of an analog pin
 +
*/
 +
float getVoltage(int pin){
 +
  // Convert digital value between 0 & 4095 to
 +
  //    voltage between 0 & 3.3 volts.
 +
  //    (each unit equal 3.3 / 4095 = 0.805 millivolts)
 +
  return (analogRead(pin) * .000805);
 +
}
 +
</syntaxhighlight>
   −
La tension de sortie est de 0V à -50°C et 1.75V à 125°C. Il est facile de convertir la tension de sortie (en millivolts) en température à l'aide de la formule:
+
Once the sketch uploaded to the board, you can start the Serial Monitor
   −
Temp °C = 100*(lecture en V) - 50
+
[[Fichier:ENG-CANSAT-BMP280-04.png]]
   −
La fiche technique du TMP36 est accessible ici.
+
Which produce the following result on the Serial Monitor
    +
[[Fichier:ENG-CANSAT-TMP36-70.png|640px]]
    
{{ENG-CANSAT-TRAILER}}
 
{{ENG-CANSAT-TRAILER}}
29 917

modifications

Menu de navigation