Making Sound Effects with Arduino

speaker

Sound and Voice Effects

Sound plays an important role in the user experience by adding another layer of depth; making for a more realistic experience.  http://www.robotoid.com/sound/soundingoff-sounds.html

  • Arduino and piezo ~ dual purpose can make sound or be used as a vibration sensor
  • Low-cost option – WT588D ~ $5
  • Other options include the Adafruit Audio sound board $20 and mini computer systems on a board, such as Raspberry Pi or similar $30+.  These devices also need an SD card to provide memory space, more sensitive to vibrations and use more power.

 

SoundFX Lightshow

Using an Arduino Nano on an expansion board with push-buttons, one to play a sound and the other to select a sound effect from a WT588D through a speaker.

For this project, I’ve selected a low-cost option, internal memory, and reasonable sound quality – WT588D-U, this model includes a built-in mini USB port for power and direct programming.  Sound output is amplified by the module and produced by a standard 0.5w 8-ohm speaker or can be connected to an amplified speaker system. The down-side with this module is that it can be difficult to get the programming software and drivers installed and configured.

Using the WT588D voice module connected to a basic speaker, the project can deliver cellular phone quality sound.

More information and tutorials specific to the WT588D:

There are several options for triggering a sound clip to play.  Examining the documentation for this module including the schematic…The sound module has a few modes to select from when working with it.  If there are only a few sounds that need to be triggered then the direct button mode would work without a microcontroller. However, if there are several sound clips, it takes just as many wires to connect to a microcontroller using the following 3-wire configuration:

WT588D-3-line-serial
Three Line Mode=

I’ve taken the time to download sound clips, modify, and organize a few themes.

  • Games – sound effects for the mechanics and the animation, GLaDoS voices from the Portal video game
  • Spooky – selection of spooky sounds for Halloween projects.
  • LCARS – Star Trek computer phrases and sounds.
  • Zelda: Link To The Past – sounds from the video game.

 

 

 

Other themes online:

 

IMG_20180726_072519070
Alien Invasion Slot Machine uses the WT588D board for sound effects.

 

Parts:

  • Arduino Nano
  • Expansion Board
  • USB to mini USB ~ 5ft. cord
  • AC/DC Outlet Power Adapter
  • Project Box
  • WT588D Sound Module
  • 8 x 7-segment Display module
  • (1-4) strips of 10 RGB 12mm LEDs.
  • (2) push-buttons
  • photocell
  • microphone
  • PIR sensor

 

Steps:

Prepare the following for wiring and connect to the expansion board:

  • WT588D with wiring harness and speaker
  • (1-4) strips of 10 RGB 12mm LEDs.
  • 8 x 7-segment Display Module
  • (2) push-buttons
  • photocell
  • microphone
  • PIR sensor

 

Connect the push-buttons to the expansion board and upload test code.

Nano with buttons

Connect strips of 10 RGB 12mm LEDs to the expansion board and upload test code.

Connect the 8×7 segment display module to the expansion board and upload test code.

Nano WT588D

HotGlue WT588DConnect the WT588D with wiring harness and speaker and upload test code.

 

 

Any sensor can be used to trigger specific or random sounds and going even further, a basic neural network could make decisions using multiple sensor inputs.

Connect the photocell to the expansion board and upload test code.

Connect the Microphone to the expansion board and upload test code.

Connect the PIR sensor to the expansion board and upload test code.

 

SoundEffects
Completed SoundFXLight Project

Insert Arduino Nano into Expansion Board and plan to provide power using USB to mini USB cord.  Optionally, AC/DC Outlet Power Adapter

https://youtu.be/kD2SiK95vtk

Enclosing the project

Drill 7/16” – 1/2” holes into the project box:

  • HOLE 1: side
  • USB to mini USB ~ 5ft. cord
  • Optionally, AC/DC Outlet Power Adapter

 

  • HOLE 2:  cover push-button
  • HOLE 3:  cover push-button

 

  • top front side
  • HOLE 4:  (1-4) strips of 10 RGB 12mm LEDs
  • HOLE 5:  speaker connector

 

  • HOLE 6:  side
  • microphone, PIR sensor

 

