10
Construct a temperature sensor and connect to Arduino Uno 1 Module 2, Lesson 1 – Construct a temperature sensor and connect to Arduino Teacher 60 minutes Overview of module 2 The Sensor deployment and data gathering module will require students to integrate their sensors with microprocessors (Arduino Uno), and write simple programs to enable gathering and analysis of sensed environmental data. Students will then deploy their sensor system and use it to make measurements of their local environment which they will then plot and analyze. The deployment and data gathering module will require students to use mathematics skills (systems of equations, simple statistics, manipulation of formulae), science skills (hydrology, electrical circuits), pre-engineering skills (design, testing and problem solving, tool use), technology skills (programming and interfacing a microprocessor) and general skills (teamwork, communication). Purpose of this lesson Construct a temperature sensor Convert Resistance to Temperature Program the Arduino to read voltages from a sensor circuit and display on the screen. Materials Copy of the lesson USB A/B cable NTC thermistor 10K Ice Arduino Uno Thermometer 10k ohm Resistor Beakers Jumper wires Hot water/electric kettle Breadboard Arduino IDE software Computer Soldering kit (optional) Graph paper (or Excel)

Module 2, Lesson 1 – Construct a temperature sensor and ......Construct a temperature sensor and connect to Arduino Uno 1 Module 2, Lesson 1 – Construct a temperature sensor and

  • Upload
    others

  • View
    16

  • Download
    0

Embed Size (px)

Citation preview

Page 1: Module 2, Lesson 1 – Construct a temperature sensor and ......Construct a temperature sensor and connect to Arduino Uno 1 Module 2, Lesson 1 – Construct a temperature sensor and

Construct a temperature sensor and connect to Arduino Uno 1

Module 2, Lesson 1 – Construct a temperature sensor and connect to Arduino

Teacher

60 minutes

Overview of module 2 The Sensor deployment and data gathering module will require students to integrate their

sensors with microprocessors (Arduino Uno), and write simple programs to enable gathering

and analysis of sensed environmental data. Students will then deploy their sensor system and

use it to make measurements of their local environment which they will then plot and analyze.

The deployment and data gathering module will require students to use mathematics skills

(systems of equations, simple statistics, manipulation of formulae), science skills (hydrology,

electrical circuits), pre-engineering skills (design, testing and problem solving, tool use),

technology skills (programming and interfacing a microprocessor) and general skills (teamwork,

communication).

Purpose of this lesson

● Construct a temperature sensor

● Convert Resistance to Temperature

● Program the Arduino to read voltages from a sensor circuit and display on the screen.

Materials

Copy of the lesson USB A/B cable

NTC thermistor 10K Ice

Arduino Uno Thermometer

10k ohm Resistor Beakers

Jumper wires Hot water/electric kettle

Breadboard

Arduino IDE software

Computer

Soldering kit (optional)

Graph paper (or Excel)

Page 2: Module 2, Lesson 1 – Construct a temperature sensor and ......Construct a temperature sensor and connect to Arduino Uno 1 Module 2, Lesson 1 – Construct a temperature sensor and

Construct a temperature sensor and connect to Arduino Uno 2

Procedure

Connecting a thermistor to the Arduino Uno

What is a breadboard? A breadboard is used for prototyping electronics and testing circuit designs. Most components in electronic circuits can be interconnected by inserting their leads or terminals into the holes and then making connections with wires where appropriate. The breadboard has strips of metal underneath the board and connect the holes on the top of the board. The metal strips are laid out as shown below. Note that the top and bottom rows of holes are connected horizontally and split in the middle while the remaining holes are connected vertically. A set of connected holes can be called a node:

To interconnect the selected row (node A) and column (node B) a cable going from any hole in the row to any hole in the column is needed:

Page 3: Module 2, Lesson 1 – Construct a temperature sensor and ......Construct a temperature sensor and connect to Arduino Uno 1 Module 2, Lesson 1 – Construct a temperature sensor and

Construct a temperature sensor and connect to Arduino Uno 3

