Pada theremin ini tidak memerlukan sentuhan tangan, jadi kita hanya perlu mengatur jarak antara tangan dan antena tanpa harus menyentuh antenanya. Pada jaman sekarang theremin tidak hanya menggunakan frekuensi radio dan antena tapi berkembang melaui media/sensor yang lain seperti sensor cahaya, piezo dan yang sekarang saya ingin membuatnya dengan menggunakan sensor ultrasonik dan Arduino Uno R3.
Alat dan Bahan:
- Sensor Ultrasonik HC-SR04
- Arduino Uno R3
- Resistor 100 ohm
- Speaker Kecil
- Kabel Jumper
Koneksi Kabel
- VCC Sensor Ultrasonik → +5V Arduino
- GND Sensor Ultrasonik → GND Arduino
- Trig Sensor Ultrasonik → Pin 12 Arduino
- Echo Sensor Ultrasonik → Pin 11 Arduino
- Speaker (diseri dengan resistor 100 ohm) → Pin 9 Arduino
- Speaker → Pin 10 Arduino
Source Code
/**
* Copyright (c) 2015 by http://www.electrominds.com
* Simple Arduio Theremin "Theremino" Project
* Project URL: http://www.electrominds.com/projects/simple-arduino-theremin-theremino
*
* This file is free software; you can redistribute it and/or modify
* it under the terms of either the GNU General Public License version 2
* or the GNU Lesser General Public License version 2.1, both as
* published by the Free Software Foundation.
*
* Required libraries:
* NewPing: https://code.google.com/p/arduino-new-ping/downloads/detail?name=NewPing_v1.5.zip
* toneAC: https://code.google.com/p/arduino-tone-ac/downloads/detail?name=toneAC_v1.2.zip
*/
#include <NewPing.h>
#include <toneAC.h>
#define DEBUG false // Set to true to enable Serial debug
#define TONE_PIN 8
#define TONE_VOLUME 10 // 1-20
#define TRIGGER_PIN 12 // Board pin tied to trigger pin on the ultrasonic sensor.
#define ECHO_PIN 11 // Board pin tied to echo pin on the ultrasonic sensor.
#define MAX_DISTANCE 200 // Maximum distance we want to ping for (in centimeters). Maximum sensor distance is rated at 400-500cm.
NewPing sonar(TRIGGER_PIN, ECHO_PIN, MAX_DISTANCE);
void setup() {
if (DEBUG) {
Serial.begin(115200);
Serial.println("Theremino starting");
}
}
void loop() {
delay(30); // Wait 30ms between pings (about 33 pings/sec). 29ms should be the shortest delay between pings.
unsigned long uS = sonar.ping(); // Send ping, get ping time in microseconds (uS).
if (DEBUG) Serial.println(uS);
if (uS > 2000) { // Range is about 0-30 cm from sensor
toneAC(0); // Turn sound off when not in range
if (DEBUG) Serial.println("No tone");
} else {
int freq = 1000 - uS / 1.5; // Get sound frequency
toneAC(freq, TONE_VOLUME); // Play it!
if (DEBUG) Serial.println(freq);
}
}
No comments:
Post a Comment