Grew up like this in 4 days. :)
In a meanwhile, I've updated the source code.
/*
* For Automated Mung Bean Sprouts growing machine
*
* Watering every 2 hours
* play music when watering
*
* Relay pin 12
* speaker pin 8
*
* created 22 Jan 2017
*
* updated 24 Jan 2017
* -Added one more song (Butterfly)
* -Randomly select a song (Schoolbell or Butterfly)
* -watering every an hour from every 2 hours.
* -increase watering time (Schoolbell - play 3 times, Butterfly - play 2 times)
*
*by Douglas Changsoo Park
*
*/
#include <SimpleTimer.h>
#include "pitches.h"
int relay = 12;
int melodyPin = 8;
SimpleTimer timer;
int schoolbell_melody[] = {
NOTE_G4, NOTE_G4, NOTE_A4, NOTE_A4, NOTE_G4, NOTE_G4, NOTE_E4, NOTE_G4, NOTE_G4, NOTE_E4, NOTE_E4, NOTE_D4, 0,
NOTE_G4, NOTE_G4, NOTE_A4, NOTE_A4, NOTE_G4, NOTE_G4, NOTE_E4, NOTE_G4, NOTE_E4, NOTE_D4, NOTE_E4, NOTE_C4, 0 };
int schoolbell_noteDurations[] = { 1,1,1,1, 1,1,2, 1,1,1,1, 3,1, 1,1,1,1, 1,1,2, 1,1,1,1, 3,1 };
int butterfly_melody[] = {
NOTE_G4,NOTE_E4,NOTE_E4,NOTE_F4,NOTE_D4,NOTE_D4,NOTE_C4,NOTE_D4,NOTE_E4,NOTE_F4,NOTE_G4,NOTE_G4,NOTE_G4,
NOTE_G4,NOTE_E4,NOTE_E4,NOTE_E4,NOTE_F4,NOTE_D4,NOTE_D4,NOTE_C4,NOTE_E4,NOTE_G4,NOTE_G4,NOTE_E4,NOTE_E4,NOTE_E4,0,
NOTE_D4,NOTE_D4,NOTE_D4,NOTE_D4,NOTE_D4,NOTE_E4,NOTE_F4,NOTE_E4,NOTE_E4,NOTE_E4,NOTE_E4,NOTE_E4,NOTE_F4,NOTE_G4,
NOTE_G4,NOTE_E4,NOTE_E4,NOTE_F4,NOTE_D4,NOTE_D4,NOTE_C4,NOTE_E4,NOTE_G4,NOTE_G4,NOTE_E4,NOTE_E4,NOTE_E4,0
};
int butterflyNoteDurations[] = {
1,1,2,1,1,2, 1,1,1,1,1,1,2, 1,1,1,1,1,1,2, 1,1,1,1,1,1,3,1,
1,1,1,1,1,1,2,1,1,1,1,1,1,2, 1,1,2,1,1,2,1,1,1,1,1,1,3,1
};
void setup() {
// put your setup code here, to run once:
pinMode(relay, OUTPUT);
digitalWrite(relay, HIGH);
//timer.setInterval(7200000, watering);
timer.setInterval(3600000, watering);
//timer.setInterval(25000, watering); // Test Mode
}
void loop() {
// put your main code here, to run repeatedly:
timer.run();
}
void watering() {
digitalWrite(relay, LOW);
int song = random(1,3);
if(song == 1) {
music_schoolBell();
music_schoolBell();
music_schoolBell();
} else {
music_butterfly();
music_butterfly();
}
digitalWrite(relay, HIGH);
noTone(8);
}
void music_schoolBell() {
int size = sizeof(schoolbell_melody) / sizeof(int);
for(int thisNote = 0; thisNote < size; thisNote++) {
int noteDuration = 250 * schoolbell_noteDurations[thisNote];
tone(melodyPin, schoolbell_melody[thisNote], noteDuration);
int pauseBetweenNotes = noteDuration * 1.30;
delay(pauseBetweenNotes);
noTone(melodyPin);
}
}
void music_butterfly(){
int size = sizeof(butterfly_melody) / sizeof(int);
for (int thisNote = 0; thisNote < size; thisNote++) {
int noteDuration = 250 * butterflyNoteDurations[thisNote];
tone(melodyPin, butterfly_melody[thisNote], noteDuration);
int pauseBetweenNotes = noteDuration * 1.30;
delay(pauseBetweenNotes);
noTone(melodyPin);
}
}
'IoT > Arduino' 카테고리의 다른 글
[Arduino] 3rd project. 4X4X4 LED Light Cube (1) | 2017.06.05 |
---|---|
[Arduino Project 2] LED Light stand for 3D Crystal laser cube Ver. 0.4 (0) | 2017.05.08 |
[I don't like you] practice project for the project 'I like you' (0) | 2017.05.07 |
MIT App Inventor - Android App - Mega Millions Jackpot number generator (0) | 2017.01.30 |
Arduino Project 1 - Automated Mung Bean Sprouts Growing Machine (0) | 2017.01.23 |
[Arduino] Motion Sensor and Water Level Sensor (0) | 2017.01.17 |
[Arduino] Joystick, LED Dot Matrix and ADXL335 Module (0) | 2017.01.17 |
[Arduino] Ultrasonic, Keypad and Temperature and Humidity Sensor (0) | 2017.01.15 |
[Arduino] 7 Segment, Servo, LCD and Thermometer (0) | 2017.01.14 |
[Arduino] Using 74HC595 8-bit serial-in/serial or parallel-out shift register (0) | 2017.01.12 |