Electronic Circuit Connect the thermistor, the resistor and the wires as shown in the picture below. Make sure to

follow the breadboard connection logic mentioned in the previous section.

- Thermistor (Two black wires with circle at top)

Thermistor Pin 1: Connected to Arduino ground (Black jumper cable wire)

Thermistor Pin 2: Connected to Arduino Analog Input A0 (White jumper cable wire)

and 10K resistor Pin 2

- Resistor (blue with stripes)

Resistor Pin 1: Connected to the Arduino +5V (Red jumper cable wire)

Resistor Pin 2: Connected to signal (White jumper cable wire) and Thermistor Pin 2

Note: The connection of the Red, Black and White cables to the Arduino are pictured

below. The Thermistor and the resistor might be different for each individual setup but

the schematic logic remains identical.

Page 4: Module 2, Lesson 1 – Construct a temperature sensor and ......Construct a temperature sensor and connect to Arduino Uno 1 Module 2, Lesson 1 – Construct a temperature sensor and

Construct a temperature sensor and connect to Arduino Uno 4

Signal Cables connection

Page 5: Module 2, Lesson 1 – Construct a temperature sensor and ......Construct a temperature sensor and connect to Arduino Uno 1 Module 2, Lesson 1 – Construct a temperature sensor and

Construct a temperature sensor and connect to Arduino Uno 5

Using Arduino IDE (Arduino programming environment)

