Wednesday, March 20, 2013

Testing the Arduino TMP102

Documentation by Andrew Samuels

Description


TMP102 - Temperature Sensor
Specs
  • Accurate: -40 – 125 oC
  • Operating: -55 – 150 oC
  • 0.0625 oC Resolution
  • 1.4 – 3.6 V Input
  • 10 µA
Thermal Resistivity
  • 260 oC/W

I2C bus Interface

Goals

The goal of the test is to read the temperature of the h1surrounding environment with the TMP102 component.

Results

This was our second temperature component tested on our breadboard. Watch the video to see the circuit and results of the test.



Source for the code is from Bildr.com, How's the weather? TMP102 + Arduino
The code:
//Arduino 1.0+ Only
//Arduino 1.0+ Only

//////////////////////////////////////////////////////////////////
//©2011 bildr
//Released under the MIT License - Please reuse change and share
//Simple code for the TMP102, simply prints temperature via serial
//////////////////////////////////////////////////////////////////

#include 
int tmp102Address = 0x48;

void setup(){
  Serial.begin(9600);
  Wire.begin();
}

void loop(){

  float celsius = getTemperature();
  Serial.print("Celsius: ");
  Serial.println(celsius);

  float fahrenheit = (1.8 * celsius) + 32;
  Serial.print("Fahrenheit: ");
  Serial.println(fahrenheit);

  delay(200); //just here to slow down the output. You can remove this
}

float getTemperature(){
  Wire.requestFrom(tmp102Address,2); 

  byte MSB = Wire.read();
  byte LSB = Wire.read();

  //it's a 12bit int, using two's compliment for negative
  int TemperatureSum = ((MSB << 8) | LSB) >> 4; 

  float celsius = TemperatureSum*0.0625;
  return celsius;
}

Monday, January 28, 2013

Intro to Arduino - Two Tasks : #1) 8 Sequentially Blinking LEDs #2) Ambient Temperature Sensor

Documentation by Andrew Samuels

We completed two tasks assigned to us in our introduction to the Arduino microcontroller. The first task was to instruct the Arduino to blink 8 LEDs in sequence without the Arduino programming language's delay() function. The second task was to measure the ambient temperature sensor using the TMP36 sensor. Arduino code is included for both tasks.

#1) 8 Blinking LEDs in Sequence



/* 8 blinking LEDS w/ no delay func
hopefully this fixes the random LED problem
*/

//int timer = 100; //higher number, slower timing

//changing variables
int ledState = LOW; //used to set the LED
long previousMillis = millis(); //will store last time LED was updated

long interval = 500; //interval at which to blink
int thisPin = 5;
int startPin = 6;
void setup(){
//initialize each pin as output
for(int thisPin = 6; thisPin < 13; thisPin++){
    pinMode(thisPin, OUTPUT);
  }
}

void loop(){
//loop from the lowest pin to the highest pin
    unsigned long currentMillis = millis();
    if(currentMillis - previousMillis > interval){
      //save the last time you blinked the LED
      previousMillis = currentMillis;
      digitalWrite(thisPin, LOW);
      thisPin++;
      
      //set the LED with ledState
      if (thisPin == 14){
      digitalWrite(startPin, HIGH);
      thisPin = startPin;
    }
      else{
      digitalWrite(thisPin, HIGH);
      }
      //If LED is off turn it on, if on..turn off
    }
    
      
    
    }

#2) Ambient Temperature Sensor (TMP36)


/* Temperature Sensor with TMP36
Measures the ambient temperature of the room.
*/

int sensPin = 0; //analog pin for TMP36

void setup(){
  Serial.begin(9600); //initialize serial connection with computer
     //to view results
}


void loop(){
//get the voltage reading from the temp sensor
int reading = analogRead(sensPin);

//convert reading to voltage
float voltage = reading * 5.0;
voltage /= 1024.0; //divide and assign voltage

//print voltage
Serial.print(voltage);
Serial.println(" volts");

//convert voltage to tempurature in Celsius, then print
float temperatureC = (voltage - 0.5) * 100; //convert 10mV per degree
//with 500 mV offset to degrees 
Serial.print(temperatureC);
Serial.println(" degrees C");

delay(1000);

}