270e Final Project

From CSclasswiki
Jump to: navigation, search

Julia Chen and Jemimah Charles

Proposal

Overview

The goal of this project is to integrate three Elegoo kit sensors on the Arduino and design a program in which they work together.

Our project will combine a 64-LED matrix display, a sound sensor, and an LED on the breadboard. The LED is sound sensitive to the music playing. The 64-LED matrix display will show a happy face when the music is on, and a sad face when the music is off.

We have picked two sensors we have not worked with before: a sound sensor and 64-LED matrix display. As we are unfamiliar with these sensors, we will need to learn how they work, using both online sources and through trial and error. This unfamiliarity will allow us as users to gauge the benefits and challenges each sensor contains, in regards to the needs of our project. By doing this we will expand our knowledge about what results an Arduino paired with a sensor is capable of producing, along with the challenges that accompanies the different sensors.

Plan

  1. Connect the 64-LED matrix and write a sketch to display our names.
  2. Write a sketch to display happy and sad faces on the 64-LED matrix display.
  3. Wire the LEDs and sound sensor.
  4. Write a sketch to make the input from the sound sensor change the output of the LEDs.
  5. Write a sketch to make the sound sensor input change the display on the 64-LED matrix.
  6. Finish and compile the code, test.

The Project

Materials

  1. Arduino Mega2560
  2. 64-LED matrix display
  3. Red, Green LEDs
  4. Jumper wires
  5. Resistors
  6. Breadboard
  7. Sound Sensor
  8. Female-to-Male wires

Languages and Libraries

Code is in C for the Arduino.

Library: LedControl.

Testing

We will test how the sound sensor works with different frequencies of sound, to ensure that the song picked will allow the sensor to work properly. All songs will be at the same level, as to not interfere with the results of the song. We will test out a variety of smiley faces to ensure the proper expression is chosen. We will also test how the matrix display our names by adding in different names, along with special characters.

During the project, we realized the sound sensor was not sufficiently sensitive to pick up the sound from the speakers of a laptop. It was sensitive to vibrations and was able to pick up sounds from hard surfaces. A range of surfaces were picked and tested: a person speaking into the sensor, a table, a chair, a laptop, a phone, a plate. All of these sounds were picked up by the sound sensor. We picked a table to be the surface used in the video seen in Part 2 and 4 due to the fact that it was easiest to use when executing the code on the Arduino.

Part 1

Using a 64 LED matrix with a Sketch and Arduino, we have spelled out our names, Julia and Jemimah, respectively below. By having a one second delay, the viewer is able to clearly see the letters and piece together the name. Not only is this a testament to what we had learned this semester, but we have also become educators with our new memory game.

Julia:

Ezgif.com-video-to-gif (1).gif

Jemimah:

Ezgif.com-video-to-gif (2).gif

Schematics

This schematic was altered from the following site to fit the needs of the project: https://how2electronics.com/8x8-led-matrix-max7219-arduino/

Sketch-1588651026207.png

Code

/* 
 *  Julia Chen and Jemimah Charles
 *  CSC270 Final project, Spring 2020
 *  
 *  The 64-LED Matrix displays our names, Julia and Jemimah,
 *  with a 1 second delay between letters.
 *  
 *  This code was adapted from what is shown in the video:
 *   https://www.youtube.com/watch?v=TOuKnOG8atk
 *  
 *  The LedControl library can be found at:
 *   https://github.com/wayoda/LedControl
 *  
 */

#include <LedControl.h>

int DIN = 12;
int CS = 11;
int CLK = 10;

LedControl lc = LedControl( DIN, CLK, CS, 1);

void setup() {
  lc.shutdown( 0, false ); // The MAX72XX is in power-saving mode on startup
  lc.setIntensity( 0, 15 ); // Set the brightness to maximum value
  lc.clearDisplay( 0 ); // clear the display
}

