Tuesday, August 27, 2013

Wind Chimes (Arduino, Raspi, and Magnets!!)


Arduino Uno Talking to Raspi via Serial
I'm going to do a quick post on another project I'm working on.  This is not complete yet, but I'll share my progress to date.

Here's the concept:
I'm building a wind chime that does not actually chime, well, acoustically that is.  Instead, it will allow me to play any sound for a chime instead of a metal or wood clunking sound.  I will capture the "striking" of a "chime" (yes lots of quotes) using analog sensors on the Arduino, and then communicate a command to the Pi via a serial line. I am using the Arduino for it's analog pins and its ability to sample incredibly fast.  I'm using the Pi to play sounds simultaneously (Nope, there is no simultaneous audio shield for the Arduino).  Pi audio is a longer subject worth of its own post. But the audio you hear in the video below will not be the finished product.



Magnetic pendulum
To capture the virtual strike, my plan is to put neodymium magnets around the pendulum hammer and detect when it comes close to one of the chime tubes.  The chime tubes will likely be small copper tubes that don't resonate so there will not actually be a sound when the hammer strikes them.  I have a steampunk/birdcage style wind chime design.  Pictures will post when I have something finished.

Hall Effect chimes
In order to detect the strike, I will be using Hall Effect sensors to determine when the magnetic field comes near and exceeds a threshold.  Hall Effect sensors are incredibly easy to work with, especially with an Arduino.  If you look at the image above, I have five of the sensors wired to five analog pins and my Arduino is simply looping and sampling the value all the time.

What's a Strike?
How do I tell when a chime has been struck?  Well, the Arduino has a setting (in the code) for a threshold.  Should the value go above that threshold, then the chime is considered struck.

How Hard?
I also want to know how hard the pendulum struck, so I am keeping a simple memory buffer for each sensor in the memory of the Arduino and pushing the latest value on the top of that buffer.  When I detect a strike, I read a certain number of samples back in time and determine the difference in magnetic field values.  The greater the difference, the faster the magnet was approaching the chime and the higher the strike strength value is.

What to do with the value?
After the Arduino has determined which sensor and hence chime is struck and how hard, it sends a simple Chime:Value pair across a serial link to the PI.  The Pi is listening for this on its serial port and will do the "sound output" part of the job which I will explain in a moment.

3.3V to 5V
Don't just hook up your Arduino to you PI.  It will break something.  The Arduino is 5V, the Pi is 3.3V.  This goes for the serial pins as well as GPIO.  Fortunately, +Adafruit Industries has a quick and inexpensive fix called a "logic level converter".
Logic Level Converter

This board will convert bi-directional high speed serial and i2c communications between high and low voltage sides.  This is perfect for bridging serial lines between Pi and Arduino.  (I could have just used one channel TX from the Arduino, but I hooked up both TX and RX to be thorough or superstitious).  The picture at the top of this post shows the boards communicating through two of the four possible channels available in this inexpensive solution.


Chiming on the PI

The Pi is listening to the serial port via a simple perl script (if you haven't figured out that is my go to language).  When it receives a Chime:Value pair on the bus, it spins off a thread to play a Chime file (.wav) at Value volume.  And get this, because real wind chimes bounce around the harder the wind blows, I added a function to do a random roll and see if another chime was struck, the probability based on the strength of the first strike (then call recursively).  A really hard strike will results in 3-7 different chimes all sounding in reducing strengths.   The video below shows how the Arduino/Pi wind chime proof of concept sounds as I wave the magnet near the hall effect sensors on the breadboard.



The sounds I used came from freesound.org, the bamboo marimba series.

Next steps:

  • Finish working out the Pi audio issues.  I am going to try the JACK system again for better simultaneous sound and responsiveness.  This is a good link to start with here.
  • Build audio amplifier board (Velleman 7W Mono Audio Amplifier Kit)
  • Design and build way cool wind chime form factor


Look at me!  I'm a squirrel!
I'll post more on this project as it develops.  Back to our regularly scheduled posts on FrankenStein unless I get distracted by another project.  Look! Squirrel!









No comments:

Post a Comment