Beginner's Project - Temperature Alarm

I am very new to arduino and am having an excruciating time doing a simple simple project.
I am trying to creat a temperature alarm, where at a certain temp the piezo will sound and an LED will go off
pretty simple stuff huh? yeah I have been working for 2 weeks and am about to pull my hair out so PLEASE help me out with my code?

//TMP36 Pin Variables
int temperaturePin = 0; 
int speakerPin = 9;

int length = 15; // the number of notes
char notes[] = "ccggaagffeeddc "; // a space represents a rest
int beats[] = { 1, 1, 1, 1, 1, 1, 2, 1, 1, 1, 1, 1, 1, 2, 4 };
int tempo = 300;

void playTone(int tone, int duration) {
  for (long i = 0; i < duration * 1000L; i += tone * 2) {
    digitalWrite(speakerPin, HIGH);
    digitalWrite(speakerPin, LOW);

void playNote(char note, int duration) {
  char names[] = { 'c', 'd', 'e', 'f', 'g', 'a', 'b', 'C' };
  int tones[] = { 1915, 1700, 1519, 1432, 1275, 1136, 1014, 956 };
  // play the tone corresponding to the note name
  for (int i = 0; i < 8; i++) {
    if (names[i] == note) {
      playTone(tones[i], duration);

  void setup()
pinMode(8, OUTPUT);
Serial.begin(9600);  //Start the serial connection with the copmuter
pinMode(speakerPin, OUTPUT);
void loop(){                     // run over and over again

for (int i = 0; i < length; i++) {
    if (notes[i] == ' ') {
      delay(beats[i] * tempo); // rest
    } else {
      playNote(notes[i], beats[i] * tempo);
    // pause between notes
    delay(tempo / 2); 
 float temperature = getVoltage(temperaturePin);  //getting the voltage reading from the tem
                    //perature sensor
 temperature = ((temperature .5) * 100);          //converting from 10 mv per degree wit 500
                    // mV offset
                                                  //to degrees ((volatge - 500mV) times 100)
 Serial.println(temperature);                     //printing the result
{                   //olts
if (temperature > 190){
digitalWrite (9, HIGH);
{                   //olts
if (temperature > 190){
digitalWrite (8, HIGH);
 //waiting a second

 * getVoltage() - returns the voltage on the analog input defined by
 * pin
float getVoltage(int pin){
 return (analogRead(pin) * .004882814); //converting from a 0 to 1023 digital range
                                        // to 0 to 5 volts (each 1 reading equals ~ 5 milliv
{                   //olts


sketch_oct17b.ino (2.14 KB)

The improperly posted code does something. Perhaps you'd like to tell us what. You want the code to do something. Perhaps you could be more explicit. "above a certain temperature" doesn't mean anything. "above 495 degrees F" does.

If you put every { on a new line, where it belongs, and use Tools + Auto Format, perhaps the code would make more sense.

Posting it properly (read the damned sticky like you were supposed to BEFORE you posted) would also help.

 temperature = ((temperature .5) * 100);          //converting from 10 mv per degree wit 500

What do you think (temperature .5) is doing? Besides being syntactically invalid.

{                   //olts

What useful information is this comment providing?

 //waiting a second

When the comment and the code disagree, the comment is wrong.

Well, I see you have been indoctrinated into the forum- welcome! Please do read the stickies on what is expected of you - this is for everyone’s benefit.

I am trying to creat a temperature alarm, where at a certain temp the piezo will sound and an LED will go off

Most newbies and a few of us more senior members often make the mistake of coding yourself into a corner - same concept as painting yourself into a corner.
You did not state the model of your temperature sensor with a web link to the specs, but most sensors appropriate to Arduino use have example sketches that demonstrate the most basic usage. Find that example sketch and work with it until you understand every line.

An alarm is just a variable used as a compare or test value. The variable could be
int TempToAlarm = 70;
Or… If you need a decimal and your sensor provides that sensitivity it could be
float TempToAlarm = 69.9;

So if you wish to know if the temperature is 70 or greater you could test
if ( CurrentTemp >= TempToAlarm ) {

Note: Comparison Operators. == (equal to) != (not equal to); < (less than); > (greater than); <= (less than or equal to); >= (greater than or equal to)

Point is, build upon working cods code. Save your sketches with a suffix such as 01…99 so that you can go back to the last working sketch. Sketches aepre ASCII and take very little disk space - you can clean-up at the end of the project.

Good luck. If you need to come back for help, remember to do your reading assignment first. There is only a finite number of members I can help a night and it takes a long time to recite rules of the forum. Thanks.