/* function prints J-U-L-I-A to the 64-LED matrix with 1 sec delay between letters*/
void julia() {
  // data for characters
  byte j[8] = {B01111110,B00001000,B00001000,B00001000,B00001000,B10001000,B10001000,B11111000};
  byte u[8] = {B00000000,B01000010,B01000010,B01000010,B01000010,B01000010,B00100100,B00011000};
  byte l[8] = {B00100000,B00100000,B00100000,B00100000,B00100000,B00100000,B00100000,B00111111};
  byte i[8] = {B01111110,B00010000,B00010000,B00010000,B00010000,B00010000,B00010000,B01111110};
  byte a[8] = {B00011000,B00100100,B01000010,B01000010,B01111110,B01000010,B01000010,B01000010};

  lc.setRow(0,0,j[0]);
  lc.setRow(0,1,j[1]);
  lc.setRow(0,2,j[2]);
  lc.setRow(0,3,j[3]);
  lc.setRow(0,4,j[4]);
  lc.setRow(0,5,j[5]);
  lc.setRow(0,6,j[6]);
  lc.setRow(0,7,j[7]);
  delay(1000);

  lc.setRow(0,0,u[0]);
  lc.setRow(0,1,u[1]);
  lc.setRow(0,2,u[2]);
  lc.setRow(0,3,u[3]);
  lc.setRow(0,4,u[4]);
  lc.setRow(0,5,u[5]);
  lc.setRow(0,6,u[6]);
  lc.setRow(0,7,u[7]);
  delay(1000);

  lc.setRow(0,0,l[0]);
  lc.setRow(0,1,l[1]);
  lc.setRow(0,2,l[2]);
  lc.setRow(0,3,l[3]);
  lc.setRow(0,4,l[4]);
  lc.setRow(0,5,l[5]);
  lc.setRow(0,6,l[6]);
  lc.setRow(0,7,l[7]);
  delay(1000);

  lc.setRow(0,0,i[0]);
  lc.setRow(0,1,i[1]);
  lc.setRow(0,2,i[2]);
  lc.setRow(0,3,i[3]);
  lc.setRow(0,4,i[4]);
  lc.setRow(0,5,i[5]);
  lc.setRow(0,6,i[6]);
  lc.setRow(0,7,i[7]);
  delay(1000);

  lc.setRow(0,0,a[0]);
  lc.setRow(0,1,a[1]);
  lc.setRow(0,2,a[2]);
  lc.setRow(0,3,a[3]);
  lc.setRow(0,4,a[4]);
  lc.setRow(0,5,a[5]);
  lc.setRow(0,6,a[6]);
  lc.setRow(0,7,a[7]);
  delay(1000);
}

/* function prints J-E-M-I-M-A-H to the 64-LED matrix with 1 sec delay between letters*/
void jemimah(){
  //data for characters
  byte j[8] = {B01111110,B00001000,B00001000,B00001000,B00001000,B10001000,B10001000,B11111000};
  byte e[8] = {B01111110,B01000000,B01000000,B01111110,B01000000,B01000000,B01000000,B01111110};
  byte m[8] = {B01000001,B01100011,B01010101,B01011101,B01001001,B01000001,B01000001,B01000001};
  byte i[8] = {B01111110,B00010000,B00010000,B00010000,B00010000,B00010000,B00010000,B01111110};
  //byte m[8] = {B01000001,B01100011,B01010101,B01011101,B01001001,B01000001,B01000001,B01000001};
  byte a[8] = {B00011000,B00100100,B01000010,B01000010,B01111110,B01000010,B01000010,B01000010};
  byte h[8] = {B01000010,B01000010,B01000010,B01111110,B01000010,B01000010,B01000010,B01000010};

  lc.setRow(0,0,j[0]);
  lc.setRow(0,1,j[1]);
  lc.setRow(0,2,j[2]);
  lc.setRow(0,3,j[3]);
  lc.setRow(0,4,j[4]);
  lc.setRow(0,5,j[5]);
  lc.setRow(0,6,j[6]);
  lc.setRow(0,7,j[7]);
  delay(1000);

  lc.setRow(0,0,e[0]);
  lc.setRow(0,1,e[1]);
  lc.setRow(0,2,e[2]);
  lc.setRow(0,3,e[3]);
  lc.setRow(0,4,e[4]);
  lc.setRow(0,5,e[5]);
  lc.setRow(0,6,e[6]);
  lc.setRow(0,7,e[7]);
  delay(1000);

  lc.setRow(0,0,m[0]);
  lc.setRow(0,1,m[1]);
  lc.setRow(0,2,m[2]);
  lc.setRow(0,3,m[3]);
  lc.setRow(0,4,m[4]);
  lc.setRow(0,5,m[5]);
  lc.setRow(0,6,m[6]);
  lc.setRow(0,7,m[7]);
  delay(1000);

  lc.setRow(0,0,i[0]);
  lc.setRow(0,1,i[1]);
  lc.setRow(0,2,i[2]);
  lc.setRow(0,3,i[3]);
  lc.setRow(0,4,i[4]);
  lc.setRow(0,5,i[5]);
  lc.setRow(0,6,i[6]);
  lc.setRow(0,7,i[7]);
  delay(1000);

  lc.setRow(0,0,m[0]);
  lc.setRow(0,1,m[1]);
  lc.setRow(0,2,m[2]);
  lc.setRow(0,3,m[3]);
  lc.setRow(0,4,m[4]);
  lc.setRow(0,5,m[5]);
  lc.setRow(0,6,m[6]);
  lc.setRow(0,7,m[7]);
  delay(1000);

  lc.setRow(0,0,a[0]);
  lc.setRow(0,1,a[1]);
  lc.setRow(0,2,a[2]);
  lc.setRow(0,3,a[3]);
  lc.setRow(0,4,a[4]);
  lc.setRow(0,5,a[5]);
  lc.setRow(0,6,a[6]);
  lc.setRow(0,7,a[7]);
  delay(1000);

  lc.setRow(0,0,h[0]);
  lc.setRow(0,1,h[1]);
  lc.setRow(0,2,h[2]);
  lc.setRow(0,3,h[3]);
  lc.setRow(0,4,h[4]);
  lc.setRow(0,5,h[5]);
  lc.setRow(0,6,h[6]);
  lc.setRow(0,7,h[7]);
  delay(1000);
}

void loop(){
  julia();
  jemimah();
  delay(1000);
}


Part 2

We wrote a sketch so that when the sound sensor detects a loud enough sound, an LED on the breadboard turns on. We found that the sound sensor doesn't pick up soft sounds, but works consistently with a louder sound vibration (such as hitting on a table).

Ezgif.com-video-to-gif.gif

Schematics

This schematic was altered from the following site to fit the needs of the project: https://create.arduino.cc/projecthub/iotboys/control-led-by-clap-using-arduino-and-sound-sensor-e31809

Sketch-1588652251680.png

Code

/* 
 *  Julia Chen and Jemimah Charles
 *  CSC270 Final project, Spring 2020
 *  
 *  The LED will turn on when sound is detected from the sound sensor.
 *  
 *  This code was adapted from:
 *   https://create.arduino.cc/projecthub/iotboys/control-led-by-clap-using-arduino-and-sound-sensor-e31809
 *  
 */

// pins for LED and sound sensor
int soundSensor = 29;
int LED = 31;

void setup(){
  pinMode(soundSensor, INPUT); 
  pinMode( LED, OUTPUT);
}

void flash(){
  // if the sound sensor picks up sound, turn on LED
  int statusSensor = digitalRead( soundSensor );
  if (statusSensor == 1 ){
    digitalWrite(LED, HIGH );
    delay( 1000 );
  }
  else{
    digitalWrite( LED, LOW );
    delay( 1000 );
  }
}

void loop(){
  flash();
  delay( 1000 );
}


As we noted, the sensor didn't seem to be picking up softer sounds. In the final code used for the sound sensor we deleted the one second delays in the flash function. By doing this we were able to make the sensor more sensitive and reactive to sound.

Part 3

We connected the 64-LED matrix and sound sensor to the Arduino. Using the sketch below we made a happy face appear on the 64-LED matrix when sound was detected, and a sad face appear when no sound was detected. To ensure we could see the changes we added a 1 second delay between changing faces.

