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

Arduino Nano-Controlled Sound-Activated Relay System

View and Edit Project In Cirkit DesignerImage of Arduino Nano-Controlled Sound-Activated Relay System

Circuit Documentation

Summary

This circuit is designed to control a 4-channel relay module based on sound levels detected by a sound sensor. The Arduino Nano microcontroller reads the output from the sound sensor and activates the relays accordingly. The relays can be activated in different configurations depending on the detected sound level, which is categorized into NORMAL, LOW, MEDIUM, and HIGH levels. The sound sensor output is connected to the analog pin A0 of the Arduino Nano, while the relay control pins are connected to digital pins D2, D3, D4, and D5.

Component List

Relay 4 Channel 5v

Sound Sensor

Arduino Nano

Wiring Details

Relay 4 Channel 5v

Sound Sensor

Arduino Nano

Documented Code

/*
 * This Arduino Sketch controls a 4-channel relay module based on sound levels
 * detected by a sound sensor. The relays are activated sequentially based on
 * the sound level. The sound sensor output is read from analog pin A0, and the
 * relays are controlled via digital pins D2, D3, D4, and D5.
 *
 * Sound levels:
 * - Normal: No relays activated
 * - LOW: Relay 1 activated
 * - MEDIUM: Relay 1 and 2 activated
 * - HIGH: All relays activated
 */

const int soundSensorPin = A0; // Sound sensor output connected to A0
const int relayPins[] = {2, 3, 4, 5}; // Relay control pins
const int numRelays = 4; // Number of relays

void setup() {
  // Initialize serial communication
  Serial.begin(9600);
  // Initialize relay control pins as outputs
  for (int i = 0; i < numRelays; i++) {
    pinMode(relayPins[i], OUTPUT);
    digitalWrite(relayPins[i], HIGH); // Turn off relays initially
  }
}

void loop() {
  int soundLevel = analogRead(soundSensorPin); // Read sound level
  Serial.println(soundLevel); // Print sound level to serial monitor

  // Determine which relays to activate based on sound level
  if (soundLevel > 600) { // HIGH sound level
    for (int i = 0; i < numRelays; i++) {
      digitalWrite(relayPins[i], LOW); // Activate all relays
    }
  } else if (soundLevel > 400) { // MEDIUM sound level
    digitalWrite(relayPins[0], LOW); // Activate relay 1
    digitalWrite(relayPins[1], LOW); // Activate relay 2
    digitalWrite(relayPins[2], HIGH); // Deactivate relay 3
    digitalWrite(relayPins[3], HIGH); // Deactivate relay 4
  } else if (soundLevel > 200) { // LOW sound level
    digitalWrite(relayPins[0], LOW); // Activate relay 1
    digitalWrite(relayPins[1], HIGH); // Deactivate relay 2
    digitalWrite(relayPins[2], HIGH); // Deactivate relay 3
    digitalWrite(relayPins[3], HIGH); // Deactivate relay 4
  } else { // Normal sound level
    for (int i = 0; i < numRelays; i++) {
      digitalWrite(relayPins[i], HIGH); // Deactivate all relays
    }
  }

  delay(100); // Small delay to avoid rapid switching
}

This code is designed to be uploaded to the Arduino Nano microcontroller. It initializes the serial communication for debugging purposes and sets up the relay control pins. The main loop reads the sound level from the sound sensor and activates the relays based on predefined thresholds.