Category Archives: Tutorials

“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.

“Virtuoso” an Arduino musical instrument

Introduction

Virtuoso is a program that plays different sequences of pre-defined notes. There are  seven push buttons which(each) add  one note  to the sequence. You can choose between two different octaves bye pressing and releasing each button. Also there are two potentiometers for changing “Tempo” and adding “Tremolo” effect.

Virtuoso_circuit

Schematics

Below is the schematics for the circuit which works with the Virtuoso program:

Circuit_Virtuoso

As shown above 7 push buttons are used on digital inputs (pulled down within  1 – 10K ohm range to ground) and two potentiometers (potentiometers can be any range from 1K to 50K ohm) are on Analog inputs (0 to 5V scale).
If you intend to increase the number of buttons simply copy the same component and connections. If more analog inputs needed the same applies. You can use a variety of sensors (LDRs, IR/Ultra Sonic distance meters, Force sensors, etc.) instead of the potentiometers. In such a case, you can simply take the potentiometer out and place the other sensor instead (as an analog voltage).
Code
Dowload the code from here.
Here is another version of the code which works with three push buttons [With the same configuration in the schematic above.Read the instructions in the code]
Uses part of the code provided by Jaxon BK (http://www.blackkat.org/Arduinoise/Arduinoise.html)

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


Pulse Width Modulation

This video does a good job explaining PWM.

Allen Smith

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.

Arduino and RF(nRF24L01+)

One of the cool things you can do with Arduino is interfacing with RF modules.There are different types of RF boards available in the market. We are going to work with “nrf24L01+”Transceiver chip from NordicSemiconductor
Mounted on a breakout board from
Sparkfun.

Before you start

For this project you need two Arduino boards and two RF modules. Download and install  this library for Arduino program(Mirf). Extract the files and put (the folder) in the Library folder in the Arduino installation path:
Windows: “\arduino-1.0.1\libraries\”
OS X: “/Applications/Arduino.app/Contents/Resources/Java/libraries”
You must restart Arduino Program after installing above libraries.

The Circuit

The project consists of a sender and a receiver . The connections for the nrf 24L01+ for the sender and receiver is as picture below

In the sender circuit you also need to connect a potentiometer to pin A0 as shown here: 

On the receiver side add a LED as shown below:

Now download  the code for the sender and receiver below and upload it to the Arduinos:

Sender

Receiver

By changing the potentiometer on the sender side you see the LED on the receiver side changes intensity.

The code used in this post is slightly changed version of the code from http://www.bajdi.com/playing-with-nrf24l01-modules/

Arduino driving a motor with Pololu MC33887 / Seed Studio L298 Motor Driver

Introduction


There are different approaches to driving a motor when it comes to driving  a motor with Arduino. If a simple relay is used to drive a motor it can only turn the motor on and off. In case a single transistor like TIP120 (BJT) or IRF510 (MOSFE ) is used, it is possible to control the speed of the rotation. There exist smarter DC motor drivers (so called H-bridge) that can control the direction of rotation and even brake.

Seed Studio L298 Motor Driver

H-bridge_2_pot

Use this sketch and schematics above, compile and upload it to your Arduino. By changing the position of the potentiometer you should be able to change the rotation speed and direction of the motor.
Motor driver manual can be found here.

MC33887 Motor Driver

An example of such a driver is Plolu’s MC33887 Motor Driver which is affordable and versatile. This driver can control a single DC motor with maximum consumption of 2.5A and peaks of 5A. Motor voltage can range from 5-28V which makes it an excellent general purpose motor driver.

Table below describes the marking of the pins on the back side of the MC33887 driver board from Pololu:

Interfacing MC33887 Motor Driver with Arduino

In order to drive a motor with Arduino you will need the components below:

  • A DC motor (5-12V)
  • A Breadboard
  • A Pololu MC338870 driver board
  • An Arduino with a USB cable
  • Some wires
  • A DC Jack connector
  • An adapter matching the voltage of your motor (less than 5-12V)
  • 10-50KΩ Potentiometer

Make the circuit shows below:

Your circuit should look like this:

Use this sketch, compile and upload it to your Arduino. By changing the position of the potentiometer you should be able to change the rotation speed and direction of the motor.

More info:

The circuit suggested above is the simplest form of using an MC338870 to drive a motor. By using D1 and D2, Disable1 and Disable2, one can leave the motor pins in tri-state. FS, Fault Signal, pin can be used to determine malfunction of the driver. FB, Feed Back, can aslo be read with the analog inputs to determine the amount of current being consumed by the motors.