Töö protsess:
Kood juhib buzzer, mis mängib meloodiat antud nootide põhjal. Noodid ja nende rütm on määratletud notes и beats massiividega.
Kasutatud:
1x Arduino UNO
1x Buzzer
4x Juhtmed
Kood:
const int buzzerPin = 13;
// pikkus on nootide ja pausite koguste summa
const int songLength = 18;
char notes[] = "cdfda ag cdfdg gf "; // tähed on noodid ja tühik on paus
// Rütmi seadistamine.
int beats[] = {1,1,1,1,1,1,4,4,2,1,1,1,1,1,1,4,4,2};
// "tempo" meloodia kiirus. Kui väiksem tempo_ siis suurem kiirus.
int tempo = 150;
void setup()
{
pinMode(buzzerPin, OUTPUT);
}
void loop()
{
int i, duration;
for (i = 0; i < songLength; i++)
{
duration = beats[i] * tempo;
if (notes[i] == ' ') // kui noot puudub
{
delay(duration);
}
else
{
tone(buzzerPin, frequency(notes[i]), duration);
delay(duration);
}
delay(tempo/10); // väike paus nootide vahel
}
while(true){}
}
int frequency(char note)
{
int i;
const int numNotes = 8; // nootide kogus
char names[] = { 'c', 'd', 'e', 'f', 'g', 'a', 'b', 'C' };
int frequencies[] = {262, 294, 330, 349, 392, 440, 494, 523};
// kui noot on olemas, siis tagastame selle tiheduse
for (i = 0; i < numNotes; i++)
{
if (names[i] == note)
{
return(frequencies[i]);
}
}
return(0);
}
Foto:

Niiskuse- ja temperatuuriandur
Töö protsess:
DHT11 või DHT22 on temperatuuri ja niiskuse andur Arduino jaoks, see loeb andmeid andurilt ja kuvab need jadamonitoril.
Kasutatud:
DHT11 või DHT22 temperatuuri- ja õhuniiskuse andur
Arduino UNO
DHT sensor library by Adafruit
Foto:

Väike Alarm Süsteem
Töö protsess:
Kood mõõdab andurite abil temperatuuri, valgustaset ja niiskust, kuvab andmed LCD-ekraanil ja aktiveerib helisignaali, kui temperatuur on liiga kõrge või valgustase liiga madal. Samuti muudab kuvatavat temperatuuri Celsiuse ja Fahrenheiti vahel ning kuvab ekraanil naeratava näo sõltuvalt temperatuurist (kurb, kui temperatuur on alla 25, ja õnnelik, kui üle 25).
Kasutatud:
1x Arduino UNO
1x Fototaksis
1x Temperatuuriandur
1x LED 16×2
1x Buzzer
1x Niiskusandur (joonisel pinnase niiskusandur)
1x Potentsiomeeter
1x 220om taksi
1x 10K om taksi
27x Juhtmed
Kood:
#include <LiquidCrystal.h>
LiquidCrystal lcd(12, 11, 5, 4, 3, 2);
const int tempPin = A1;
const int lightPin = A0;
const int humidityPin = A2;
const int buzzerPin = 8;
float temperature;
float voltage;
float degreesF;
int lightLevel;
int humidityLevel;
unsigned long previousMillis = 0;
const long interval = 1000;
unsigned long lastEmojiShowTime = 0;
const long emojiInterval = 10000;
unsigned long lastDegreeSwitch = 0;
bool fDegrees = false;
bool potato = true;
bool lemon = false;
bool minecraft_end = false;
bool dog = true;
bool danger = false;
bool lastDangerState = false;
void setup() {
lcd.begin(16, 2);
pinMode(tempPin, INPUT);
pinMode(lightPin, INPUT);
pinMode(humidityPin, INPUT);
pinMode(buzzerPin, OUTPUT);
}
void loop() {
unsigned long currentMillis = millis();
if (currentMillis - previousMillis >= interval) {
previousMillis = currentMillis;
lightLevel = analogRead(lightPin);
voltage = getVoltage(tempPin);
temperature = (voltage - 0.5) * 100.0;
degreesF = temperature * (9.0 / 5.0) + 32.0;
humidityLevel = analogRead(humidityPin);
danger = false;
if (temperature > 30 || lightLevel < 100) {
danger = true;
}
lcd.clear();
lcd.setCursor(0, 0);
lcd.print("Temp: ");
if (currentMillis - lastDegreeSwitch > 500) {
lastDegreeSwitch = currentMillis;
fDegrees = !fDegrees;
}
if (fDegrees) {
lcd.print(degreesF, 1);
lcd.print(" F");
} else {
lcd.print(temperature, 1);
lcd.print(" C");
}
lcd.setCursor(0, 1);
lcd.print("L:");
lcd.print(1023 - lightLevel);
lcd.print(" H:");
lcd.print(humidityLevel / 10);
if (danger && !lastDangerState) {
playAlarm();
}
lastDangerState = danger;
}
}
float getVoltage(int pin) {
return (analogRead(pin) * 0.004882814);
}
void playAlarm() {
for (int i = 0; i < 3; i++) {
tone(buzzerPin, 1000, 200);
delay(250);
}
noTone(buzzerPin);
}
Foto:

Video:

