Using some sensors, I took the real-time readings from the plant to trigger a sound file through SonicPi.
Real-time readings from the sensors are received and compared to check whether they are below the critical levels, and if yes, the Arduino sends out a MIDI note: an F# note for sub-critical levels (when the plant needs watering) and a Bb note when the moisture level rises abruptly ( when the plant is watered).
The MIDI note then goes through a virtual port and a serial bridge.
SonicPi listens to the incoming note on the virtual port and compares whether the incoming note is F# or Bb.
If the former, it triggers a sound file, and if the latter, another sound file.
All in all, the plant is putting up a musical performance of just two notes.
int sensor_pin = A0;
int output_value_new ;
int output_value_old = 0;
int satisfied_note = 0x6A;
int scream_note = 0x66;
int threshold_moisture = 80;
void setup() {
Serial.begin(9600);
Serial.println("Reading From the Sensor ...");
delay(2000);
}
void loop() {
output_value_new= analogRead(sensor_pin);
output_value_new = map(output_value_new,550,0,0,100);
if (output_value_old ==0){
output_value_old = output_value_new;
}
if (output_value_new <= threshold_moisture) {
//Note on channel 1 (0x90), some note value (note), silent velocity (0x00):
noteOn(0x90, scream_note, 0x7F);
delay(100);
}
int output_difference = output_value_new - output_value_old;
if (output_difference >=30){
//Note on channel 1 (0x90), some note value (note), middle velocity (0x45):
noteOn(0x90, satisfied_note, 0x7F);
delay(100);
}
Serial.print("Mositure : ");
Serial.print(output_value_new);
Serial.println("%");
delay(1000);
output_value_old = output_value_new;
}
void noteOn(int cmd, int pitch, int velocity) {
Serial.write(cmd);
Serial.write(pitch);
Serial.write(velocity);
}
-SonicPi Codescreams = "YOUR_SMAPLE_FOLDER_HERE"
satisfied = "YOUR_SMAPLE_FOLDER_HERE"
live_loop :midi_piano do
use_real_time
note, velocity = sync "/midi:loopmidi_port_0:1/note_on"
if note == 102 #Fsharp7
sample screams, rrand_i(1,7)
sleep(rrand_i(1,5))
end
if note == 106 #Bb7
sample satisfied, rrand_i(1,3)
sleep(rrand_i(1,4))
end
end
in_thread do
use_real_time
use_real_time
note, velocity = sync "/midi:loopmidi_port_0:1/note_on"
if note == 106 #Fsharp7
sample screams, rrand_i(1,7)
sleep(rrand_i(2,6))
end
if note == 102 #Bb7
sample satisfied, rrand_i(1,3)
sleep(rrand_i(1,4))
end
end
NOTE: I have made the demonstration video along the lines of those sleazy TV infomercial ads we used to see on cable.
Comments