이 사이트를 좋아합니다. 여기서 뭘 해줘서 고마워요!Arduino 코드 조합 - 최대 분 온도 코드에서 온도 센서와 부저를 결합하십시오.
마침내 Arduino Uno와 함께 내 프로젝트를 진행하고 있습니다. 나는 단지 그것을 할 때 내가 가장 잘 배웁니다. 내 TMP36GZ 온도를 Ardino를 통해 16x2 LCD에서 읽는 방법에 대한 자습서를 찾았습니다. 멋지다! 하지만 이제 온도가 최대 및/또는 최소에 도달 할 때 CEM1203 (42) 버저를 꺼내는 방법을 알아 내고 싶습니다. 나는 부저가 너무 가도록 간단한 코드를 발견했다. 이제 저는이 두 가지를 결합해야합니다.
다음은 2 코드입니다. temp = =/< 65 ° F 및 => 75 ° F 일 때 부저 소리를 내고 싶습니다.
제공 할 수있는 도움에 감사드립니다. 나는이 물건을 배우는 것에 매우 흥분한다!
/*
Piezo
This example shows how to run a Piezo Buzzer on pin 9
using the analogWrite() function.
It beeps 3 times fast at startup, waits a second then beeps continuously
at a slower pace
*/
void setup() {
// declare pin 9 to be an output:
pinMode(9, OUTPUT);
beep(50);
beep(50);
beep(50);
delay(1000);
}
void loop() {
beep(200);
}
void beep(unsigned char delayms){
analogWrite(9, 20); // Almost any value can be used except 0 and 255
// experiment to get the best tone
delay(delayms); // wait for a delayms ms
analogWrite(9, 0); // 0 turns it off
delay(delayms); // wait for a delayms ms
}
/*
September 12 2013
October 25 2012
Based off of a project by DJ Mentzik.
Enhanced and modified by WWC and citin.
Supporting documents can be found at http://www.instructables.com/member/WWC/
Use and modife as needed.
Displays Current, 8 sec Average, Max and Min Temperature.
To wire your LCD screen to your Arduino, connect the following pins:
LCD Pin 6 to digital pin 12
LCD Pin 4 to digital pin 11
LCD Pin 11 to digital pin 5
LCD Pin 12 to digital pin 4
LCD Pin 13 to digital pin 3
LCD Pin 14 to digital pin 2
LCD PIN 15 to POS
LCD PIN 16 to GND
*/
#include <LiquidCrystal.h> // include the LCD driver library
//declare variables
float tempC = 0; // Variable for holding Celcius temp (floating for decimal points precision)
float tempf = 0; // variable for holding Fareghneit temp
int tempPin = 0; // Declaring the Analog input to be 0 (A0) of Arduino board.
float samples[8]; // Array to hold 8 samples for Average temp calculation
float maxi = 0,mini = 100; // Max/Min temperature variables with initial values. LM35 in simple setup only measures Temp above 0.
int i;
LiquidCrystal lcd(12, 11, 5, 4, 3, 2); // initialize the library with the numbers of the interface pins
void setup()
{
Serial.begin(9600); // Opens serial port, sets data rate to 9600 bps
lcd.begin(16, 2); // Set up the LCD's number of columns and rows:
lcd.setCursor(2, 0); // Set LCD cursor position (column, row)
lcd.print("Waynes World"); // Print text to LCD
lcd.setCursor(3, 1); // Set LCD cursor position (column,row)
lcd.print("Thermometer"); // Print text to LCD
delay(5000); // wait 500ms // Delay to read text
lcd.clear(); // clear LCD display // Clear the display
lcd.setCursor(2, 0); // Set LCD cursor position (column, row)
lcd.print("LCD Displayed"); // Print text to LCD
lcd.setCursor(1, 1); // Set LCD cursor position (column, row)
lcd.print(" Averaged Temp "); // Print text to LCD
delay(5000); // Delay to read text
lcd.clear(); // Clear LCD
}
void loop()
{
Serial.println(""); // Blank line for spacing in the serial monitor
Serial.println("You are looking at a project built by WWC."); // Print text to Serial monitor
Serial.print("Feal free to use and modife as needed.");
Serial.println(""); // Blank line for spacing in the serial monitor
Serial.print("LM35 Raw data: "); // Print text to Serial monitor
Serial.println(analogRead(tempPin)); // Displays on serial monitor the sampled value before conversion to real Temperature reading
// Start of calculations FOR loop.
for(i = 0;i<=7;i++){ // gets 8 samples of temperature
samples[i] = (4.4 * analogRead(tempPin) * 26)/1024.0; // conversion math of tmp36GZ sample to readable temperature and stores result to samples array.
Serial.println(samples[i]); // Print samples [i] to sertiual monitor
// (LCD note: line 1 is the second row, since counting begins with 0):
lcd.setCursor(0, 0); // Set LCD cursor position (column 0, row 0)
lcd.print("Current Temp is: "); // Print text to LCD
lcd.setCursor(1, 1); // Set LCD cursor position (column 1, row 1)
lcd.print(" Celcius "); // Print text to LCD
lcd.setCursor(12, 1); // Set LCD cursor position (column 12, row 1)
lcd.print(samples[i]); // print current Temp sample to LCD
tempC = tempC + samples[i]; // do the addition for average temperature
delay(800); // wait 800ms
} // END of FOR loop
Serial.println(""); // Blank line for spacing in the serial monitor
Serial.println(""); // Blank line for spacing in the serial monitor
tempC = tempC/8.0; // calculated the averare of 8 samples in Celcius
tempf = (tempC * 9)/ 5 + 32; // converts to fahrenheit
if(tempC > maxi) {maxi = tempC;} // set max temperature
if(tempC < mini) {mini = tempC;} // set min temperature
if(tempC >16.0)
// Send Results to Serial Monitor
Serial.println("New measurement:");
Serial.print(" Average Temperature in Celcius is "); // Print text to Serial monitor
Serial.println(tempC);//send the data to the computer // Send the data to the computer
Serial.print(" Average Temperature in Farenait is "); // Print text to Serial monitor
Serial.println(tempf);//send the data to the computer // Send the data to the computer
Serial.print(" MAX Temperature in Celcius is "); // Print text to Serial monitor
Serial.println(maxi);//send the data to the computer // Send the data to the computer
Serial.print(" MIN Temperature in Celcius is "); // Print text to Serial monitor
Serial.println(mini);//send the data to the computer // Send the data to the computer
// Send results to LCD.
lcd.setCursor(0, 1); // Set LCD cursor position (column 0, line 1)
lcd.print(" Fahrenheit "); // Print text to LCD
lcd.setCursor(12, 1); // Set LCD cursor position (column 12, line 1)
lcd.print(tempf); // Send the data to the LCD
delay(6000); // Wait 3 seconds to display the Fahrenheit temp and 3 seconds to display results to LCD screen befor starting the loop again = 6 seconds.
tempC = 0; // Set tempC to 0 so calculations can be done again
}