Skip to content

Instantly share code, notes, and snippets.

@h4ck4life
Created October 2, 2013 18:11
Show Gist options
  • Save h4ck4life/6798030 to your computer and use it in GitHub Desktop.
Save h4ck4life/6798030 to your computer and use it in GitHub Desktop.
Arduino Uno R3 temperature sensor + buzzer sample code. Read more here: http://alif.my/2013/10/project-2-temperature-sensor-buzzer/
float temp;
int tempPin = 0;
int buzzer=8; //Connect the buzz positive Pin to Digital Pin 8
void setup()
{
pinMode(buzzer,OUTPUT); //Set Pin Mode as output
Serial.begin(9600);
beep(500);
}
void loop()
{
//digitalWrite(buzzer,LOW);
temp = analogRead(tempPin);
temp = temp * 0.48828125;
if(temp > 35) { beep(50); beep(50); }
Serial.print("TEMPRATURE = ");
Serial.print(temp);
Serial.print(" Celcius");
Serial.println();
delay(1000);
}
void beep(unsigned char delayms){
digitalWrite(buzzer,HIGH);
delay(delayms); // wait for a delayms ms
digitalWrite(buzzer,LOW);
delay(delayms); // wait for a delayms ms
}
@rogerin19
Copy link

How can i make this code interact with Matlab? I know I can create a GUI but i am not sure what is the KEY word or code to make this happen

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment