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

Arduino UNO R4 WiFi-Controlled Object Detection System with I2C LCD Feedback and Relay-Servo Activation

View and Edit Project In Cirkit DesignerImage of Arduino UNO R4 WiFi-Controlled Object Detection System with I2C LCD Feedback and Relay-Servo Activation

Circuit Documentation

Summary

This circuit is designed to interface an Arduino UNO R4 WiFi with multiple peripherals including an I2C LCD 16x2 Screen, a 4-channel 5V relay module, an IR sensor, a micro servo 9G, a speaker, and a PAM8403 5W Bluetooth 5.0 Digital Stereo Power Audio Amplifier. The Arduino board serves as the central processing unit, controlling the relay module and servo based on input from the IR sensor. The LCD screen displays system status and frequency information, while the speaker generates sound at a specified frequency driven by the Arduino. The PAM8403 amplifier is connected to the speaker to amplify the audio signal.

Component List

Arduino UNO R4 WiFi

I2C LCD 16x2 Screen

Relay 4 Channel 5v

IR Sensor

Micro Servo 9G

Speaker

PAM8403 5W Bluetooth 5.0 Digital Stereo Power Audio Amplifier

Wiring Details

Arduino UNO R4 WiFi

I2C LCD 16x2 Screen

Relay 4 Channel 5v

IR Sensor

Micro Servo 9G

Speaker

PAM8403 5W Bluetooth 5.0 Digital Stereo Power Audio Amplifier

Documented Code

/*
 * This Arduino sketch interfaces with an I2C LCD, IR sensor, relay module,
 * micro servo, and a speaker. The IR sensor detects objects and triggers
 * relays and servo movements. The LCD displays system status and frequency
 * information. The speaker generates a soundwave at a specified frequency.
 */

#include <Wire.h>
#include <hd44780.h>           // main hd44780 header
#include <hd44780ioClass/hd44780_I2Cexp.h> // i2c expander i/o class header
#include <Servo.h>

// I2C LCD setup
hd44780_I2Cexp lcd; // declare lcd object: auto locate & auto config expander chip

// Pin definitions
#define IR_SENSOR_PIN 2
#define RELAY_PIN_1 6
#define RELAY_PIN_2 5
#define RELAY_PIN_3 4
#define RELAY_PIN_4 3
#define SERVO_PIN 10
#define SPEAKER_PIN 8

// Servo setup
Servo myServo;

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

  // Initialize LCD
  lcd.init();
  lcd.backlight();
  lcd.setCursor(0, 0);
  lcd.print("System Initializing");

  // Initialize pins
  pinMode(IR_SENSOR_PIN, INPUT);
  pinMode(RELAY_PIN_1, OUTPUT);
  pinMode(RELAY_PIN_2, OUTPUT);
  pinMode(RELAY_PIN_3, OUTPUT);
  pinMode(RELAY_PIN_4, OUTPUT);
  myServo.attach(SERVO_PIN);

  // Initial states
  digitalWrite(RELAY_PIN_1, LOW);
  digitalWrite(RELAY_PIN_2, LOW);
  digitalWrite(RELAY_PIN_3, LOW);
  digitalWrite(RELAY_PIN_4, LOW);
  myServo.write(0);

  lcd.setCursor(0, 1);
  lcd.print("Ready");
}

void loop() {
  // Read IR sensor
  int irValue = digitalRead(IR_SENSOR_PIN);

  if (irValue == HIGH) {
    // Object detected
    lcd.setCursor(0, 1);
    lcd.print("Object Detected ");
    digitalWrite(RELAY_PIN_1, HIGH);
    digitalWrite(RELAY_PIN_2, HIGH);
    digitalWrite(RELAY_PIN_3, HIGH);
    digitalWrite(RELAY_PIN_4, HIGH);
    myServo.write(90); // Move servo to 90 degrees
    delay(1000); // Wait for the servo to move
  } else {
    // No object detected
    lcd.setCursor(0, 1);
    lcd.print("No Object       ");
    digitalWrite(RELAY_PIN_1, LOW);
    digitalWrite(RELAY_PIN_2, LOW);
    digitalWrite(RELAY_PIN_3, LOW);
    digitalWrite(RELAY_PIN_4, LOW);
    myServo.write(0); // Move servo back to 0 degrees
    delay(1000); // Wait for the servo to move
  }

  // Generate soundwave frequency
  int frequency = 1000; // 1000 Hz frequency
  tone(SPEAKER_PIN, frequency); // Pin 8, 1000 Hz frequency
  delay(1000); // 1 second delay
  noTone(SPEAKER_PIN); // Stop tone
  delay(1000); // 1 second delay

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

This code is responsible for controlling the various components of the circuit. It initializes the LCD and sets up the pins for the IR sensor, relay module, servo, and speaker. The main loop reads the IR sensor and activates the relays and servo accordingly. It also generates a tone on the speaker and displays the frequency on the LCD.