You can purchase a completed SoundFXLight directly from me as a functioning example.

promini sound
Arduino Pro-Mini directly connected to WT588D

Hot Stuff

Hot Stuff

glue guns
Glue guns

Rather than use a cyanoacrylate or superglue, I use hot glue to keep the connections in place.  I used to have a negative perception of using hot glue because it seemed amateur and trashy. After having dismantled many Furbies and Talking Elmos, I see it frequently makes it in the final product.  I’ve since reconsidered, and now, I like hot glue because it is convenient and can be removed later if there is a need to check a connection or replace a part.

Furby and Friends.jpg
Inside Furby and Elmo

 

IMG_20180801_163126539
Elmer’s Glue-All (All-Purpose) and School Glue

Diffusing and attaching the lights to a project:  Hot glue is the default, commonly and conveniently comes in both clear and milky white!  I also use Elmer’s All Purpose Glue because it comes in white and dries mostly clear, seals surfaces, allows most paints, glitters, powders, and such to be added for effect.

Making

torches
RGB Torches

 

IMG_20180811_203712682
DIY Fountain

 

 

Arduino FastLED Library

RGB Strip

The FastLED library is an impressive piece of work:

https://github.com/FastLED/FastLED/wiki/Basic-usage

After you download and install the library give it a try:

Using an Arduino Uno to calibrate an RGB LED strip.

The purpose of running this example is to determine what settings are needed to use the FastLED library.  For this example I’m using an Arduino Uno. The Uno has a ground pin next to pin 13, so for convenience, I’m using pin 13 as a low-current Vcc for the RGB LED lights strip:

pinMode(13, OUTPUT);
digitalWrite(13, HIGH);

// The data pin is the pin we are using to connect to the Arduino.
// Data pin that led data will be written out over
#define DATA_PIN 12

// How many individual LED modules are on the strip?
#define NUM_LEDS 10

// When using an SPI based chipset, the there should be four wires
// Clock pin only needed for SPI based chipsets when not using hardware SPI
//#define CLOCK_PIN 8

Important configuration setting is to specify the model of LED strips being used.  May require some try-and-error.

      // Uncomment one of the following lines for your leds arrangement.

     // FastLED.addLeds<WS2811, DATA_PIN, RGB>(leds, NUM_LEDS);
      FastLED.addLeds<WS2812, DATA_PIN, RGB>(leds, NUM_LEDS);
      // FastLED.addLeds<WS2812B, DATA_PIN, GRB>(leds, NUM_LEDS);
      // FastLED.setBrightness(CRGB(255,255,255));
      // FastLED.addLeds<GW6205, DATA_PIN, RGB>(leds, NUM_LEDS);

A nice variety of color effects is included with the library.  After trying out the RGBCalibration source code example, make the changes need to Demo Reel and give it a go:  https://github.com/FastLED/FastLED/blob/master/examples/DemoReel100/DemoReel100.ino

Copy the settings for the LED strip to the DemoReel example

Upload and if all goes well, you should see a basic visual effects show.

Lightshow

More

Please share with friends and follow to receive a notification when I publish a new article.

 

IMG_20190605_094809140
Existential Crisis

Making a Lightshow with Arduino

They are in games, decorations, shadow boxes, sign borders, torches, spotlights, and so on…

 

 

 

 

This slideshow requires JavaScript.

Making a Lightshow

Using an Arduino Nano on an expansion board with a push-button to change the color palette mode of the RGB LED strip.  A microphone module is used to detect sound and alter the speed of flashing lights.

Arduino

Why Arduino?

The greatest advantage to using the Arduino family of microcontrollers for these types of projects, is that they are ubiquitous.  Since they are so available, they are inexpensive and you can find open-source software to get started. If you’ve ever had the opportunity to work with an Arduino Uno microcontroller board, then you’ve probably executed the flashing LED example.  Going further, you might attach a button, or switch, to trigger the LED or to turn it off making the project interactive.