Now that the electrical circuit is constructed, the Arduino needs to be programmed using the “Arduino IDE” in order to acquire and read the signal from the thermistor. The program is written in “C” and will be described in the following sections. Install the Arduino IDE (https://www.arduino.cc/en/Main/Software) and launch the program. Arduino IDE

1 Menu Bar: Gives you access to the tools needed for create and saving Arduino sketches.

2 Verify Button: Compiles your code and checks for errors in spelling or syntax.

3 Upload Button: Sends the code to the Arduino.

4 New Sketch: Opens up a new window containing a blank sketch.

5 Sketch Name: Saved sketch names are displayed here.

6 Open Existing Sketch: Open saved sketches or one from stored examples.

7 Save Sketch: Saves the sketch currently open.

8 Serial Monitor: When an Arduino is connected, its serial information will be displayed here.

9 Code Area: Area to compose the code of the sketch.

10 Message Area: Messages about the status of saving, code compiling, errors and more.

11 Text Console: Details of an error message, size of the program and additional information.

12 Board and Serial Port: Identifies the board in use and serial port the board is connected to.

Page 6: Module 2, Lesson 1 – Construct a temperature sensor and ......Construct a temperature sensor and connect to Arduino Uno 1 Module 2, Lesson 1 – Construct a temperature sensor and

Construct a temperature sensor and connect to Arduino Uno 6

Connecting Arduino to a computer Plug one end of the USB A/B cable into your computer’s USB port, and the other end of the

cable into the Arduino.

Go the Tools in the Menu Bar. Select Board. Select Arduino Uno.

Page 7: Module 2, Lesson 1 – Construct a temperature sensor and ......Construct a temperature sensor and connect to Arduino Uno 1 Module 2, Lesson 1 – Construct a temperature sensor and

Construct a temperature sensor and connect to Arduino Uno 7

Note: The Port can be different for your setup but just make sure to select “COMX

(Arduino/Genuino Uno), the X denotes the serial port number allocated by the computer

depending on the available ports. Programming the Arduino

1. Select “File” then “New Sketch” in the toolbar

2. In the Code Area, copy and paste the code (below). Do not Copy the line //Begin and //End, //

means comment in C programming language. 3. In the Menu Bar, select “Tools”, select “Serial Port”, and the correct serial port (COMX). This

will depend on your system. 4. Verify the code (click the Checkmark in the green circle) 5. Upload the code to the Arduino by clicking Upload (click the Arrow in the green circle)

PROGRAM 1

//Begin // the value of the 'other' resistor #define SERIESRESISTOR 10000 // What pin to connect the sensor to #define THERMISTORPIN A0 void setup(void) { Serial.begin(9600); } void loop(void) { float reading; reading = analogRead(THERMISTORPIN); Serial.print("Analog reading "); Serial.println(reading); // convert the value to resistance reading = (1023 / reading) - 1; // (1023/ADC - 1) reading = SERIESRESISTOR / reading; // 10K / (1023/ADC - 1) Serial.print("Thermistor resistance "); Serial.println(reading); delay(1000); }

//End

Page 8: Module 2, Lesson 1 – Construct a temperature sensor and ......Construct a temperature sensor and connect to Arduino Uno 1 Module 2, Lesson 1 – Construct a temperature sensor and

Construct a temperature sensor and connect to Arduino Uno 8

Note: If all the steps have been followed correctly, the values of the reading should be

displayed in the “Serial Monitor” of the “Arduino IDE”. To have access to the Serial Monitor, first

make sure that after Step 5 (Uploading the code) no error is present in the “Text Console”, area

(11) in the Arduino IDE image. Then, in the toolbar, go to “Tools” then “Serial Monitor” (Can also

be seen in one of the previous picture). The values of the thermistor resistance should be

plotted.

Converting to Temperature

Finally, we want to have the temperature reading, not just a resistance reading. To do that we'll

use a simplified version of the Steinhart-Hart equation to convert the values.

Where To (room temperature, 25 °C = 298.15 K) and B (in this case 3950, the coefficient of the

thermistor), and Ro (the resistance at room temp, in this case 10Kohm). We plug in R

(resistance measured) and get out T (temperature in Kelvin) which is converted to °C

The following sketch will calculate °C for you

PROGRAM 2

//Begin

// which analog pin to connect #define THERMISTORPIN A0 // resistance at 25 degrees C #define THERMISTORNOMINAL 10000 // temp. for nominal resistance (almost always 25 C) #define TEMPERATURENOMINAL 25 // how many samples to take and average, more takes longer // but is more 'smooth' #define NUMSAMPLES 5 // The beta coefficient of the thermistor (usually 3000-4000) #define BCOEFFICIENT 3950 // the value of the 'other' resistor #define SERIESRESISTOR 10000 uint16_t samples[NUMSAMPLES]; void setup(void) { Serial.begin(9600); analogReference(EXTERNAL); } void loop(void) {

Page 9: Module 2, Lesson 1 – Construct a temperature sensor and ......Construct a temperature sensor and connect to Arduino Uno 1 Module 2, Lesson 1 – Construct a temperature sensor and

Construct a temperature sensor and connect to Arduino Uno 9

uint8_t i; float average; // take N samples in a row, with a slight delay for (i=0; i< NUMSAMPLES; i++) { samples[i] = analogRead(THERMISTORPIN); delay(10); } // average all the samples out average = 0; for (i=0; i< NUMSAMPLES; i++) { average += samples[i]; } average /= NUMSAMPLES; Serial.print("Average analog reading "); Serial.println(average); // convert the value to resistance average = 1023 / average - 1; average = SERIESRESISTOR / average; Serial.print("Thermistor resistance "); Serial.println(average); float steinhart; steinhart = average / THERMISTORNOMINAL; // (R/Ro) steinhart = log(steinhart); // ln(R/Ro) steinhart /= BCOEFFICIENT; // 1/B * ln(R/Ro) steinhart += 1.0 / (TEMPERATURENOMINAL + 273.15); // + (1/To) steinhart = 1.0 / steinhart; // Invert steinhart -= 273.15; // convert to C Serial.print("Temperature "); Serial.print(steinhart); Serial.println(" *C"); delay(1000); }

//End

Open the Serial Monitor and the temperatures values should be displayed as below with

the computed resistance of the thermistor.

Page 10: Module 2, Lesson 1 – Construct a temperature sensor and ......Construct a temperature sensor and connect to Arduino Uno 1 Module 2, Lesson 1 – Construct a temperature sensor and

Construct a temperature sensor and connect to Arduino Uno 10

Note: The numbers may be different from your reading according to the current temperature of

the thermistor.