喝饱水的植物开心的哼唱一首‘黑人抬棺曲’
本帖最后由 gada888 于 2020-5-28 14:32 编辑最近风靡全球的‘黑人抬棺舞’开始进入创客视野,国内创客也得开始做点什么,来加入这一元素。这个项目就是用一些基本元件搭建一个浇花系统,并使得喝到水的植物用一首名曲来表达心情。虽然主题有点无厘头,黑色幽默。但从轮回角度看这个主题,似乎也没那么的悲伤。
https://v.youku.com/v_show/id_XNDY4OTU5OTc3Ng==.html?spm=a2hzp.8244740.0.0
连好线后,把土壤传感湿水,然后水泵浇水三秒,最后喇叭播放‘抬棺舞曲’
言归正传。项目用到的物料:物料除了12v电池组和水泵,其余均来自DFRobot官方商城,技术参数可以参考官方wiki
1.Arduino uno Romeo---1
2.蜂鸣器---1
3.继电器---1
4.土壤传感---1
以下是物料的电学特性。
蜂鸣器
继电器
土壤传感
水泵
连线图
代码如下:
/*This sketch is made by gada888 in 2020-05-20*/
const int AirValue = 520; //you need to change this value that you had recorded in the air
const int WaterValue = 260; //you need to change this value that you had recorded in the water
int intervals = (AirValue - WaterValue)/3;
int soilMoistureValue = 0;
const int Relay = 8;
#define NOTE_B031
#define NOTE_C133
#define NOTE_CS1 35
#define NOTE_D137
#define NOTE_DS1 39
#define NOTE_E141
#define NOTE_F144
#define NOTE_FS1 46
#define NOTE_G149
#define NOTE_GS1 52
#define NOTE_A155
#define NOTE_AS1 58
#define NOTE_B162
#define NOTE_C265
#define NOTE_CS2 69
#define NOTE_D273
#define NOTE_DS2 78
#define NOTE_E282
#define NOTE_F287
#define NOTE_FS2 93
#define NOTE_G298
#define NOTE_GS2 104
#define NOTE_A2110
#define NOTE_AS2 117
#define NOTE_B2123
#define NOTE_C3131
#define NOTE_CS3 139
#define NOTE_D3147
#define NOTE_DS3 156
#define NOTE_E3165
#define NOTE_F3175
#define NOTE_FS3 185
#define NOTE_G3196
#define NOTE_GS3 208
#define NOTE_A3220
#define NOTE_AS3 233
#define NOTE_B3247
#define NOTE_C4262
#define NOTE_CS4 277
#define NOTE_D4294
#define NOTE_DS4 311
#define NOTE_E4330
#define NOTE_F4349
#define NOTE_FS4 370
#define NOTE_G4392
#define NOTE_GS4 415
#define NOTE_A4440
#define NOTE_AS4 466
#define NOTE_B4494
#define NOTE_C5523
#define NOTE_CS5 554
#define NOTE_D5587
#define NOTE_DS5 622
#define NOTE_E5659
#define NOTE_F5698
#define NOTE_FS5 740
#define NOTE_G5784
#define NOTE_GS5 831
#define NOTE_A5880
#define NOTE_AS5 932
#define NOTE_B5988
#define NOTE_C61047
#define NOTE_CS6 1109
#define NOTE_D61175
#define NOTE_DS6 1245
#define NOTE_E61319
#define NOTE_F61397
#define NOTE_FS6 1480
#define NOTE_G61568
#define NOTE_GS6 1661
#define NOTE_A61760
#define NOTE_AS6 1865
#define NOTE_B61976
#define NOTE_C72093
#define NOTE_CS7 2217
#define NOTE_D72349
#define NOTE_DS7 2489
#define NOTE_E72637
#define NOTE_F72794
#define NOTE_FS7 2960
#define NOTE_G73136
#define NOTE_GS7 3322
#define NOTE_A73520
#define NOTE_AS7 3729
#define NOTE_B73951
#define NOTE_C84186
#define NOTE_CS8 4435
#define NOTE_D84699
#define NOTE_DS8 4978
int melody[] = {
NOTE_AS4, NOTE_AS4, NOTE_AS4, NOTE_AS4,
NOTE_AS4, NOTE_AS4, NOTE_AS4, NOTE_AS4,
NOTE_AS4, NOTE_AS4, NOTE_AS4, NOTE_AS4,
NOTE_AS4, NOTE_AS4, NOTE_AS4, NOTE_AS4,
NOTE_AS4, NOTE_AS4, NOTE_AS4, NOTE_AS4,
NOTE_D5, NOTE_D5, NOTE_D5, NOTE_D5,
NOTE_C5, NOTE_C5, NOTE_C5, NOTE_C5,
NOTE_F5, NOTE_F5, NOTE_F5, NOTE_F5,
NOTE_G5, NOTE_G5, NOTE_G5, NOTE_G5,
NOTE_G5, NOTE_G5, NOTE_G5, NOTE_G5,
NOTE_G5, NOTE_G5, NOTE_G5, NOTE_G5,
NOTE_C5, NOTE_AS4, NOTE_A4, NOTE_F4,
NOTE_G4, 0, NOTE_G4, NOTE_D5,
NOTE_C5, 0, NOTE_AS4, 0,
NOTE_A4, 0, NOTE_A4, NOTE_A4,
NOTE_C5, 0, NOTE_AS4, NOTE_A4,
NOTE_G4,0, NOTE_G4, NOTE_AS5,
NOTE_A5, NOTE_AS5, NOTE_A5, NOTE_AS5,
NOTE_G4,0, NOTE_G4, NOTE_AS5,
NOTE_A5, NOTE_AS5, NOTE_A5, NOTE_AS5,
NOTE_G4, 0, NOTE_G4, NOTE_D5,
NOTE_C5, 0, NOTE_AS4, 0,
NOTE_A4, 0, NOTE_A4, NOTE_A4,
NOTE_C5, 0, NOTE_AS4, NOTE_A4,
NOTE_G4,0, NOTE_G4, NOTE_AS5,
NOTE_A5, NOTE_AS5, NOTE_A5, NOTE_AS5,
NOTE_G4,0, NOTE_G4, NOTE_AS5,
NOTE_A5, NOTE_AS5, NOTE_A5, NOTE_AS5
};
// note durations: 4 = quarter note, 8 = eighth note, etc.:
int noteDurations[] = {
4,4,4,4,
4,4,4,4,
4,4,4,4,
4,4,4,4,
4,4,4,4,
4,4,4,4,
4,4,4,4,
4,4,4,4,
4,4,4,4,
4,4,4,4,
4,4,4,4,
4,4,4,4,
4,4,4,4,
4,4,4,4,
4,4,4,4,
4,4,4,4,
4,4,4,4,
4,4,4,4,
4,4,4,4,
4,4,4,4,
4,4,4,4,
4,4,4,4,
4,4,4,4,
4,4,4,4,
4,4,4,4,
4,4,4,4,
4,4,4,4,
4,4,4,4,
};
void setup() {
Serial.begin(9600); // open serial port, set the baud rate to 9600 bps
pinMode(Relay, OUTPUT);
// Set outputs to LOW
digitalWrite(Relay, LOW);
}
void loop() {
soilMoistureValue = analogRead(A0); //put Sensor insert into soil
if(soilMoistureValue > WaterValue && soilMoistureValue < (WaterValue + intervals))
{
Serial.println("Very Wet");
digitalWrite(Relay, LOW);
}
else if(soilMoistureValue > (WaterValue + intervals) && soilMoistureValue < (AirValue - intervals))
{
Serial.println("Wet");
digitalWrite(Relay, LOW);
}
else if(soilMoistureValue < AirValue && soilMoistureValue > (AirValue - intervals))
{
Serial.println("Dry");
digitalWrite(Relay, HIGH);
delay(3000);
digitalWrite(Relay, LOW);
AfricaTone();
}
delay(100);
}
void AfricaTone(){
for (int thisNote = 0; thisNote < 112; thisNote++) {
int noteDuration = 750 / noteDurations;
tone(7, melody, noteDuration);
int pauseBetweenNotes = noteDuration * 1.30;
delay(pauseBetweenNotes);
noTone(7);
}
}
代码解释如下:
1.const int AirValue = 520; //you need to change this value that you had recorded in the air
const int WaterValue = 260; //you need to change this value that you had recorded in the water
int intervals = (AirValue - WaterValue)/3;
这一部分是定义土壤传感的浇水参数,主要参考是官方wiki
2.#define NOTE_B031
#define NOTE_C133
#define NOTE_CS1 35
note部分很长,这个部分是定义音符的播放频率
3.AfricaTone(}函数式定义音符播放间隔
创意我给满分! 抬棺舞曲…………
页:
[1]