There are many sensors that could be connected to the Arduino Uno and setup to trigger events, such as the LED flashing, using threshold values that we would need to experiment with in order to figure out what settings work best for creating the effect we want.

While the examples that come with the Arduino software and the examples included with libraries are an excellent start to a project; the Arduino family of microcontrollers is often grossly underutilized in many projects.  Sure microcontrollers are limited in how many instructions it can run and hitting the program size limit doesn’t take very long when you want to control more than a few blinking LEDs.

Even with creative variable handling and custom libraries, eventually, there is a need for another microcontroller or to move to a larger one.  In my hydroMazing Smart Garden System and in my Alien Invasion Slot Machine projects, I push the Arduino closer to its limits.

Time Management and state and trigger flags

At its most basic, a microcontroller loops through a set of instructions handling each action with the focus of The Red Eye of Sauron from Lord of the Rings.  There are a few interrupts that can be configured should an event be so important to receive the full attention of the microcontroller.  Using some form of time management creates a state machine. If x amount of time has passed since x event, then do something and so on…

“The behavior of state machines can be observed in many devices in modern society that perform a predetermined sequence of actions depending on a sequence of events with which they are presented. Simple examples are vending machines, which dispense products when the proper combination of coins is deposited, elevators, whose sequence of stops is determined by the floors requested by riders, traffic lights, which change sequence when cars are waiting, and combination locks, which require the input of combination numbers in the proper order.” https://en.wikipedia.org/wiki/Finite-state_machine

There are rare instances where: RTOS, AI, neural networks exist on microcontrollers, but that’s best left to software-oriented systems such as a Raspberry Pi.

After trying many different timer and time management libraries I felt they were either too much or not enough of what I was wanting in my timers.  A set of timers that are easy to set, keep track of their own state, and each have their own trigger flags.

Button assumptions

buttons

Interacting with an electronics device such as a microcontroller or computer system is relatively easy and typically provided as an example for developers looking to use the device in their project.  Press a button and an LED illuminates. A button or switch may seem like a simple sensor input, but it’s not.

The device’s system resources are consumed waiting and watching for a button press. When we use a button in a project we typically think of it being activated when pressed.  Then what? What should happen if the user holds the button in the active position? Will the button be counted as pressed once, or is the program going to count each second, or x amount of time, as another button press?  Does the program need to know that the button has been released?

Hardware

I’m going to be adding on a lot of peripheral devices and moving away from basic prototyping.  Rather than using the Arduino Uno and a protoboard or breadboard for this project, I’m using the Arduino Nano on an expansion board.  I’ve created several color palettes by porting the sample code from the FastLED library examples to my base code templates.  with a push-button input to change the color palette mode of the RGB LED strip.

wiring harness

Wiring

Keep it simple using common wiring colors, keep it modular so connections can be made with ease, keep your project sustainable; a part can be replaced rather than the entire system.  The DuPont wire connectors that come with prototyping starter kits makes it easy to create your own custom wiring connections. The wires are easy to solder when a more permanent connection is needed.  I make custom wiring harnesses for neater, cleaner, and more easily connectable modules.

 

Lighting Effects

There many RGB LED options, so I will be focusing on the WS2811/WS2812 modules.  Single RGB LEDs to strings of RGB LEDs in various configurations. Most of the RGB options wilRGB Stripl have three wires for connecting to the microcontroller board and require 5vdc or 12vdc.  Unless you are designing a new printed circuit board, use DC/DC conversion modules to convert your power to the needs of your project.  You might need to step-up voltage from 3v to 5v, or maybe step-down 12v to 5v?

*** The more lights added, the more power needed. ***

The Arduino Uno, and variants, should only be used for directly powering peripheral modules and not devices.  Consider the maximum current consumption when determining what is a device and what is a module.  A string of lights is more of a device as opposed to a panel indicator light, motor controller boards are modules, not the motors they drive, MOSFET boards, not the valves or solenoids that they control.  See Arduino FastLED Library.

 

 

 

 

 

Common Options for Power

  • USB Powered Devices
  • AC/DC wall-wart Power Supplies
  • Rechargeable Batteries
  • Solar Panels
  • power

