31st Jan 2022 – Tolu

In this lab we began by recalling the information from codes that we studied in last weeks lab. We then took one of the codes we used and began to look in depth at the functions and the variables of that code to make more sense of it.

Next we took time to look at different softwares/libraries that are available to produce sound on Arduino. I looked at Teensy and Mozzi. These two are similar audio libraries that enhance the function of the one we have on our board. They don’t need any external boards to work and can produce a variety of sounds and sounds can be altered using the builtin audio toolkit which includes things like synthesisers, oscillators and delays.

(Individual research task)

What is mozzi about?

Mozzi allows the production of more complex and interesting growls, sweeps and chorusing atmospherics. These sounds can be quickly and easily constructed from familiar synthesis units like oscillators, delays, filters and envelopes. 

You can use Mozzi to generate algorithmic music for an installation or performance, or make interactive sonifications of sensors and can be done without additional boards.

From listening to the sounds, there is the ability to:

  • modulate amplitude
  • change shapes of waves
  • change sounds using oscillators

What are key features?

  • variable control rate
  • designed to be easy to use & extendable
  • has a broad audio toolkit: oscilators, samples lines, filters etc.

Weird Behaviours

audio glitches can be caused when calling delay or other functions that wait.

analogRead() is replaced by mozziAnalogRead(), which works in the background instead of blocking the processor.

Lab Session – 31/01/22 –

In this session, we discussed our previous blog posts and revised the content from last week. We were then set on the task of finding a few audio libraries for Arduino and below is the research I found.

DFPlayerMini: included within the IDE software libraries page and is a reliable, responsive driver for DFPlayer Mini sound module for Arduino, and functions with SD card readers you can buy from DF and third parties.

ESP8266Audio: Arduino library for parsing and decoding MOD, WAV, MP3, FLAC, MIDI, AAC, and RTTL files and playing them on an I2S DAC

MD_YM2413: the YM2413 can only play one user-defined instrument at a time, with an additional 15 read-only hard-coded instrument profiles available

Mozzi: Expands on the current beeps that the Arduino is capable of, implementing much more complex sounds to be available for playback. You can use Mozzi to generate algorithmic music for an installation or performance.

Musician: This library implements a virtual musician. You can easily ask him to play a melody, based on the MELO music notation from the Melody Library.

Teensy: Audio Library is a toolkit for building streaming audio projects, featuring Polyphonic Playback, Recording, Synthesis, Analysis, Effects, Filtering, Mixing, Multiple Simultaneous Inputs & Outputs, and Flexible Internal Signal Routing.

#include <MozziGuts.h>
#include <Oscil.h>
#include <tables/sin2048_int8.h>

#define CONTROL_RATE 128
Oscil <2048, AUDIO_RATE> aSin(SIN2048_DATA);
Oscil <2048, CONTROL_RATE> kVib(SIN2048_DATA);

float centre_freq = 440.0;
float depth = 0.25;

