Created
March 22, 2020 13:37
-
-
Save polluxlabs/67a200eadbcb030a163b51bf40d0374b to your computer and use it in GitHub Desktop.
An Arduino Organ with Kinder Surprise
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/* | |
Arduino Organ by pollux labs, 2020 | |
More procects and tutorials: https://polluxlabs.net | |
*/ | |
// Import the CapacitiveSensor Library. | |
#include <CapacitiveSensor.h> | |
//Define speaker pin | |
#define speaker 11 | |
//Set sensor sensitivity | |
int sensitivity = 3000; | |
//Set threshold for triggering a tone | |
int threshold = 5000; | |
// Set the Send Pin & Receive Pin. | |
CapacitiveSensor cs_2_4 = CapacitiveSensor(2, 4); | |
CapacitiveSensor cs_2_5 = CapacitiveSensor(2, 5); | |
CapacitiveSensor cs_2_6 = CapacitiveSensor(2, 6); | |
CapacitiveSensor cs_2_7 = CapacitiveSensor(2, 7); | |
CapacitiveSensor cs_2_8 = CapacitiveSensor(2, 8); | |
void setup() | |
{ | |
Serial.begin(115200); | |
} | |
void loop() | |
{ | |
// Set the sensitivity of the sensors | |
long sensor4 = cs_2_4.capacitiveSensor(sensitivity); | |
long sensor5 = cs_2_5.capacitiveSensor(sensitivity); | |
long sensor6 = cs_2_6.capacitiveSensor(sensitivity); | |
long sensor7 = cs_2_7.capacitiveSensor(sensitivity); | |
long sensor8 = cs_2_8.capacitiveSensor(sensitivity); | |
Serial.print(sensor4); | |
Serial.print("\t"); | |
Serial.print(sensor5); | |
Serial.print("\t"); | |
Serial.print(sensor6); | |
Serial.print("\t"); | |
Serial.print(sensor7); | |
Serial.print("\t"); | |
Serial.println(sensor8); | |
// When your hand touches the sensor, the speaker will produce a tone. | |
// Probably you'll have to experiment with the threshold. | |
if (sensor4 > threshold) tone(speaker, 440); // A | |
if (sensor5 > threshold) tone(speaker, 523); // C | |
if (sensor6 > threshold) tone(speaker, 587); // D | |
if (sensor7 > threshold) tone(speaker, 659); // E | |
if (sensor8 > threshold) tone(speaker, 784); // G | |
// When nothing is touched the speaker is quiet | |
if (sensor4 <= threshold & sensor5 <= threshold & sensor6 <= threshold & sensor7 <= threshold & sensor8 <= threshold) { | |
noTone(speaker); | |
} | |
delay(10); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment