[Back]

Lab 5: Temperture Sensors & Encoders

This lab has three purposes. First, to introduce the TMP 36, an IC temperature sensor. Then, to introduce the use of timer interrupts to ensure critical operations act at a fixed time. Lastly, to introduce the use of optical encoders to measure rotational position or speed.

Before starting the lab please be sure that you have the your nScope, nScope software, Arduino, and Arduino IDE installed. Additionally, you'll need to download TimerOne library, unzip the files, and place the folder in your Arduino Library folder (Will either be Arduino>Libraries, or Arduino>Hardware>Libraries)

Part List:
(1) TMP 36
(1) Encoder
(1) LED
(1) Resistor (pick your favorite!)
     Connecting wires

Part 1: Temperture Sensor

This is the easiest breadboard setup you will see in the class. HOWEVER, the TMP-36 looks identical to your BJT's that we used in the last lab. Make sure you have the right one before you start. The temperature sensor has a relatively simple pinout as shown in Figure 2. Connect the power and ground pins as indicated and then connect the center pin to pin A1. This sensor will give a voltage reading that is related to temperature in Celcius by fig1.png Obviously we can manipulate this to give readings in Fahrenheit if we want.

fig2.png

Figure 2: Pinout for TMP 36 temperature sensor

Code

The 1st provided .ino file reads the signal from the sensor and outputs the results to the serial terminal at a fixed time determined by a timer interrupt.

The timer interrupt behaves much like the external interrupts we've used, but performs interrupts at specified time intervals rather than on button presses. You can find a lot of good information on timer interrupts here: http://playground.arduino.cc/Code/Timer1.

Now squeeze the temperature sensor and look at how those readings change due to your body heat.

Your Turn

Connect the temperature sensor output to the NScope and, using a trigger (an option in the nScope software, not a hardware thing), measure the time constant as you grip the sensor. Temperature sensors are notoriously slow, so don't expect something in the ms range.


Part 2: Encoder

Now we'll use the fancy motor that you checked out from Meredith for the course. The encoder on your motor has two magnetic tracks, each with 12 tracks per revolution. There is no index track. A Hall effect sensor is used to read the sensors. The pinout for the motor is:

fig3.png

Connections

Let's use the Arduino's interrupts to read the position from the encoder. Connect the motor's green wire to ground, and blue wire to 5V. Then connect the yellow wire to digital pin 2 and the white wire to digital pin 3. We are now in a position to read the encoder.

Code

Now load the second .ino file for the lab. This code sample uses interrupts on pins 2 and 3 to monitor the transitions of the two encoder lines. By setting the interrupts to trigger on both rising and falling edges of the signals, the total sensing resolution is 48 transitions per motor revolution, or 464.64 transitions per output shaft revolution.

The code outputs the current angular position of the output shaft to the screen in degrees, starting from zero at power on. Rotate either the motor shaft or just the encoder and watch the position change. Do the measurements match your expectations?

Your Turn

1] Modify the code to compute the angular velocity in RPM.

2] Display the motor speed to the serial terminal. (Counterclockwise rotations should have a positive angular velocity, whereas clockwise angular velocities should be negative). Spin the motor by hand to show the performance of the speed measurement.

3] Wire an LED to the PWM pin of your choice. Make the brightness of the LEDs be proportional to the rotation speed.

4] Show to a TA, and that's it!