Jak wiadomo herbatę zieloną zaparzać należy w temperaturze 80° Celsiusza. Postanowiłem zrobić prosty układ, który będzie tego pilnował. Po zagotowaniu wody w czajniku wkładam czujnik i czekam aż da znać melodyjką, że można zaparzać herbatę (80°C). Zaparzam w zaparzarce. Następnie przelewam do kubka, wkładam czujnik i czekam, aż da znać inną melodyjką, że woda nadaje się do posłodzenia miodem (40°C). Proste.
PODŁĄCZENIE:
Przy budowie czujnika korzystałem ze strony uczymy.edu.pl. I właśnie napisał do mnie właściciel witryny, żeby ostrożnie podłączać większe buzzery, które mogą przepalić wyjście płytki Arduino i będzie kłopot. Tu instrukcja jak to zrobić bezpiecznie z pomocą tranzystora. Dzięki za pomoc.
Przypominam jeszcze, że do grania melodii potrzebujemy biblioteki “pitches.h”. Tu instrukcja jak ją pobrać.
KOD:
#include "pitches.h"
const int tempMaxGreenTea=83;
const int tempMinGreenTea=79;
const int tempMaxHoney=42;
const int tempMin=39;
float lastTemp=22;
void setup(){
Serial.begin(9600);
//Serial.println("czekam");
pinMode(LED_BUILTIN, OUTPUT);
tone(8, 1000, 250);
}
void loop(){
//playTeaForTwo();
float temperatura = pomiarTemperaturyMCP9700();
//Serial.print("lastTemp: ");
//Serial.println(lastTemp);
Serial.print("MCP9700: ");
Serial.println(temperatura);
float roznica=lastTemp-temperatura;
// sprawdzamy jak szybko spada temperatura.
//Jeśli szybko - termometr wyjęty, jeśli w. ujemna - termometr dopiero włożony
Serial.print("Roznica: ");
Serial.println(roznica);
if (roznica>=0 && roznica<1 ){
if ((temperatura>tempMinGreenTea) && (temperatura<tempMaxGreenTea))
{ playTeaForTwo();};
if ((temperatura<tempMaxHoney) && (temperatura>tempMin))
{ playHoney();};
digitalWrite(LED_BUILTIN, HIGH);
}
else
{
digitalWrite(LED_BUILTIN, LOW);
}
delay(3000); // zwłoka ustawiona tak, by odnotować szybkość zmian temperatury
lastTemp=temperatura;
}
float pomiarTemperaturyMCP9700() {
//Pobierz wartosc na pinie A0 i zamien na napiecie, 5V max
float temp = ( analogRead(A0) * 5.)/1023;
//Odejmij 500mv na 0stC
temp = temp - .5;
//Podziel na 10mV.
temp = temp / 0.01;
temp = temp - 6;
return (temp);
}
void ledblinking() {
digitalWrite(LED_BUILTIN, HIGH); // turn the LED on (HIGH is the voltage level)
delay(200); // wait for a second
digitalWrite(LED_BUILTIN, LOW); // turn the LED off by making the voltage LOW
delay(200); // wait for a second
}
void playHoney(){
//Honeysuckle rose standard
int melody[] = {
NOTE_C5, NOTE_AS4, NOTE_D4, NOTE_F4, NOTE_A4,
NOTE_C5, NOTE_AS4, NOTE_D4, NOTE_F4, NOTE_A4,
NOTE_C5, NOTE_AS4, NOTE_D4, NOTE_F4, NOTE_A4, NOTE_A4, NOTE_A4,
NOTE_A4, NOTE_G4, NOTE_F4, NOTE_D4, NOTE_F4, NOTE_F4, NOTE_F4,
NOTE_A4, NOTE_G4, NOTE_F4, NOTE_D4, NOTE_F4, 0
};
int noteDurations[] = {
2, 1, 2, 1, 6,
2, 1, 2, 1, 6,
2, 1, 2, 1, 3, 3, 6,
2, 1, 2, 1, 3, 3, 12,
2, 1, 2, 1, 12, 12
};
for (int thisNote = 0; thisNote < sizeof(melody)/sizeof(int); thisNote++) {
int noteDuration = 100 * noteDurations[thisNote];
tone(8, melody[thisNote], noteDuration);
// to distinguish the notes, set a minimum time between them.
// the note's duration + 30% seems to work well:
int pauseBetweenNotes = noteDuration * 1.30;
delay(pauseBetweenNotes);
noTone(8);
}
}
void playMelody2(){
int melody[] = {NOTE_A5, NOTE_F5, NOTE_E5, NOTE_D5};
int noteDurations[] = {3, 2, 1, 6};
// iterate over the notes of the melody:
for (int thisNote = 0; thisNote < sizeof(melody)/sizeof(int); thisNote++) {
// to calculate the note duration, take one second
// divided by the note type.
//e.g. quarter note = 1000 / 4, eighth note = 1000/8, etc.
int noteDuration = 200 * noteDurations[thisNote];
tone(8, melody[thisNote], noteDuration);
// to distinguish the notes, set a minimum time between them.
// the note's duration + 30% seems to work well:
int pauseBetweenNotes = noteDuration * 1.3;
delay(pauseBetweenNotes);
//stop the tone playing:
noTone(8);
}
}
void playTeaForTwo(){
//Tea for two
int melody[] = {
NOTE_F5, NOTE_D5, NOTE_E5, NOTE_D5, NOTE_F5, NOTE_D5, NOTE_E5, NOTE_C5,
NOTE_E5, NOTE_C5, NOTE_D5, NOTE_C5, NOTE_E5, NOTE_C5, NOTE_D5, NOTE_C5,
NOTE_F5, NOTE_D5, NOTE_E5, NOTE_D5, NOTE_F5, NOTE_D5, NOTE_E5, NOTE_C5, NOTE_A5, 0
};
int noteDurations[] = {
3, 1, 3, 1, 3, 1, 3, 1,
3, 1, 3, 1, 3, 1, 3, 1,
3, 1, 3, 1, 3, 1, 3, 1, 8, 8
};
for (int thisNote = 0; thisNote < sizeof(melody)/sizeof(int); thisNote++) {
int noteDuration = 140 * noteDurations[thisNote];
tone(8, melody[thisNote], noteDuration);
// to distinguish the notes, set a minimum time between them.
// the note's duration + 30% seems to work well:
int pauseBetweenNotes = noteDuration * 1.30;
delay(pauseBetweenNotes);
noTone(8);
}
}
/*void playPipsLong(){
tone(8, NOTE_C3, 500);
delay(4000);
}
void playPipsShort(){
tone(8, NOTE_B5, 250);
delay(250);
tone(8, NOTE_FS5, 250);
}*/
