Project work3:Arduino code and the circuit diagram using arduino

code and the circuit diagram

In order to realise the “music garden”,the most important part is the Arduino code and circuit diagram.

First of all,I will present my Arduino code:(I will show you the way I think as a flow chart at first)

Flow Chart:

code and the circuit diagram

Details:this flow chart is a mode for one single flower pot

IRDs means the sensor

PREVn means the records about whether there are people in front the sensor

When turn on the IRDn and the PREVn equals FALSE,Which will trigger the sound card to play tone(TONEn),then set the PREVn equals TRUE,and time(TIMEn) set up to 0,and that cycle repeats.

Code:

const int sets = 8;
const int tick = 100;
int IRD[sets] = {30, 31, 32, 33, 34, 35, 36, 37};
int music[sets] = {38, 39, 40, 41, 42, 43, 44, 45};
bool previous[sets] = {false, false, false, false, false, false, false, false};
double limit[sets] = {2.0, 2.0, 2.0, 2.0, 2.0, 2.0, 2.0, 2.0};
double time[sets] = {0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0};

void setup() {
// put your setup code here, to run once:
for (int i = 0; i < sets; ++i) {
pinMode(IRD[i], INPUT);
pinMode(music[i], OUTPUT);
digitalWrite(music[i], HIGH);
}
}

void loop() {
// put your main code here, to run repeatedly:
int val;
for (int i = 0; i < sets; ++i) {
val = digitalRead(IRD[i]);
if (val == LOW && !previous[i]) {
digitalWrite(music[i], LOW);
previous[i] = true;
time[i] = 0.0;
}

if (val == LOW && time[i] >= limit[i]) {
digitalWrite(music[i], HIGH);
}
if (val == HIGH) {
previous[i] = false;
digitalWrite(music[i], HIGH);}}

 code and the circuit diagram1

delay(tick);
for (int i = 0; i < sets; ++i) {
time[i] += (double)tick/1000;
}
}

Read more: Project work3:Arduino code and the circuit diagram

Leave a Comment

Your email address will not be published. Required fields are marked *