Parts:

  • Arduino Nano
  • Expansion Board
  • USB to mini USB cord
  • AC/DC Outlet Power Adapter
  • Project Box
  • (1-4) strips of 10 RGB 12mm LEDs.
  • (1) push-buttons
  • microphone

bad connection

Steps:

Insert Arduino Nano into the Expansion Board by carefully pressing the Nano pins into the expansion boards headers.  Note the picture where only half of the pins are correctly inserted.  Plan to provide power using USB to mini USB cord.  Optionally, AC/DC Outlet Power Adapter.

Prepare the following wiring connections to the expansion board by soldering and protecting with heat-shrink:

  • (1-4) strips of 10 RGB 12mm LEDs.
  • (1) push-button
  • microphone

Programming considerations:

  • brightness of lights
  • color palette
  • speed of flashing lights
  • what triggers change?

Connect the push-button to the expansion board.

Connect strip(s) of 10 RGB 12mm LEDs to the expansion board and upload test code.

Optionally, connect the potentiometer to the expansion board and upload test code.

mic and pir

Making projects more interactive

Every sensor gives us a data-point to work with, providing an input so that our program can make a decision based on its current environment or what happens when conditions are met.  Going further with the project, I’ve added a microphone to detect sound, and at a later time, I’ll add a PIR sensor to detect motion.

 

 

Connect the microphone to the expansion board and upload test code.

Lightshow Inside

Complete the project with an enclosure.

  • Drill 7/16” – 1/2” holes into the project box:
  • HOLE 1: side ~ USB to mini USB cord ~ Optionally, AC/DC Outlet Power Adapter
  • HOLE 2:  cover ~ push-button
  • HOLE 3:  side ~ 1-4 x strips of 10 RGB 12mm LEDs

Lightshow

More:

Solar-Rechargeable Decorations

Phoenix Fire Lily:  Solar rechargeable battery connected to a flickering LED inside an artificial lily flower residing in a hand-crafted wooden vase.

IMG_20180731_145416444IMG_20180825_170808853lily

I don’t know about you, but I rarely have money to spend on projects and whenever possible reusing and re-purposing junk is ideal.  Many of my projects contain parts I’ve purchased at local dollar stores and items found through eBay.

IMG_20180808_174135637
Discount hackables!!

 

Parts:

  • Artificial Lily Flower
  • Flickering LED
  • Thermostat Wire
  • 100-330ohm Resistor
  • Mini switch
  • Solar-panel ~ 5vDC
  • Rechargeable Li-ion Coin-cell Battery
  • Rechargeable Li-ion Coin-cell Battery charger = TP4056 Mini USB 1A Lithium Battery Charger Module
  • USB to mini USB ~ 5ft. cord
  • Optional ~ hand-crafted vase station

Steps:

IMG_20180826_135523525

  • Cut the end of the stem and remove the wire.

IMG_20180826_135554418

  • Gut the Artificial Lily Flower by removing its pistil.

IMG_20180826_135814012IMG_20180826_134320215

  • Using a 8-10″ length of Thermostat Wire that extends just beyond the end of the lily’s stem, solder a 100-330ohm resistor to flickering LED and/or later near the mini switch inside the recycled case.

Do I really need a resistor?

  • Clear LED without resistor = 30mA @ 3vDC
  • Flickering Yellow LED ~ 6mA @ 3vDC
  • salvaged 10 LED string of lights = 6mA @ 3vDC

 

  • Carefully thread the wired LED through the lily and down her stem.

IMG_20180826_135619996

  • Add a piece of heat-shrink tubing, solder jumper wires, and attach connector header.

IMG_20180826_134646442

  • Solder a set of short jumper wires to the Rechargeable Li-ion Coin-cell Battery charger output.
  • Solder the Rechargeable Li-ion Coin-cell Battery charger output short jumper wires, resistor, to the mini switch and recycled case ( two “AA” batteries ).

IMG_20180826_134721596

IMG_20180826_134731388

  • Solder the coin-cell battery holder to the Rechargeable Li-ion Coin-cell Battery charger
  • Insert the Rechargeable Li-ion Coin-cell Battery into the Rechargeable Li-ion Coin-cell Battery charger.