Ezgif.com-video-to-gif (4).gif

Schematics

This schematic was altered from the following site to fit the needs of the project: https://create.arduino.cc/projecthub/iotboys/control-led-by-clap-using-arduino-and-sound-sensor-e31809

Sketch-1588654217800.png

Code

/* 
 *  Julia Chen and Jemimah Charles
 *  CSC270 Final project, Spring 2020
 *  
 *  The 64-LED matrix will display a happy face when sound is detected 
 *  from the sound sensor, and a sad face if no sound is detected.
 *  
 *  This code was adapted from the two sources:
 *   https://create.arduino.cc/projecthub/iotboys/control-led-by-clap-using-arduino-and-sound-sensor-e31809
 *   https://www.youtube.com/watch?v=TOuKnOG8atk
 *  
 */

#include <LedControl.h>

// pins for 8x8 LED matrix
int DIN = 12;
int CS = 11;
int CLK = 10;

LedControl lc = LedControl( DIN, CLK, CS, 1);

void setup() {
  // setup for 8x8 matrix
  lc.shutdown( 0, false ); // The MAX72XX is in power-saving mode on startup
  lc.setIntensity( 0, 15 ); // Set the brightness to maximum value
  lc.clearDisplay( 0 ); // clear the display
}

void writeSmile() {
  /* data for characters */
  byte smile[8] = {0x3C, 0x42, 0xA5, 0x81, 0xA5, 0x99, 0x42, 0x3C};

  /* display one by one */
  lc.setRow(0,0,smile[0]);
  lc.setRow(0,1,smile[1]);
  lc.setRow(0,2,smile[2]);
  lc.setRow(0,3,smile[3]);
  lc.setRow(0,4,smile[4]);
  lc.setRow(0,5,smile[5]);
  lc.setRow(0,6,smile[6]);
  lc.setRow(0,7,smile[7]);
  delay(1000);
}

void writeFrown() {
  /* data for characters */
  byte frown[8] = {0x3C, 0x42, 0xA5, 0x81, 0x99, 0xA5, 0x42, 0x3C};

  /* display one by one */
  lc.setRow(0,0,frown[0]);
  lc.setRow(0,1,frown[1]);
  lc.setRow(0,2,frown[2]);
  lc.setRow(0,3,frown[3]);
  lc.setRow(0,4,frown[4]);
  lc.setRow(0,5,frown[5]);
  lc.setRow(0,6,frown[6]);
  lc.setRow(0,7,frown[7]);
  delay(1000);
}

void flash(){
  int statusSensor = digitalRead( soundSensor );
  // if the sound sensor picks up sound, put happy face on 64-LED matrix
  if (statusSensor == 1 ){
    writeSmile();
    delay( 1000 );
  }
  else{
    writeFrown();
    delay( 1000 );
  }
}

void loop(){
  flash();
  delay( 1000 );
}


We had similar issues with the sound sensor sensitivity with this part. With the same change of deleting the delays in the flash function in the final version of our code, the sound sensor was more reactive to sound.

Part 4

We connected all the sensors together by combining the sketches used previously. However, after experimenting more with Part 2, we changed the code for the flash() function. By deleting delays and changing the order of the function we made the sound sensor more sensitive and accurate.

Now, when sound is detected we have the 64-LED matrix displaying a happy face and the LED on the breadboard turning on simultaneously. When no sound is detected the 64-LED matrix displays a sad face and the LED on the breadboard is off. Our project can be seen in action below:

Ezgif.com-video-to-gif (3).gif

Schematics

This schematic was altered from the following site to fit the needs of the project: https://create.arduino.cc/projecthub/iotboys/control-led-by-clap-using-arduino-and-sound-sensor-e31809

Sketch-1588654683220.png

Code

