Skip to content

Instantly share code, notes, and snippets.

@h4ck4life
Created October 2, 2013 18:11
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • 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
}
@GM-Gainji
Copy link

Sir i have this code and working properly but now i want add buzzer to alert if temperature increase
suppose if (temperature > 50) then buzzer beep
please help me

#include<LiquidCrystal.h>
LiquidCrystal lcd(2,4,7,8,9,10);

const int Sensor = A0;
byte degree_symbol[8] =
{
0b00111,
0b00101,
0b00111,
0b00000,
0b00000,
0b00000,
0b00000,
0b00000
};
void setup()
{
pinMode(Sensor, INPUT);
lcd.begin(16,2);
lcd.createChar(1, degree_symbol);
lcd.setCursor(0,0);
lcd.print(" Digital ");
lcd.setCursor(0,1);
lcd.print(" Thermometer ");
delay(4000);
lcd.clear();
}
void loop()
{

 float temp_reading=analogRead(Sensor);
 float temperature=temp_reading*(5.0/1023.0)*100;
 delay(10); 

lcd.clear();
lcd.setCursor(0,0);
lcd.print("Temperature in C");
lcd.setCursor(4,1);
lcd.print(temperature);
lcd.write(1);
lcd.print("C");
delay(1000);

}

@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