Tag Archives: Physical Computing

“Simple note” an Arduino musical instrument

Introduction

Simple note works like a musical keyboard. It has 8 buttons which you can use to plays notes (C D E F G A B C) similar to a piano. Pitch and duration of the notes (Octaves) can be adjusted by a potentiometers or hard-coded in the code. The video below shows the circuit in action:
Circuit
The board is shown in the picture above. Its better to build the circuit on a bread board before soldering it on a piece of strip board. The schematics for the micro sequencer is shown below:
As shown above 6 push buttons are used on digital inputs (pull up resistors, R1-R6 can be any value from 1K to 10K ohm) and two potentiometers are on Analog inputs (potentiometers can be any range from 1K to 50K ohm).
If you intend to increase the number of buttons or analog inputs simply copy the same component and connections and change the code accordingly. You can use a variety of sensors (LDRs, IR/Ultra Sonic distance meters, Force sensors, etc.) instead of the potentiometers.
Code
This program uses the Arduino tone library to play music. Program reads the eight digital inputs and plays the corresponding tone for that key on digital pin 9 of Arduino. The music signal needs to be amplified with a small amplifier like an LM386 amplifier.
Button 1, 2, 3, 4, 5, 6, 7, 8: C, D, E, F, G, A, B, C tone in order
Analog input 0: Controls the duration of tones, if you don’t want the pot simply hard code “duration” variable in the code
Analog input 1: Controls the (pitch), if you don’t want the pot simply hard code “octave” variable in the code
Download the code from here.
You can change the tones order in the variable “Melody”, so the keys would come in another other like A,B,C,D,E,F,G.
For a complete list of tones that you can use refer to the ‘Public Constants’ here. There you can read about the tone library more.
More info
Here is a simple guide to music and music alphabets. Here you can read about mapping of frequency to notes.
Advertisements

‘Micro sequencer’ an Arduino musical instrument

Introduction

Micro sequencer plays a sequence of 4 randomly chosen tones on Arduino. Tempo (playback speed) and tone length (more like a tremolo) can be controlled via two analog inputs. Four buttons control the octave of the tones where another button is used to generate a new random set of tone sequence. The sequence can be stored in the non volatile memory by pressing another button.

Circuit

The board is shown in the picture above. Its better to build the circuit on a bread board before soldering it on a piece of strip board. The schematics for the micro sequencer is shown below:

As shown above 6 push buttons are used on digital inputs (pull up resistors, R1-R6 can be any value from 1K to 10K ohm) and two potentiometers are on Analog inputs (potentiometers can be any range from 1K to 50K ohm).
If you intend to increase the number of buttons or analog inputs simply copy the same component and connections and change the code accordingly. You can use a variety of sensors (LDRs, IR/Ultra Sonic distance meters, Force sensors, etc.) instead of the potentiometers.
Code

This program uses the tremolo effect that has been developed by  Jaxon BK.
Program reads the inputs listed below and plays back a sequence according to the inputs on digital pin 9 of Arduino. The music signal needs to be amplified with a small amplifier like an LM386 amplifier.

Button 1: Generates a new random tone sequence (keep pressing until you hear a beep)
Button 2: Store the sequence to the non-volatile memory (keep pressing until you hear two beeps)

Button 3-6: Holding these button will affect the octave of the tones being played at that moment. (3 Lowest, 4  Low, 5 High, 6 Highest octave)
Analog input 0: Controls the tempo (playback speed)
Analog input 1: Controls the tremolo (similar to length of playback of the note)
The tone values are also printed on serial port of the Arduino board when button 1 or 2 are pressed. So if you would like to see the frequencies you can open the Arduino serial monitor. Saved data will be loaded upon reset. So, each time you power on or reset your Arduino the saved tone sequence will be loaded from the non-volatile memory.
Do not leave the button 2 unconnected! otherwise the program might try writing to the non-volatile memory all the time.  Pull these pins high if you do not intend to place a switch in your final circuit.

Download the code from here.

More info
Here is a simple guide to music and music alphabets. Here you can read about mapping of frequency to notes.

MMA7260Q Accelerometer, Arduino and Processing

Introduction

Accelerometers can measure acceleration and tilt (angle). They are used in many devices nowadays such as Mobile phones (iPhone), Gaming consoles and gadgets (Nintendo Wii), Navigation (GPS navigators, Airplanes), and etc. In physical computing accelerometers are used to measure device’s position relative to the ground.  A simple Accelerometers can measure acceleration along one axis. Here, a simple program is presented that interfaces a 3-axis MMA7260Q accelerometer from Sparkfun to an Arduino board.

Circuit

Use a MMA7260Q “triple Axis Accelerometer Breakout board” from Sparkfun. Connect the board as shown below to an Arduino board:

Be careful while making connections to your Arduino, not to misconnect the Negative and Positive supply.

Code

Download the code for Processing and Arduino in a zip package here*. Unzip and upload the code provided for the Arduino to your Arduino board. Then run the code provided for Processing. Press ‘X’, ‘Y’, ‘Z’ key on your keyboard to see the real time graph for the corresponding axis on your screen.

The Arduino code sends three consecutive bytes by serial baudrate of 9600. On the computer side the processing program gets the data and translates the bytes (each byte for one axis[X,Y,Z]) into a graph representation.

*.The code is taken from here(Thanks to Daniel Goncalves)

Output of the program in Processing

More info

You can read how accelerometers work Here. For a more Interactive guide please check this link.

12V Lamp on Arduino with a reed relay

Intro

Arduino has a limited current sinking/sourcing capability (less than 40 mili Amps) on its pins. Whenever you intend to switch a device which needs high current or high voltage (like a lamp or a motor) an intermediate circuit is needed. In the simplest case this intermediate circuit is a relay.

Relays

Relay acts as a normal switch, but is triggered with a magnet rather than a handle. Here we use a special kind of relay called reed relay. Such relays come in vacuum enclosures and have excellent performance in terms of being an ideal switch. Whenever driving coils there should be a diode connected across the coil in reverse bias, so it will damp the back EMF produced. However, the relay we are using has this diode across its coils internally, so we don’t need to worry about it.

Circuit

Make the circuit below:

Select the Blink sketch (File>Examples>Digital>Blink) from your Arduino software and upload it to your board. The Lamp on the bread and the LED on your Arduino board should light up at the same time.

More info

Note that similar to any other load, relays draw current. This current can be more than what an Arduino can provide. In such cases you cannot connect the relay directly to an Arduino output. Use a transistor for the relay and a diode to protect against back EMF. Here is an example how to drive such a relay with a transistor.

An easier approach for driving high current/voltage relays is to use a relay driver such as ULN2003 or ULN2803. Here is a sample schematic how to do so (taken from this rocket project).

Arduino and Processing, Potentiometer

This is an updated version of the Potentiometer post from here.

To build the electronic circuit you need the following parts:

  • a 10kΩ potentiometer(You can use any potentiometer < 100kΩ ),
  • a 1kΩ resistor,
  • and a couple of wires.

A potentiometer is a variable resistor. Between the two outer pins you will always measure the (maximum) value of the resistor, while the variable resistance is measure between the middle and an outer pin. That’s where we connect a wire to measure the voltage. The pull-down resistor avoids a short circuit when the variable resistance is set to zero. The circuit on your breadboard should look something like this:

Working circuit on breadboard

If everything is set up right, you can connect the board to USB port of your computer. The power LED should light up the next step is to export the program, which reads the state of the switch to the board. Open the ap_ReadAnalog.pde file in Arduino set the right serial port (from the menu Tools->Serial Port), compile the program, and then click on the Upload icon () to send the program to the board.To check if everything works fine so far, turn the potentiometer to both extremes: the LED should light up/turn off when the potentiometer reaches (approximately) its middle position. If that works fine, you can then download and unzip pa_Potentiometer.zip and open the file pa_Potentiometer.pde in Processing. Then you will have to set the right serial port as described before.

Now, you can run your Processing program. A new window will open and you should see something like this:

Output of the program

As you turn the potentiometer the vertical bar should move as it indicates the value read from the serial port.

Arduino and Processing,Piezo Element

This is an updated version of the Piezo Element post from here.

To build the electronic circuit you need the following parts:

  • a piezo element,
  • a 1MΩ resistor,
  • and a couple of wires.

The schematic for the circuit looks like this:

Working circuit on breadboard

If everything is set up right, you can connect the board to the USB port of your computer.  The power LED should light up and the next step is to export the programm which reads the state of the switch to the board. Open the ap_ReadPiezoKnock.pde file in Arduino, set the right serial port and baudrate, compile the programm, and then press the reset button on your board and click on the export icon to send the program to the board.

To check if everything works fine so far, see if the control LED lights up when the switch is on ON-position. Now, you can download and unzip pa_PiezoKnock.zip and open the file pa_PiezoKnock.pde in Processing. Then you will have to set the right serial port as described before.

Now, you can run your Processing programm. A new window will open and you should see something like this:

Output of the program

Arduino and Processing, LDR

This is an updated version of the LDR post from here.

To build the electronic circuit you need the following parts:

  • a LDR light sensor,
  • a 1kΩ resistor,
  • and a couple of wires.

A LDR light sensor is a variable resistor. Notice, that in this case we use a pull-up resistor (which means that it is located before the sensor). Still, we measure the voltage ‘between’ this resistor and the light sensor. The circuit on your breadboard should look something like this:

Working circuit on breadboard

If everything is set up right, you can connect the board to USB port of your computer. The power LED should light up the next step is to export the program, which reads the state of the switch to the board. Open the ap_ReadAnalog.pde file in Arduino set the right serial port (from the menu Tools->Serial Port) and baudrate (in the code), compile the program, and then click on the Upload icon () to send the program to the board.To check if everything works fine so far, see if the control LED goes off when you cover the sensor with you hand. If it’s turned off you might have to expose it to more light to pass the threshold value and cause the LED to light up. Now, you can download and unzip pa_LDR.zip and open the file pa_LDR.pde in Processing.Then you will have to set the right serial port as described before.

Run your Processing program. A new window will open and you should see something like this:

Program Output

The maximum size of the pulsating circle depends from the quantity of light that hits the sensor. More light will increase the size of the circle, less light will make it smaller.