Cirkit Designer LogoCirkit DesignerYour all-in-one circuit design IDE Launch Cirkit Designer App

Raspberry Pi Zero W Based Sound Detection System with GLCD Feedback

View and Edit Project In Cirkit DesignerImage of Raspberry Pi Zero W Based Sound Detection System with GLCD Feedback

Circuit Documentation

Summary

The circuit in question is designed to interface a Raspberry Pi Zero W with a Graphic LCD Display (GLCD 128x64), a Potentiometer, and a Sound Sensor. The Raspberry Pi Zero W processes audio signals from the Sound Sensor and displays information on the GLCD. The Potentiometer is used to adjust the contrast of the GLCD. The system is capable of detecting specific sound patterns, such as those made by rice weevils, and displaying the results on the GLCD.

Component List

Raspberry Pi Zero W

Graphic LCD Display (GLCD 128x64)

Potentiometer

Sound Sensor

Wiring Details

Raspberry Pi Zero W

Graphic LCD Display (GLCD 128x64)

Potentiometer

Sound Sensor

Documented Code

Raspberry Pi Zero W Code

/*
 * This Arduino Sketch is for a Raspberry Pi Zero W connected to a Sound Detector.
 * The Raspberry Pi processes audio signals picked up by the Sound Detector.
 * The audio signals can be analyzed to detect specific sound patterns, such as
 * those made by rice weevils. The Raspberry Pi can connect to a laptop via WiFi
 * or Bluetooth for further processing and analysis.
 */

#include <WiFi.h>
#include <BluetoothSerial.h>

#define ENVELOPE_PIN 0
#define AUDIO_PIN 5
#define GATE_PIN 6

BluetoothSerial SerialBT;

void setup() {
  Serial.begin(115200);
  SerialBT.begin("RaspberryPi"); // Bluetooth device name
  WiFi.begin("yourSSID", "yourPASSWORD");

  pinMode(ENVELOPE_PIN, INPUT);
  pinMode(AUDIO_PIN, INPUT);
  pinMode(GATE_PIN, INPUT);

  while (WiFi.status() != WL_CONNECTED) {
    delay(1000);
    Serial.println("Connecting to WiFi...");
  }
  Serial.println("Connected to WiFi");
}

void loop() {
  int envelopeValue = analogRead(ENVELOPE_PIN);
  int audioValue = analogRead(AUDIO_PIN);
  int gateValue = digitalRead(GATE_PIN);

  Serial.print("Envelope: ");
  Serial.print(envelopeValue);
  Serial.print(" Audio: ");
  Serial.print(audioValue);
  Serial.print(" Gate: ");
  Serial.println(gateValue);

  SerialBT.print("Envelope: ");
  SerialBT.print(envelopeValue);
  SerialBT.print(" Audio: ");
  SerialBT.print(audioValue);
  SerialBT.print(" Gate: ");
  SerialBT.println(gateValue);

  delay(1000); // Adjust delay as needed
}

Graphic LCD Display (GLCD 128x64) Code

/*
 * This Arduino Sketch is for a Graphic LCD Display (GLCD 128x64) connected to
 * a Raspberry Pi Zero W and a Sound Detector. The system analyzes audio signals
 * to detect frequencies in the range of 2kHz to 5kHz, indicating the presence of
 * rice weevils. The result is displayed on the GLCD.
 */

#include <Wire.h>
#include <Adafruit_GFX.h>
#include <Adafruit_PCD8544.h>

#define AUDIO_PIN 21
#define CS1_PIN 22
#define CS2_PIN 27
#define RST_PIN 17
#define ENABLE_PIN 10
#define DI_PIN 11
#define DB0_PIN 16
#define DB1_PIN 20
#define DB2_PIN 21
#define DB3_PIN 26
#define DB4_PIN 19
#define DB5_PIN 13
#define DB6_PIN 6
#define RW_PIN 9

Adafruit_PCD8544 display = Adafruit_PCD8544(CS1_PIN, CS2_PIN, RST_PIN, ENABLE_PIN, DI_PIN, RW_PIN);

void setup() {
  display.begin();
  display.setContrast(50);
  display.clearDisplay();
  display.display();
  pinMode(AUDIO_PIN, INPUT);
}

void loop() {
  int audioValue = analogRead(AUDIO_PIN);
  float frequency = getFrequency(audioValue);
  display.clearDisplay();
  display.setCursor(0, 0);
  if (frequency >= 2000 && frequency <= 5000) {
    display.print("Rice weevils detected");
  } else {
    display.print("No rice weevils detected");
  }
  display.display();
  delay(1000);
}

float getFrequency(int audioValue) {
  // Placeholder function to simulate frequency detection
  // Replace with actual frequency analysis code
  return 3000.0; // Example frequency
}

Sound Sensor Code

/*
 * This Arduino Sketch is for a Sound Sensor connected to a Raspberry Pi Zero W.
 * The system detects sound frequencies and categorizes them into different ranges.
 * The detected frequency range is printed to the Serial Monitor.
 */

#define SOUND_SENSOR_PIN A0

void setup() {
  Serial.begin(115200);
  pinMode(SOUND_SENSOR_PIN, INPUT);
}

void loop() {
  int sensorValue = analogRead(SOUND_SENSOR_PIN);
  float frequency = getFrequency(sensorValue);
  Serial.print("Detected Frequency: ");
  Serial.print(frequency);
  Serial.print(" Hz - ");
  if (frequency < 1000) {
    Serial.println("Low Frequency");
  } else if (frequency < 5000) {
    Serial.println("Medium Frequency");
  } else {
    Serial.println("High Frequency");
  }
  delay(1000);
}

float getFrequency(int sensorValue) {
  // Placeholder function to simulate frequency detection
  // Replace with actual frequency analysis code
  return 3000.0; // Example frequency
}

Note: The provided code snippets are for illustrative purposes and may require further development to function in a real-world scenario. The getFrequency function is a placeholder and should be replaced with actual frequency analysis algorithms.