2020-5-28 14:14:11 [显示全部楼层]
2915浏览
查看: 2915|回复: 2

[项目] 喝饱水的植物开心的哼唱一首‘黑人抬棺曲’

[复制链接]
本帖最后由 gada888 于 2020-5-28 14:32 编辑

最近风靡全球的‘黑人抬棺舞’开始进入创客视野,国内创客也得开始做点什么,来加入这一元素。这个项目就是用一些基本元件搭建一个浇花系统,并使得喝到水的植物用一首名曲来表达心情。虽然主题有点无厘头,黑色幽默。但从轮回角度看这个主题,似乎也没那么的悲伤。

喝饱水的植物开心的哼唱一首‘黑人抬棺曲’图5
连好线后,把土壤传感湿水,然后水泵浇水三秒,最后喇叭播放‘抬棺舞曲’


言归正传。项目用到的物料:物料除了12v电池组和水泵,其余均来自DFRobot官方商城,技术参数可以参考官方wiki
1.Arduino uno Romeo---1
2.蜂鸣器---1
3.继电器---1
4.土壤传感---1

以下是物料的电学特性。
蜂鸣器
喝饱水的植物开心的哼唱一首‘黑人抬棺曲’图1
继电器
喝饱水的植物开心的哼唱一首‘黑人抬棺曲’图2
土壤传感
喝饱水的植物开心的哼唱一首‘黑人抬棺曲’图3
水泵
喝饱水的植物开心的哼唱一首‘黑人抬棺曲’图4

连线图
喝饱水的植物开心的哼唱一首‘黑人抬棺曲’图6
代码如下:
[mw_shl_code=applescript,false]/*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_B0  31
#define NOTE_C1  33
#define NOTE_CS1 35
#define NOTE_D1  37
#define NOTE_DS1 39
#define NOTE_E1  41
#define NOTE_F1  44
#define NOTE_FS1 46
#define NOTE_G1  49
#define NOTE_GS1 52
#define NOTE_A1  55
#define NOTE_AS1 58
#define NOTE_B1  62
#define NOTE_C2  65
#define NOTE_CS2 69
#define NOTE_D2  73
#define NOTE_DS2 78
#define NOTE_E2  82
#define NOTE_F2  87
#define NOTE_FS2 93
#define NOTE_G2  98
#define NOTE_GS2 104
#define NOTE_A2  110
#define NOTE_AS2 117
#define NOTE_B2  123
#define NOTE_C3  131
#define NOTE_CS3 139
#define NOTE_D3  147
#define NOTE_DS3 156
#define NOTE_E3  165
#define NOTE_F3  175
#define NOTE_FS3 185
#define NOTE_G3  196
#define NOTE_GS3 208
#define NOTE_A3  220
#define NOTE_AS3 233
#define NOTE_B3  247
#define NOTE_C4  262
#define NOTE_CS4 277
#define NOTE_D4  294
#define NOTE_DS4 311
#define NOTE_E4  330
#define NOTE_F4  349
#define NOTE_FS4 370
#define NOTE_G4  392
#define NOTE_GS4 415
#define NOTE_A4  440
#define NOTE_AS4 466
#define NOTE_B4  494
#define NOTE_C5  523
#define NOTE_CS5 554
#define NOTE_D5  587
#define NOTE_DS5 622
#define NOTE_E5  659
#define NOTE_F5  698
#define NOTE_FS5 740
#define NOTE_G5  784
#define NOTE_GS5 831
#define NOTE_A5  880
#define NOTE_AS5 932
#define NOTE_B5  988
#define NOTE_C6  1047
#define NOTE_CS6 1109
#define NOTE_D6  1175
#define NOTE_DS6 1245
#define NOTE_E6  1319
#define NOTE_F6  1397
#define NOTE_FS6 1480
#define NOTE_G6  1568
#define NOTE_GS6 1661
#define NOTE_A6  1760
#define NOTE_AS6 1865
#define NOTE_B6  1976
#define NOTE_C7  2093
#define NOTE_CS7 2217
#define NOTE_D7  2349
#define NOTE_DS7 2489
#define NOTE_E7  2637
#define NOTE_F7  2794
#define NOTE_FS7 2960
#define NOTE_G7  3136
#define NOTE_GS7 3322
#define NOTE_A7  3520
#define NOTE_AS7 3729
#define NOTE_B7  3951
#define NOTE_C8  4186
#define NOTE_CS8 4435
#define NOTE_D8  4699
#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[thisNote];
    tone(7, melody[thisNote], noteDuration);
    int pauseBetweenNotes = noteDuration * 1.30;
    delay(pauseBetweenNotes);
    noTone(7);
  }
}[/mw_shl_code]

代码解释如下:
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_B0  31
#define NOTE_C1  33
#define NOTE_CS1 35

note部分很长,这个部分是定义音符的播放频率

3.AfricaTone(}函数式定义音符播放间隔







汤果  初级技神

发表于 2020-5-28 14:29:11

创意我给满分!
回复

使用道具 举报

20060606  高级技匠

发表于 2020-6-26 06:27:34

抬棺舞曲…………
回复

使用道具 举报

您需要登录后才可以回帖 登录 | 立即注册

本版积分规则

为本项目制作心愿单
购买心愿单
心愿单 编辑
[[wsData.name]]

硬件清单

  • [[d.name]]
btnicon
我也要做!
点击进入购买页面
上海智位机器人股份有限公司 沪ICP备09038501号-4

© 2013-2024 Comsenz Inc. Powered by Discuz! X3.4 Licensed

mail