Ligne 65 : |
Ligne 65 : |
| === Low resolution reading === | | === 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){ |
| + | |
| + | // 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> |
| + | |
| + | 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-70.png]] |
| + | |
| + | {{ENG-CANSAT-TRAILER}} |
| | | |
| === High resolution reading === | | === High resolution reading === |