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

Arduino UNO Controlled Soundwave Generator with IR Sensor Activation and Relay Switching

View and Edit Project In Cirkit DesignerImage of Arduino UNO Controlled Soundwave Generator with IR Sensor Activation and Relay Switching

Circuit Documentation

Summary

The circuit is designed to generate sound waves controlled by a potentiometer, display frequency information on an LCD, and respond to IR sensor inputs to control a servo and relay channels. The core of the circuit is an Arduino UNO microcontroller, which interfaces with an XR2206 function generator, two IR sensors, a 4-channel relay, a servo motor, an LCD display with I2C interface, a PAM8403 audio amplifier, and a speaker. The circuit also includes a resistor and an electrolytic capacitor for signal conditioning or power stabilization.

Component List

Relay 4 Channel 5v

IR Sensor

PAM8403

Speaker

Arduino UNO

LCD I2C Display

Micro Servo 9G

XR2206 HLF 224A8

Resistor

Electrolytic Capacitor

Wiring Details

Relay 4 Channel 5v

IR Sensor

PAM8403

Speaker

Arduino UNO

LCD I2C Display

Micro Servo 9G

XR2206 HLF 224A8

Resistor

Electrolytic Capacitor

Documented Code

#include <Wire.h>
#include <LiquidCrystal_I2C.h>
#include <Servo.h>

// Relay pin definitions
const int relayPin1 = 6;
const int relayPin2 = 5;
const int relayPin3 = 4;
const int relayPin4 = 3;

// Potentiometer pin definition
const int potPin = A0;

// IR sensor pin definitions
const int irSensor1 = 2;
const int irSensor2 = 2;

// Servo pin definition
const int servoPin = 10;
Servo myServo;

// LCD I2C address and dimensions
LiquidCrystal_I2C lcd(0x27, 16, 2);

// Variable to store the frequency
int frequency = 100;

void setup() {
  // Initialize serial communication
  Serial.begin(9600);

  // Initialize relay pins as outputs
  pinMode(relayPin1, OUTPUT);
  pinMode(relayPin2, OUTPUT);
  pinMode(relayPin3, OUTPUT);
  pinMode(relayPin4, OUTPUT);

  // Initialize potentiometer pin as input
  pinMode(potPin, INPUT);

  // Initialize IR sensor pins as input
  pinMode(irSensor1, INPUT);
  pinMode(irSensor2, INPUT);

  // Initialize servo
  myServo.attach(servoPin);

  // Initialize LCD
  lcd.begin(16, 2);
  lcd.backlight();
  lcd.setCursor(0, 0);
  lcd.print("Soundwave Gen");
}

void loop() {
  // Read the analog value from the potentiometer
  int potValue = analogRead(potPin);

  // Map the potentiometer value to a frequency range (e.g., 20Hz to 20kHz)
  frequency = map(potValue, 0, 1023, 20, 20000);

  // Print the new frequency to the serial monitor
  Serial.print("Frequency: ");
  Serial.print(frequency);
  Serial.println(" Hz");

  // Display the frequency value on the LCD
  lcd.setCursor(0, 1);
  lcd.print("Freq: ");
  lcd.print(frequency);
  lcd.print(" Hz");

  // Control relay channels based on potentiometer value
  if (potValue > 512) {
    digitalWrite(relayPin1, HIGH);
    digitalWrite(relayPin2, LOW);
    digitalWrite(relayPin3, HIGH);
    digitalWrite(relayPin4, LOW);
  } else {
    digitalWrite(relayPin1, LOW);
    digitalWrite(relayPin2, HIGH);
    digitalWrite(relayPin3, LOW);
    digitalWrite(relayPin4, HIGH);
  }

  // Read IR sensor values
  int irValue1 = digitalRead(irSensor1);
  int irValue2 = digitalRead(irSensor2);

  // Control servo based on IR sensor values
  if (irValue1 == LOW || irValue2 == LOW) {
    myServo.write(90); // Move servo to 90 degrees
  } else {
    myServo.write(0); // Move servo to 0 degrees
  }

  // Add a small delay to avoid flickering
  delay(100);
}

This code is responsible for reading the analog value from a potentiometer connected to pin A0, mapping this value to a frequency range, and displaying it on an LCD. It also controls a set of relays and a servo motor based on the potentiometer's value and the output of two IR sensors. The relays and servo are connected to digital pins D3 to D6 and D10, respectively. The LCD uses the I2C protocol, connected to analog pins A4 and A5 for SDA and SCL lines.