Skip to content

Knar33/Measure-Chest

Repository files navigation

Measure Chest

I salvaged a 4ohms 1.5W speaker from a phone system we just replaced at my job. I tested playing sound through it using just the arduino with no amplifier and it's loud enough for my needs. In order to not draw too much power I connected it to the arduino with a 120 ohm resistor.

I need some way to store and play audio. I looked into ways to store audio using the Arduino's memory alone, such as this tutorial http://highlowtech.org/?p=1963 but I didn't feel comfortable downloading the audio converter exe add couldn't get the source to run. I grabbed a couple Velleman VMA304 SD Card Logging Shields which will allow me to store up to 2 gigs of audio, which is way more than enough.

If I leave my Arduino plugged into a battery it will drain pretty quickly, so I need a way to turn the device on/off. I considered mounting a little toggle switch through the wood but that would look pretty tacky. Instead, I went to the local American Science and Surplus store and found a pretty powerful Reed switch that I can activate using a rare earth magnet from a little under an inch away. A reed switch is basically a switch that is turned on or off by a magnetic field. The magnet fits perfectly in the latch, so all I need to do to power on the Arduino is to flip the chest's latch open and wait a few seconds for the Arduino to start up.

The last important component is some way to detect how open the chest is. I could use a potentiometer and somehow rig it to the lid, so that opening the lid twists the potentiometer and I can read how far it has opened. I also played around with the idea of having two tilt switches to detect the open/closed states. I decided to go with a 3-axis gyro which, I thought would work by telling me the current x, y, and z rotation of the object. Once I wired it up to the Arduino though I realized it measures the rate of angular change along the 3 axis in Radians per second. Using that though I can very roughly approximate how much the sensor has moved and estimate the current angle. The problem with this approach normally is that there is significant drift in the angle calculation over time, but because the entire thing will reset when the box is fully opened or closed it's good enough for this.

I only care about the Z axis rotation, because that's the direction it will pivot on the chest lid. When the gyro is sitting stationary, the z gyro.z value should be 0.0 (although it actually sits around 0.1 and I don't feel like calibrating it). I define a measurementsPerSecond variable, for example 10 measurements per second ie every 100ms I take a z-axis measurement. This gives me how many radians per second the sensor is rotating at. In order to calculate how many degrees this is, I divide the gyro.z measurement by the measurementsPerSecond value (because we are really looking at 1/10 of a second of movement) then multiplying by 57.2958 which is roughly how many degrees are in a radian. This gives me how many degrees it will move in the timeframe, assuming a constant rotation rate for the duration of the 100ms timeframe. That is a very false assumption though, which leads to drift over time. I take this degree change and add it to a variable that tracks the current z-axis orientation, which I start at 0. When the rotation goes in the other way, it is a negative change and the current angle decreases.

I have a "rotationalThreshold" variable, which is the minimum gyro.z value I consider to be moving (I have it set to 0.05). If the gyro reads between -0.05 and 0.05, it will not do any angle calculations. This is to avoid excess drift and noise.

Audacity https://learn.adafruit.com/adafruit-wave-shield-audio-shield-for-arduino/check-your-files https://www.instructables.com/id/Audio-Player-Using-Arduino-With-Micro-SD-Card/

Logic

About

No description, website, or topics provided.

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages