To get Arduino to tell the computer what the ambient temperature is in the room.
Equipment:
- 1x Arduino Uno
- 1x Breadboard
- 1x Temperature Sensor
- 5x Wire
Reference:
Program Details:
This program introduces another integrated circuit which is packaged in a shell which looks exactly like the P2N2222AG transistors which we have worked with before. The only way too tell the difference would be to closely examine the case, as this one will be labeled TMP36. For this piece of hardware to work, it needs 3 connections: Voltage, signal, and ground. For the signal, it sends a signal, rather than take one in; as it tells arduino what the temperature is. And so, the signal is sent to an analog pin, where it can be read.
This code is the first time we have done a serial connection with the computer. And in doing so, there is a new method called Serial.begin(number);. This method is used in the setup to establish at which speed arduino sends information, and how quickly the computer reads it. Modern computers can read information much faster than 9600 killlabits per seconds, but we choose this speed because arduino cannot communicate any faster than this. Another new method we use is Serial.println(temperature); which is used for arduino to print the information it has received onto the serial monitor. Without it, arduino would tell the computer that it wants to communicate, but would say nothing. We use println rather than print because we want a break after every other statement, else it would all just be one big line, and difficult for the user to read.
Finally putting this together is very simple. We can save time by not using the (+) and the (-) column, as it is inefficient to do so since there is only one device which need voltage and is grounded. So we can connect 5V directly to the +5V pin, and ground to the gnd pin on the TMP36. Finally we take a wire from analog pin0, and connect it to the signal pin on arduino.
Time to Complete:
5 minutes to build, 10 minutes to code.
Results:
At first it was stating that the temperature in the room was below 10 degrees Celsius. After leaving it alone for a few seconds, it adjusted itself to the 17 - 21 degree range; which seems like the range the room temperature probably is.
Photos:
Tips:
Make sure you read what you are working with carefully, as this Temperature Sensor looks just like a Transistor. If you look at the black head closely, it should state the model number, which in turn will indicate what it is you are working with.
Further Work:
We can convert the temperature which is uploaded to a different form of measurement. You can do this by changing the outputted value from (temperature) --> (temperature - 273). This should print the value from Celsius to Kelvin.
Further Work:
We can convert the temperature which is uploaded to a different form of measurement. You can do this by changing the outputted value from (temperature) --> (temperature - 273). This should print the value from Celsius to Kelvin.
Program Modifactions:
Very similar to the one found in the reference:
The only thing which I changed was how often the temperature is displayed. I felt it was being displayed too slowly, so I shortened the time gap between when each temperature was being printed. I simply did this by going inot void loop(); and changing the delay(1000) ---> delay(200).
Program:
void setup()
{
Serial.begin(9600); //Sets the speed at which Arduino and the Computer communicate
}
{
Serial.begin(9600); //Sets the speed at which Arduino and the Computer communicate
}
void loop()
{
float temperature = getVoltage(temperaturePin);//Gets the voltage from the TMP36(calls method)
temperature = (temperature – .5) * 100; //Converts the voltage to Celcius
Serial.println(temperature); //Prints the temperature on the serial monitor
delay(1000); //1 second wait
}
{
float temperature = getVoltage(temperaturePin);//Gets the voltage from the TMP36(calls method)
temperature = (temperature – .5) * 100; //Converts the voltage to Celcius
Serial.println(temperature); //Prints the temperature on the serial monitor
delay(1000); //1 second wait
}
float getVoltage(int pin){ //Returns a float
return (analogRead(pin) * .004882814); //Reduces range from 0 - 1024 --> 0 - 5, Gives number
}
No comments:
Post a Comment