/* 
 *  Julia Chen and Jemimah Charles
 *  CSC270 Final project, Spring 2020
 *  
 *  The 64-LED matrix will display a happy face when sound is detected 
 *  from the sound sensor, and a sad face if no sound is detected.
 *  Simultaneously, when sound is detected an LED on the breadboard turns
 *  on, and is off otherwise.
 *  
 *  This code was adapted from code found at several sources:
 *   https://www.youtube.com/watch?v=TOuKnOG8atk
 *   https://create.arduino.cc/projecthub/iotboys/control-led-by-clap-using-arduino-and-sound-sensor-e31809
 *  
 */


#include <LedControl.h>

// pins for 8x8 LED matrix
int DIN = 12;
int CS = 11;
int CLK = 10;

LedControl lc = LedControl( DIN, CLK, CS, 1);

// pins for LED and sound sensor
int soundSensor = 29; //connected to D0 pin on sound sensor
int LED = 31;

void setup() {
  // setup for 8x8 matrix
  lc.shutdown( 0, false ); // The MAX72XX is in power-saving mode on startup
  lc.setIntensity( 0, 15 ); // Set the brightness to maximum value
  lc.clearDisplay( 0 ); // clear the display

  // setup for LED and sound sensor
  pinMode(soundSensor, INPUT); 
  pinMode( LED, OUTPUT);
}

/* function prints happy face to the 64-LED matrix*/
void writeSmile() {
  /* data for characters */
  byte smile[8] = {0x3C, 0x42, 0xA5, 0x81, 0xA5, 0x99, 0x42, 0x3C};

  /* display one by one */
  lc.setRow(0,0,smile[0]);
  lc.setRow(0,1,smile[1]);
  lc.setRow(0,2,smile[2]);
  lc.setRow(0,3,smile[3]);
  lc.setRow(0,4,smile[4]);
  lc.setRow(0,5,smile[5]);
  lc.setRow(0,6,smile[6]);
  lc.setRow(0,7,smile[7]);
}

/* function prints sad face to the 64-LED matrix*/
void writeFrown() {
  /* data for characters */
  byte frown[8] = {0x3C, 0x42, 0xA5, 0x81, 0x99, 0xA5, 0x42, 0x3C};

  /* display one by one */
  lc.setRow(0,0,frown[0]);
  lc.setRow(0,1,frown[1]);
  lc.setRow(0,2,frown[2]);
  lc.setRow(0,3,frown[3]);
  lc.setRow(0,4,frown[4]);
  lc.setRow(0,5,frown[5]);
  lc.setRow(0,6,frown[6]);
  lc.setRow(0,7,frown[7]);
}

void flash(){
  int statusSensor = digitalRead( soundSensor );
  // if the sound sensor picks up sound, turn on LED and put happy face on 64-LED matrix
  if (statusSensor == 1 ){
    digitalWrite(LED, HIGH );
    writeSmile();
    delay(1000);
    writeFrown();
    digitalWrite( LED, LOW );
  }
}

void loop() {
  flash();
}


Our final flash function is quite different from the previous ones. The main reason was to allow for greater sensitivity by deleting unnecessary 1 second delays. Another reason was to have the 64-LED matrix begin blank by default to give us another way to ensure that the sound sensor was working as we wanted. Once sound is initially detected, a smile appears on the 64-LED matrix and the LED on the breadboard turns on, both for 1 second, before a frown appears on the 64-LED matrix and the LED turns off. The frown remains on the 64-LED matrix until sound is again detected. By deleting the else statement and only checking if sound is detected, we have better control over the displays and timing of displays.

Ultimately, we found that the sound sensor was not sensitive enough to follow our original plan of the LED reacting to a song. Instead we found that the sound sensor was most reactive to being tapped on, or spoken into. With some changes to the software and better sensitivity of the sound sensor, our original goal could be met.

External References

64-LED Matrix Tutorial

  • A tutorial for using the 64-LED matrix.

LedControl Github download

  • Github to download the LedControl library for using the 64-LED matrix.

LED Matrix Editor

  • An online LED matrix letter editor.

Control LED Using Clap Tutorial

  • A tutorial for wiring and programming an LED to respond to sounds detected by the sound sensor.