Wednesday 10 March 2010

First steps with Arduino or How to make a cheap, quick, awful synth!





This week I attempted to make the most basic synthesizer using the arduino, some potentiometers and a piezo. So heres the setup,

I put the three potentiometers in a circuit, with a ground and power supply. Then on a separate circuit we plug in a piezo. Each potentiometer is connected to an analog input so the values can be read, and the piezo is connected to a digital pin.

This is basically an upgrade and mish-mash of a few basic examples on potentiometers (http://arduino.cc/en/Tutorial/AnalogInput) and on tones (http://arduino.cc/en/Tutorial/Tone). The piezo generating tones depending on the values given by the potentiometers.



For this synth, as shown in the video, one potentiometer controls frequency (Hz), one duration of tone, and the other the frequency (time) of the tones. It makes a pretty horrible little sound, so I definitely wouldn't watch the whole minute of this video, but I am pretty impressed by how quick this sort of project can be put together.





Complete Code-


int sensorPin = 0;
int sensorPin1 = 1;
int sensorPin2 = 2;//
int ledPin = 13;
float sensorValue = 0;
float sensorValue1 = 0;
float sensorValue2 = 0;

void setup() {
pinMode(ledPin, OUTPUT);
Serial.begin(9600);
}

void loop() {

sensorValue = analogRead(sensorPin); //0-342
sensorValue1 = analogRead(sensorPin1); //343-712
sensorValue2 = analogRead(sensorPin2); //711-1023
Serial.println(sensorValue);
Serial.println(sensorValue1);
Serial.println(sensorValue2);
tone(8, sensorValue, sensorValue1);
delay(sensorValue2);
}

No comments:

Post a Comment