Devices & Components
Arduino Mega 2560 Rev3
MCP9071/A
Project description
Code
Arduino code for thermometer active sensor based
arduino
taking the application scheme as referencehow to connect the sensor to the Arduino board and loading this code in the arduino, it is possibile read the room temperature in the serial output interface. Every 1s the measure is done and printed
1/* 2 3 The value of Vout is obtained by averaging 1024 values reading the voltage on pin A0. whicch is connected to the sensor output. The value of temeprature ta, read by the sensor is shown on the serial monitor. 4 5*/ 6 7 8// set pin numbers: 9 10const int in = A0; // input for reading the sensor output 11 12// set constants: 13const float vout0 = 400; // sensor output voltage in mV at 0°C 14const float tc = 19.53; // mV for °C temperature constant for the MCP9701/A 15 16// variables: 17 18int i, f; 19float vout, vout_avg, ta; 20 21 22// MAIN PROGRAM 23 24void setup() { 25 Serial.begin(9600); 26 pinMode(in, INPUT); // set pin in as input 27 pinMode(13, OUTPUT); // set pin 13 as output 28 digitalWrite(13, LOW); 29 analogReference(DEFAULT); 30 31} 32 33void loop() { 34 vout_avg = 0; 35 for (i = 0; i < 1024; i++) { 36 vout = analogRead(A0) * (4976.30 / 1023); 37 //Serial.println(vout); 38 vout_avg = vout_avg + vout; 39 } 40 vout = vout_avg / 1024; 41 //Serial.println(vout); 42 ta = (vout - vout0) / tc; 43 Serial.print("temperature ( celcius degree) = " ); 44 Serial.println(ta); 45 delay (1000); 46}
Arduino code for thermometer active sensor based
arduino
taking the application scheme as referencehow to connect the sensor to the Arduino board and loading this code in the arduino, it is possibile read the room temperature in the serial output interface. Every 1s the measure is done and printed
1/* 2 3 The value of Vout is obtained by averaging 1024 values reading the voltage on pin A0. whicch is connected to the sensor output. The value of temeprature ta, read by the sensor is shown on the serial monitor. 4 5*/ 6 7 8// set pin numbers: 9 10const int in = A0; // input for reading the sensor output 11 12// set constants: 13const float vout0 = 400; // sensor output voltage in mV at 0°C 14const float tc = 19.53; // mV for °C temperature constant for the MCP9701/A 15 16// variables: 17 18int i, f; 19float vout, vout_avg, ta; 20 21 22// MAIN PROGRAM 23 24void setup() { 25 Serial.begin(9600); 26 pinMode(in, INPUT); // set pin in as input 27 pinMode(13, OUTPUT); // set pin 13 as output 28 digitalWrite(13, LOW); 29 analogReference(DEFAULT); 30 31} 32 33void loop() { 34 vout_avg = 0; 35 for (i = 0; i < 1024; i++) { 36 vout = analogRead(A0) * (4976.30 / 1023); 37 //Serial.println(vout); 38 vout_avg = vout_avg + vout; 39 } 40 vout = vout_avg / 1024; 41 //Serial.println(vout); 42 ta = (vout - vout0) / tc; 43 Serial.print("temperature ( celcius degree) = " ); 44 Serial.println(ta); 45 delay (1000); 46}
Downloadable files
SCHEMATIC
The hardware implementation is executed by using the Arduino MEGA 2560 card: just connect the active sensor as shown in the figure. Pin A0 is set as an analog input for converting the output voltage of the sensor to the AD.
SCHEMATIC

Comments
Only logged in users can leave comments