IMG_20180826_134228643

A look inside the inexpensive battery case.

IMG_20180826_134310725

  • Gut everything from the case!

IMG_20180826_134428371

  • Drill a few holes.  One for the solar panel wires, and the other for USB connector.

IMG_20180826_134806554

  • Solder a simple switching diode, such as 1N4148, to the positive side.
  • Using short jumper wires, solder the Rechargeable Li-ion Coin-cell Battery charger input to the solar panel ~ 5vDC.

IMG_20180826_140031232

  • Insert the switch and wrap wires so they lay flat inside the case.

IMG_20180826_140138221

  • Test the output.
  • Optionally, attach USB to mini USB cord to the charger
  • Store inside a hand-crafted vase station.

IMG_20180731_145416444IMG_20180825_170808853lily

 

You can purchase a completed Phoenix Fire Lily directly from me as a functioning example.

lily base partslily base v2

 

More:

Keep Fingers Out of your Pi

In my previous article , I explain how to setup the Raspberry Pi to be a web server.   I also demonstrate searching log files for “footprints” from the IP requests that have been made to your web server.  Now, I would like to discuss protecting your web server from becoming a victim to a potentially malicious attack.

Keep your Pi updated!

sudo rpi-update

The command will automatically update the Raspberry Pi’s firmware and then ask for a reboot.  If your Pi is already up-to-date, then you can continue with:

sudo apt-get update
sudo apt-get upgrade

Now, you’ve got the latest and greatest firmware and software!!

2016-11-04-092217_1920x1080_scrot

Pi Passwords

Ideally, we would disable the default pi account,  at the very least, set the default password for your pi account.  Another major in-security is that most users have SSH (Secure Socket sHell) and VNC (Virtual Networking Computer) enabled so that they can remote into their machines.  I don’t recommend allowing access outside of your network when running a publicly exposed web server.

Apache Web Server

If you are serving web content world-wide then you’ll eventually want to adopt some sort of blacklist, or exclusion list, where you can keep specific IP addresses from accessing your server.  However, if you want to tighten-down your security and only allow a select few access then you’ll need to make some changes.

cd /etc/apache2
sudo cp apache2.conf apache2.conf.bak
sudo vi apache2.conf OR sudo nano apache2.conf

Travel down the file until you reach this section that allows everyone access to your web server from the outside:

<Directory /var/www/>
 Options Indexes FollowSymLinks
 AllowOverride None
 Require all granted
</Directory>

The AllowOverride directive is set to None meaning we will not be using an .htaccess file to override these settings.  The next directive, Require is set to all granted, meaning allow anyone access.

UPDATE:  I have found a significant number of bot requests in my log files, snooping for those of Us using phpmyadmin, be sure to limit access:

<Directory /usr/share/phpmyadmin/>
Order Deny, Allow
Deny from All
# localhost
Allow from 127.0.0.1
# Local-Area Network
Allow from 192.168.x.x
</Directory>

Next, we can add a directory that we want to protect:

<Directory /var/www/html/hydroMazing/>
 Options Indexes FollowSymLinks
 AllowOverride All
</Directory>

The AllowOverride directive is set to All meaning we will be using an .htaccess file to override these settings.  We will provide the Require directive in our .htaccess file inside the directory we specified, in this case, “/var/www/html/hydroMazing/”   One last setting of importance before we save:

# AccessFileName: The name of the file to look for in each directory
# for additional configuration directives. See also the AllowOverride
# directive.
#
AccessFileName .htaccess

You could change the name of the .htaccess file here to something harder to guess.  Keep the dot at the beginning because it means hidden file.   Use your imagination 😉  Now you can use an .htaccess file as your whitelist, or inclusion list:

To create a .htaccess ( or whatever you’ve named it ) file:

cd /var/www/html/mydirectory/

sudo vi .htaccess OR sudo nano .htaccess
# Allow access to localhost 
Require ip 127.0.0.1

# Allow access to my cell phone
Require ip 98.97.34.23