void setup(){

void updateControl(){
	float vibrato = depth * kVib.next();

int updateAudio(){
	return aSin.next();

void loop(){

So to summarise this Mozzi library tutorial, any Mozzi classes/modules or tables need to be called using the #include <_____>, for example : #include <MozziGuts.h> is the main library, whilst #include <Oscil.h> is used to call the oscillator. #include <tables/sin2048_int8.h> is the Wavetable that corresponds to the sinewave we are using in the example.

Next, we create an instance for the oscillator using Oscil to which we will then alter.

Oscil <table_size, update_rate> name(table_data);

So we input our values into the format above to create something that looks like this below. Note that the table size value typically needs to be a power of two for compatibility. The oscillator uses an audio generator

Oscil <2048, AUDIO_RATE> aSin(SIN2048_DATA);

The Mozzi Library

Today’s worksheet


For this section of the lab we researched the types of libraries that are instilled or can be installed into the arduino software to which we can code.

To find the library, you open arduino software, then go to the sketch tab. once the drop down menu comes up then go down to include library then wait for the additional menu to come up then click on mange library.

Sketch> Include Library > Manage Library

I used the library search to find the following:

  • Search by using audio,uno
  • Search by using sound, uno
  • Search by using music


24th Jan 2021 – Tolu

In the beginning of the lab session we were reminding ourselves of the previous lab and the things we did.

The first task of this weeks lab was to build a circuit that would cause a push button to control a LED using the bread board, Arduino software, switch and resistor. I firstly began by putting all the components in the right place on the breadboard then making sure that my circuit board also had the correct components in the correct place. After doing all this the next step is to put the code into the Arduino software. Making sure that everything is clear and there are no errors. Verify the code and upload the code and check using the switch if the LED is being controlled when you press it. Good for me it worked.

The next task was to use the code that would cause the LED to remain on after the button had been pressed. The code does not really change however it just gives the instruction to Arduino to “store” the value of the integer that keeps the LED on. This is important because without the store function, the LED would not be able to stay on. 0 = LED off and 1 = LED on. The state variable was determining whether the LED was on or off. The end result was that the button worked for me.

Next I used an improved code because there were times that the button was pressed and it wouldn’t register meaning the LED would either not turn on or turn off. The reason for this is because there’s bouncing from the two pieces of metal inside the button. The bouncing is only for a very small distance and happens for a short time, it causes the switch to change between off and on a number of times until the bouncing stops, and Arduino is quick enough to catch this. The outcome still worked for me at times but not consistently so I went ahead to use a code that would help with the bouncing.

The next code was more improved. It wanted to use the change of state (on and off) and keep them so that it was consistent. The main thing in this code was the if state (high and low). This is a point where the code is remembering the previous function. For example if the switch is off, when you press it the LED comes on. Even though it has changed from on to off it remembers the previous state of the LED being off so that when the button is eventually pressed again, the previous remembered function will be applied (The LED turns off).

The next task was Controlling the LED with PWM. Our task was to take advantage of the effect of Persistence of Vision (POV). In the code, by changing delay times if i made the on delay different from the off delay, yI would make the LED brighter by leaving it on for longer, and the LED dimmer by leaving it off or longer. The technique being used here is called pulse-width modulation aka PWM. This is because there is a change in the LED’s brightness by changing the width of the pulse. My end product produced an LED that was dimming and relighting.

Advanced Musical Electronics – 24th Jan Jade Holland


Today we began by looking at the different types of sensors and actuators in the lecture.

A sensor – is a device that detects and responds to some type of input from the physical environment. The specific input could be light, heat, motion, moisture, pressure, or any one of a great number of other environmental phenomena. 


In the lab we used an Arduino to connect a push button and an LED together which would allow the button when pressed to switch on the LED, this then progressed into allowing the led to fade in and out.


Below is the code used from the lab that allowed for the button to switch on the LED and keep it switched on until the button was pressed again.

const int LED = 13; // the pin for the LED
const int BUTTON = 7; // the input pin where the
// pushbutton is connected
int val = 0; // val will be used to store the state
// of the input pin
int state = 0; // 0 = LED off while 1 = LED on
void setup() {
pinMode(LED, OUTPUT); // tell Arduino LED is an output
pinMode(BUTTON, INPUT); // and BUTTON is an input
void loop(){
val = digitalRead(BUTTON); // read input value and store it
// check if the input is HIGH (button pressed)
// and change the state
if (val == HIGH) {
state = 1 - state;
if (state == 1) {
digitalWrite(LED, HIGH); // turn LED ON
} else {
digitalWrite(LED, LOW);

Arduino button switching on/off the LED

Below is a website that I have included that walks through a similar tutorial like the one completed today in the lab.

Arduino LED – Complete Tutorial – The Robotics Back-End (roboticsbackend.com)

There were several versions of the same code but all of them had different improvements as it was found that as the Arduino runs quicker than the time it takes for a human to press the button, it would sometimes flicker. Altering the code allowed for the Arduino to have time to process so now no flickering would occur with the LED.

Controlling light with pulse-width modulation

We then coded the Arduino board to allow an LED light to fade the light from high to low using this code below.

// Fade an LED in and out, like on a sleeping Apple computer
const int LED = 9; // the pin for the LED
int i = 0; // We'll use this to count up and down
void setup() {
pinMode(LED, OUTPUT); // tell Arduino LED is an output
void loop(){
for (i = 0; i < 255; i++) { // loop from 0 to 254 (fade in)

analogWrite(LED, i); // set the LED brightness

delay(10); // Wait 10ms because analogWrite // is instantaneous and we would // not see any change }

for (i = 255; i > 0; i--) { // loop from 255 to 1 (fade out)
analogWrite(LED, i); // set the LED brightness
delay(10); // Wait 10ms

Week 17 – Lab Session Blog

We began the session by revising what we learned last week and looking over our previous Arduino code, line by line.

Screenshot of last weeks code

Next, we recreated a circuit from the worksheet which features a 10K Ohm resistor, a pushbutton, an LED, a breadboard and some jumper wires with our Arduino boards. When the button is pressed the LED lights up

Photograph of the circuit.

We then altered the code to create a version where the button controls the LED in a different capacity. It is interesting that we can leave the circuit the same but we can change the function of the hardware by changing only the code.

Updated Code

We then updated the code further to remove a small bug so that the light stays on when turned on and turns off when pressed again. There is a noise generated by the push of the button which we can counteract within the code to make it much more reliable in its function.

We then created a new more basic circuit and code that allows our LED to fade on and off intermittently.

A short video of the LED fading on and off with the circuit in the background.

This session has been an important coding revision and it is very important to understand what your code is doing, line by line. Otherwise you cannot diagnose errors and you won’t have any deeper understanding of what your code is achieving.

17th January 2021

In the beginning of the session, students that took part in a previous module demonstrated their models that were created. It was cool to see how light could affect sound.

The first thing we did in the lab was to look at the Arduino board. Looking at the different part of the board and identifying specific parts of them making sure that we know where things would be placed.

We began coding using the software Arduino. the first task was to implement the coding that would cause the LED to flash. Making sure that each step was followed I was able to complete this and get the correct outcome.

The next task using Arduino was to experiment with the delay time of the LEDs changing them in the software just to see how a smaller delay time would affect and how a higher delay time would affect the rate at which the LED flashed.

Next we looked at using a function to loop 2 chosen letters for me which were L & H. when performed correctly using the correct format the end product would be automatic looping of L and H as such … LHLHLHLHLH etc. We did this by set up a function that would enable a loop when we were to go into the serial monitor. Making sure that all instructions and functions were written accurately and carefully spaced out, I was able to achieve the final goal.

The final task we did was to substitute our old functions for a new and simple one to get the same end goal of the blinking LED. This was done by first of all naming our function and then pasting it in place of the the long function that was used in the first task. This task was well performed as I had a good outcome with the blinking LED.

Lab Session Notes 17/01/2022

In this session, we began by sharing previous work from a previous years module that was applicable to the current module. Emily’s instrument comprised of a multiple oscillator synth, with multiple monophonic synths assigned to multiple control knobs that alter the pitch.

My own instrument comprises of a light dependent resistor (LDR) to control a monophonic synthesizer within an enclosure. The lighter the environment, the higher the pitch. It was interesting to compare as we never ended up getting to show each other our work last year during the module.

We then plugged in the Arduino and had a go at writing our first code which makes the Arduino LED blink in one second intervals, which is essentially the coding equivalent of “Print (“Hello World!)”.

Figure 1 – Screenshot of the code within the Arduino IDE software

As you can see from figure one, it is incredibly simple to understand the function of the code and it is incredibly concise.

We then adapted our own code by writing our own function to call an if/else statement that would print the value status of either high or low to the serial monitor. I have learned more about the Arduino coding language to which I am very unfamiliar, and is both similar and dissimilar to any coding I have done before.