Tag Archives: Arduino and Processing

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.

Advertisements

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.

Arduino and Processing, Switch

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

To build the electronic circuit you need the following parts:

  • a switch,
  • a 1kΩ resistor,
  • and a couple of wires.

The schematic for the circuit looks like this:

Switches have three pins. In one position the switch closes the connection between the middle pin an outer pin while the opposite position establishes a connection between the middle pin and the other outer pin. Therefore, we connect 5V to one of the outer pins and the 1kΩ resistor to the middle pin and ground. We will measure ‘between’ the middle pin and the resistor and therefore have a wire leading from there to pin 7 of the Arduino board. 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 the USB  port of your computer. The power LED should light up and the next step is to export the program which reads the state of the switch to the board. Open the ap_ReadDigital.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, see if the control LED lights up when the switch is in ON-position. If that’s the case, you can then download and unzip pa_Switch.zip and open the file pa_Switch.pde in Processing.

List of serial ports in MS Windows and Mac OS X

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

Output of the program

From the middle a red (or blue) bar will start growing to the right (or left), depending on the position of the switch. If you change the position of the switch, the other bar will start growing and when both bars are of equal size they will both turn green. Play around a little bit and you will see that rhythmic switching will maintain the bar green, isn’t that great?