Here are some random electronics projects from 2021 – 2022.
- For Thermodynamics/Statistical Mechanics: A Rudimentary Sous Vide
- For Digital Design and Computer Architecture: A Music Machine
For Thermodynamics/Statistical Mechanics: A Rudimentary Sous Vide
A Sous Vide is a type of cooking apparatus that holds a bath of water at a specific temperature. You place the food you want cooked in this water-bath, and it eventually comes to thermal equilibrium with the water. You can thus bring any food to the perfect internal temperature you desire. This is quite effective for large cuts of meet and other delicate items where consistency in texture across all parts of the item is necessary.
I sought out to build a poor but low cost version of this piece of equipment with an electric water kettle, an arduino, a water temperature sensor, a stepper motor, and some ice. The general logic works as follows: We set a desired temperature we want to heat the water to. The electric kettle heats the water to that temperature. When the water temperature exceeds our desired temperature, the stepper motor pulls back a platform with some ice in it and drops some ice into the water. The water temperature is then below the desired temperature, and the kettle adds heat again. This cycle repeats and the water temperature is maintained. A fairly simple control loop.

The ice sits on the platform. When the temperature goes to high, the platform gets pulled back a bit, and a little bit of ice drops into the gap created. I do this because the stepper motor I am using sucks and cannot generate a high amount of torque. Instead of actually pulling or pushing ice, all it has to do is pull a platform and a bit of the friction force generated by the ices gravitational force.
The control loop looks like this in code:

It maps fairly well onto the physical functionality. Voila! A fairly bad sous vide.
For Digital Design and Computer Architecture: A Music Machine
My system plays a little motif from The Downward Spiral and displays the corresponding notes that are played on an LED matrix while also lighting up some little groups of LEDs. It can be generalized to different sets of notes and longer sequences of notes. The ordering of events in the main loop happens as follows: A note is played, the note is displayed on the LED matrix, a random bunch of LEDs light up. This is done with the Red-V Thing Plus and some C code.
My program can only perform these actions with two octaves of notes. However, it can be generalized to more notes if extra frequencies are defined. To get the LED matrix to display the note, it first converts the frequencies to their corresponding characters (ex: 392 Hz -> G). A method in pwm.h then takes this character in and pulls an assortment of pins high and low to display the note on the matrix. It is only programmed to do this for A, B, C, D, E, F, G, and cannot display any flats or sharps as I could not figure out a way to fit it onto the LED matrix. This is a major limitation. Due to this, all flats and sharps are just generalized onto their natural note.
To light up the bunch of LEDs, a random array of values that is the same size as the array of pitches is populated with numbers between 0 and 2 (there are three LED bunches in total). These correspond to pin values in pwm.h, and as the note plays, the corresponding entry in the random LED array pulls the bunch of LEDs to high and then low once the note finishes. The system executes these actions together by going through each element of each array and playing all of them one at a time, before moving onto the next one. There is a master method that takes in each of the different arrays in their post-processed forms and unrolls them and zips all of them together, so each element is executed in the correct order.
The main function for the code works as follow:
#include <stdio.h>
#include <stdlib.h>
#include "pwm_tx.h"
#define NOTE_F3 174
#define NOTE_E3 165
#define NOTE_G3 196
#define NOTE_A3 220
#define NOTE_B3_FLAT 233
#define NOTE_B3 247
#define NOTE_C4 262
#define NOTE_D4 294
#define NOTE_E4 330
#define NOTE_F4 349
#define NOTE_G4 392
/*
random_range takes a lower and upper bound and then generates a random number in
the range
*/
int random_range(int lower, int upper){
int number = (rand() % (upper - lower + 1)) + lower;
return number;
}
/*
rand_led_arr writes a bunch of random number between 0 and 2 to light some leds
*/
void rand_led_arr(int led_arr[], int notes_num){
for (int i = 0; i < notes_num; i++){
led_arr[i] = random_range(0, 2);
}
}
/*
get_note_array converts the pitches to chars as those are used to display the
notes on the led matrix
*/
void get_note_array(int pitch_in[], char notes[], int notes_num){
for (int i = 0; i < notes_num; i++){
switch(pitch_in[i]){
case 174:
notes[i] = *"F";
break;
case 165:
notes[i] = *"E";
break;
case 196:
notes[i] = *"G";
break;
case 220:
notes[i] = *"A";
break;
case 233:
notes[i] = *"B";
break;
case 247:
notes[i] = *"B";
break;
case 262:
notes[i] = *"C";
break;
case 294:
notes[i] = *"D";
break;
case 330:
notes[i] = *"E";
break;
case 349:
notes[i] = *"F";
break;
case 392:
notes[i] = *"G";
break;
}
}
}
void print_arr_char(char arr_in[], int notes_num){
for (int i = 0; i < notes_num; i++){
printf("%c \n", arr_in[i]);
}
}
void print_arr_int(int arr_in[], int notes_num){
for (int i = 0; i < notes_num; i++){
printf("%d \n", arr_in[i]);
}
}
// g f f e c e d b_flat b_flat a c f
int main(void) {
// initialize led output pins
ledInit();
// initialize pwm stuff
pwmInit();
// initialize matrix stuff
matrixInit();
// main loop
while(1){
// designate the tune
int ds_pitch[] = {NOTE_G4, NOTE_F4, 0, NOTE_F4, NOTE_E4, 0, NOTE_C4, NOTE_E4,
NOTE_D4, NOTE_B3_FLAT, NOTE_B3_FLAT, NOTE_A3, NOTE_C4, NOTE_F3};
// set number of notes in tune
int notes_num = 14;
// make the note and led arrays
char ds_notes[notes_num];
int ds_led_arr[notes_num];
// populate the note and led arrays
get_note_array(ds_pitch, ds_notes, notes_num);
rand_led_arr(ds_led_arr, notes_num);
// set the duration of each note
int ds_duration[] = {600, 600, 300, 600, 600, 300, 300, 600, 600, 300, 300,
300, 300, 300};
// call the methods from pwm.h to start the sequence
sound_and_harmony(ds_pitch, ds_duration, ds_notes, ds_led_arr);
// delay a bit before starting again
delay(600);
}
}
Leave a comment