ArduinoTutorial: Sensorium Mozzi

How to use the Sensorium Mozzi library to play two sine waves demonstrating a beat frequency


Download Sensorium Mozzie

Instructions for installing the library


Speaker on pin 9


/*  Example playing two sinewaves at different frequencies
 *  using Mozzi sonification library.
 *  Demonstrates the resultant beat frequency
 *  Circuit: Audio output on digital pin 9 (on a Uno or similar), or 
 *  check the README or
 *  Mozzi help/discussion/announcements:
 *  Michael Shiloh 2013
 *  based on an example by Tim Barrass 2012.
 *  This example code is in the public domain.

#include <MozziGuts.h>
#include <Oscil.h> // oscillator template
#include <tables/sin2048_int8.h> // sine table for oscillator

// use: Oscil <table_size, update_rate> oscilName (wavetable)

// use #define for CONTROL_RATE, not a constant
#define CONTROL_RATE 64 // powers of 2 please

void setup(){
  startMozzi(CONTROL_RATE); // set a control rate of 64 (powers of 2 please)
  aSin.setFreq(440); // set the frequency
  bSin.setFreq(448); // set the frequency

void updateControl(){
  // put changing controls in here

int updateAudio(){
//  return (;
  int; // 8+8=9 bits
  return foo>>2;

void loop(){
  audioHook(); // required here
Print Friendly
Creative Commons License
This work is licensed under a Creative Commons Attribution-ShareAlike 4.0 International License.

Leave a Reply

Your email address will not be published. Required fields are marked *