Luc Paquin
Published © CC BY-ND

Project #16: Sound – Sound Sensor – Mk28

Project #16: Sound – Sound Sensor – Mk28

BeginnerFull instructions provided1 hour13
Project #16: Sound – Sound Sensor – Mk28

Things used in this project

Hardware components

DFRobot FireBeetle 2 ESP32-E
×1
DFRobot Fermion: 2.0" 320x240 IPS TFT LCD
×1
DFRobot GDL Line 10 CM
×1
DFRobot Gravity: IO Shield for FireBeetle 2
×1
DFRobot Gravity: Analog Sound Sensor
×1
DFRobot Gravity: Digital Speaker Module
×1
DFRobot Gravity: Digital RGB LED Module
×1
DFRobot Lithium Ion Battery - 1000mAh
×1
SparkFun Switch
×1
DFRobot USB 3.0 to Type-C Cable
×1

Software apps and online services

Arduino IDE
Arduino IDE

Story

Read more

Schematics

Fritzing

Code

DL2511Mk02p.ino

Arduino
/****** Don Luc Electronics © ******
Software Version Information
Project #16: Sound – Sound Sensor – Mk28
16-28
DL2511Mk02p.ino
DL2511Mk02
1 x DFRobot FireBeetle 2 ESP32-E
1 x Fermion: 2.0" 320x240 IPS TFT LCD
1 x GDL Line 10 CM
1 x Gravity: IO Shield for FireBeetle 2
1 x Gravity: Analog Sound Sensor
1 x Gravity: Digital Speaker Module
1 x Gravity: Digital RGB LED Module
1 x Lithium Ion Battery - 1000mAh
1 x Switch
1 x USB 3.0 to Type-C Cable
*/

// Include the Library Code
// EEPROM Library to Read and Write EEPROM
// with Unique ID for Unit
#include "EEPROM.h"
// Arduino
#include "Arduino.h"
// DFRobot Display GDL API
#include <DFRobot_GDL.h>
// Adafruit NeoPixel
#include <Adafruit_NeoPixel.h>

// Sound Sensor
int iSound = A0;
int iVal = 0;

// Speaker
int iSpeaker = D5;
// Note
#define NOTE_A4  440
#define NOTE_A6  1760

// Which pin on the Arduino is connected to the NeoPixels?
#define iNeo D11
// How many NeoPixels are attached to the Arduino?
#define NUMPIXELS 1
// When setting up the NeoPixel library.
Adafruit_NeoPixel pixels(NUMPIXELS, iNeo, NEO_GRB + NEO_KHZ800);

// Defined ESP32
#define TFT_DC  D2
#define TFT_CS  D6
#define TFT_RST D3

/*dc=*/ /*cs=*/ /*rst=*/
// DFRobot Display 240x320
DFRobot_ST7789_240x320_HW_SPI screen(TFT_DC, TFT_CS, TFT_RST);

// EEPROM Unique ID Information
#define EEPROM_SIZE 64
String uid = "";

// Software Version Information
String sver = "16-28";

void loop() {
  
  // Sound Sensor
  // isSound
  isSound();

  // isDisplaySound
  isDisplaySound();

  // Delay
  delay( 1000 );
  
}

getDisplay.ino

Arduino
// DFRobot Display 240x320
// DFRobot Display 240x320 - UID
void isDisplayUID(){

  // DFRobot Display 240x320
  // Text Display
  // Text Wrap
  screen.setTextWrap(false);
  // Rotation
  screen.setRotation(3);
  // Fill Screen => black
  screen.fillScreen(0x0000);
  // Text Color => white
  screen.setTextColor(0xffff);
  // Font => Free Sans Bold 12pt
  screen.setFont(&FreeSansBold12pt7b);
  // TextSize => 1.5
  screen.setTextSize(1.5);
  // Don Luc Electronics
  screen.setCursor(0, 30);
  screen.println("Don Luc Electronics");
  // SD
  screen.setCursor(0, 60);
  screen.println("Sound Sensor");
  // Version
  screen.setCursor(0, 90);
  screen.println("Version");
  screen.setCursor(0, 120);
  screen.println( sver );
  // EEPROM
  screen.setCursor(0, 150);
  screen.println("EEPROM");
  screen.setCursor(0, 180);
  screen.println( uid );

}
// isDisplaySound
void isDisplaySound(){

  // DFRobot Display 240x320
  // Text Display
  // Text Wrap
  screen.setTextWrap(false);
  // Rotation
  screen.setRotation(3);
  // Fill Screen => white
  screen.fillScreen(0xffff);
  // Text Color => blue
  screen.setTextColor(0x001F);
  // Font => Free Sans Bold 12pt
  screen.setFont(&FreeSansBold12pt7b);
  // TextSize => 1.5
  screen.setTextSize(1.5);
  // Sound Sensor
  screen.setCursor(0, 30);
  screen.println("Sound Sensor");
  // Val
  screen.setCursor(0, 60);
  screen.println( iVal );

  
}

getEEPROM.ino

Arduino
// EEPROM
// isUID EEPROM Unique ID
void isUID() {
  
  // Is Unit ID
  uid = "";
  for (int x = 0; x < 7; x++)
  {
    uid = uid + char(EEPROM.read(x));
  }

}// EEPROM
// isUID EEPROM Unique ID
void isUID() {
  
  // Is Unit ID
  uid = "";
  for (int x = 0; x < 7; x++)
  {
    uid = uid + char(EEPROM.read(x));
  }

}

getSound.ino

Arduino
// Sound Sensor
// isSound
void isSound(){
  
  // Set all pixel colors to 'Off'
  pixels.clear();

  // Read the value from the sensor:
  iVal = analogRead(iSound);
 
  // Sound Sensor
  if( iVal < 20) { 
        
       // The first NeoPixel in a strand is #0, second is 1, all the way up
       // to the count of pixels minus one. // For each pixel...
       for(int i=0; i<NUMPIXELS; i++) { 

          // pixels.Color() takes RGB values, from 0,0,0 up to 255,255,255
          // Green
          pixels.setPixelColor(i, pixels.Color(0, 255, 0));

          // Send the updated pixel colors to the hardware.
          pixels.show(); 

        }

    // Tone
    tone(iSpeaker, NOTE_A4);    

  }
   else{
        
      // The first NeoPixel in a strand is #0, second is 1, all the way up
       // to the count of pixels minus one. // For each pixel...
       for(int i=0; i<NUMPIXELS; i++) { 

          // pixels.Color() takes RGB values, from 0,0,0 up to 255,255,255
          // Red
          pixels.setPixelColor(i, pixels.Color(255, 0, 0));

          // Send the updated pixel colors to the hardware.
          pixels.show(); 

      }

    // Tone
    tone(iSpeaker, NOTE_A6); 
 
  }

}

setup.ino

Arduino
// Setup
void setup()
{
 
  // Delay
  delay( 100 );

  // EEPROM Size
  EEPROM.begin(EEPROM_SIZE);

  // EEPROM Unique ID
  isUID();

  // Delay
  delay( 100 );

  // INITIALIZE NeoPixel strip object
  pixels.begin();

  // Delay
  delay(100);
  
  // DFRobot Display 240x320
  screen.begin();

  // Delay
  delay(100);

  // DFRobot Display 240x320 - UID
  // Don Luc Electronics
  // Version
  // EEPROM
  isDisplayUID();

  // Delay 5 Second
  delay( 5000 );

}

Credits

Luc Paquin
50 projects • 4 followers
Teacher, Instructor, E-Mentor, R&D and Consulting -Programming Language -Microcontrollers -IoT -Robotics -Machine Learning -AI -Sensors

Comments