| Ligne 56 : |
Ligne 56 : |
| | | | |
| | == Testing the sensor == | | == Testing the sensor == |
| | + | In the both case, the measured would be identical. |
| | | | |
| | + | However, 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 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). This means that the accuracy of reading is 3.3 / 4095 = 0.000805 Volts, so 0.805 mV. |
| | + | |
| | + | === Low resolution reading === |
| | + | |
| | + | |
| | + | === High resolution reading === |
| | + | |
| | + | /* --------------------------------------------- |
| | + | * | Code d'exemple du kit d'expérimentation |
| | + | * | Arduino |
| | + | * | CIRC-10 .: Température :. |
| | + | * --------------------------------------------- |
| | + | * Un programme simple qui affiche la température |
| | + | * actuelle dans la fenêtre de monitoring/débogage |
| | + | */ |
| | + | |
| | + | // Variable pour broche du TMP36 |
| | + | const int temperaturePin = A3; // entrée analogique |
| | + | // sur laquelle la broche Vout du TMP36 est |
| | + | // connectée. La résolution est 10mv/degré |
| | + | // centigrade avec 500 mV de décalage/offset |
| | + | // pour permettre la lecture de température |
| | + | // négative. |
| | + | |
| | + | void setup() { |
| | + | Serial.begin(9600); // Démarrer la connexion série avec l'ordinateur. |
| | + | // Pour voir le le résultat, ouvrez le « moniteur série », le |
| | + | // dernier bouton dans la barre d'outil. |
| | + | // (celui qui ressemble à une boite ayant une antenne). |
| | + | analogReadResolution( 12 ); |
| | + | } |
| | + | |
| | + | void loop() { // s'exécute encore et encore |
| | + | // Acquérir la tension lue sur le senseur de température. |
| | + | float voltage = getVoltage(temperaturePin); |
| | + | Serial.print( "Voltage : " ); |
| | + | Serial.print( voltage ); |
| | + | Serial.println( " Volts" ); |
| | + | // conversion de 10mV par degré avec un décalage (offset) de 500 mV. |
| | + | // Degrés = ((tension - 500mV) fois 100) |
| | + | float temperature = (voltage - .5) *100; |
| | + | Serial.print( "Temperature: " ); |
| | + | Serial.print(temperature); //affiche résultat |
| | + | Serial.println( " °C" ); |
| | + | Serial.println( " " ); |
| | + | delay(1000); // Attendre une seconde. |
| | + | } |
| | + | |
| | + | /* |
| | + | * getVoltage() - retourne la tension d'une entrée analogique identifiée par 'pin' |
| | + | */ |
| | + | float getVoltage(int pin){ |
| | + | // Convertir valeur digital de 0 à 4095 vers une valeur entre 0 et 3.3 volts. |
| | + | // (chaque unité lue vaut ~ 3.3 / 4095 = 0.805 millivolts |
| | + | Serial.println( analogRead(pin) ); |
| | + | return (analogRead(pin) * .000805); |
| | + | } |
| | | | |
| | {{ENG-CANSAT-TRAILER}} | | {{ENG-CANSAT-TRAILER}} |