Second entry is an example, change it to your IP address, or the IP address that your web server logged.  See my previous article for instructions on checking your log files.  Save and close the file.  You can add additional access as desired.

 

Build a Wallimg_20160814_195916221

Install the open-source firewall builder

Pop open a terminal from your Raspberry Pi’s desktop and type the following:

sudo apt-get install fwbuilder

After the installation has completed, you will have a new option under the Menu/Internet option from your desktop for the firewall builder GUI.

Add a new firewall and name it the same as your server.

 2016-11-04-090801_1920x1080_scrot

Select the “web server” template to load default rules.

Note that the default rules restrict your server from accessing the outside Internet.  In order to allow access, you’ll need to add a rule.  The easiest way to add a rule is to copy an existing rule that is similar to your needs.

2016-11-04-090900_1920x1080_scrot

Compile and Install

We can build our firewall through this interface, but we won’t be able to install it because we won’t have sufficient permissions to write to the file system.  Enter the following at a terminal window’s command line assuming you named your server the same as your DDNS name:

sudo mkdir /etc/fw
sudo touch /etc/fw/servername.ddns.net.fw
sudo chmod 777 /etc/fw/servername.ddns.net.fw

Now, you should be able to use the firewall builder program to compile and install the firewall.   You can either restart the apache web server or simply reboot.

Anything incorrect, missing, or not working?  Please let me know.

Security through Obscurity

 

Security and Obscurity

“In security engineering, security through obscurity (or security by obscu58688968_1920_1080rity) is the reliance on the secrecy of the design or implementation as the main method of providing security for a system or component of a system. A system or component relying on obscurity may have theoretical or actual security vulnerabilities, but its owners or designers believe that if the flaws are not known, that will be sufficient to prevent a successful attack. Security experts have rejected this view as far back as 1851, and advise that obscurity should never be the only security mechanism.”  https://en.wikipedia.org/wiki/Security_through_obscurity

We often rely on our security being through some sort of obscurity.  “If they don’t know about it, they can’t use it to get in.”  Common household door locks only have so many combinations, yet we can rely on the lock of our front doors because we know that a thief would have to try every combination or break-the-door-down.  However, on the Internet, who is watching your front door, so a thief cannot try every combination?  Fortunately, our web-server has an access.log file that is automatically updated and archived for us.  Let’s start there and see if anyone has left their “footprints” on your web server.

Is anyone trying to gain access?

wget-shellshock-johnIf you are running a LAMP setup on a Raspberry Pi , open-up a terminal window and type in the following:

cd /var/log/apache2/
zcat access.log* | awk '{print $1}' | sort -n | uniq -c | sort -nr | head -20

 

The output should be a list with two columns, one containing the number of entries counted, and the second column is the IP address associated with each web request made.  The easiest way to get the most information from a reverse IP lookup is by using the following command:

curl ipinfo.io/REPLACE.WITH.IP.ADDRESS.TO.LOOKUP

13117907603_3cce4123de_z

Rather than rely on an external web service, you can do some digging after you install some tools that are not included by default with the Pi:

sudo apt-get install geoip-bin
geoiplookup IP.ADDRESS

Here is a good article on using geoiplookup.  Even more advanced digging not included by default with the Pi:

sudo apt-get install dnsutils
dig -x IP.ADDRESS

Does the location seem suspicious?  Try grepping for the activity, the zgrep command includes the compressed files:

zgrep 'IP.ADDRESS' access.log* -1

By looking at the web requests that were made from the IP address, you can determine whether the activity is suspicious.  Typically, you will find that these IP addresses are from bots looking for vulnerabilities in your security.  You can manually block IP addresses to your blacklist or you can just deny all and allow select IP addresses.  If you haven’t already, you’ll want to install and setup a firewall.

Power to the People!

We believe you shouldn’t need expensive gadgets and technical expertise to be a successful gardener. We are committed to a greener planet!

A handy IndoorGardeningChecklist – print yourself a copy!


Image Credits: Power to the People, Patrick Nygren 2014.
Creative Commons Commercial Use License.