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

Arduino Nano IR Sensor Activated Buzzer and Servo Motor System

View and Edit Project In Cirkit DesignerImage of Arduino Nano IR Sensor Activated Buzzer and Servo Motor System

Circuit Documentation

Summary

This circuit is designed to control a buzzer and a servo motor using an Arduino Nano. The circuit also includes an IR sensor that detects objects. When the IR sensor detects an object, the buzzer is activated, and the servo motor moves to a specified position.

Component List

  1. Buzzer

    • Description: A simple piezoelectric buzzer used to produce sound.
    • Pins: PIN, GND
  2. Arduino Nano

    • Description: A small, complete, and breadboard-friendly microcontroller board based on the ATmega328P.
    • Pins: D1/TX, D0/RX, RESET, GND, D2, D3, D4, D5, D6, D7, D8, D9, D10, D11/MOSI, D12/MISO, VIN, 5V, A7, A6, A5, A4, A3, A2, A1, A0, AREF, 3V3, D13/SCK
  3. IR Sensor

    • Description: An infrared sensor used to detect objects.
    • Pins: out, gnd, vcc
  4. Micro Servo 9G

    • Description: A small servo motor used for precise control of angular position.
    • Pins: GND, +5V, PWM

Wiring Details

Buzzer

Arduino Nano

IR Sensor

Micro Servo 9G

Code Documentation

/*
 * This Arduino sketch controls a buzzer and a servo motor connected to an
 * Arduino Nano. The buzzer and servo motor will be activated whenever the
 * IR sensor detects an object. The IR sensor is connected to pin D8 of the
 * Arduino Nano, the buzzer is connected to pin D7, and the servo motor is
 * connected to pin D6.
 */

#include <Servo.h>

const int buzzerPin = 7; // Pin connected to the buzzer
const int irSensorPin = 8; // Pin connected to the IR sensor
const int servoPin = 6; // Pin connected to the servo motor

Servo myServo; // Create a servo object

void setup() {
  pinMode(buzzerPin, OUTPUT); // Set the buzzer pin as an output
  pinMode(irSensorPin, INPUT); // Set the IR sensor pin as an input
  myServo.attach(servoPin); // Attach the servo to the pin
  myServo.write(90); // Initialize the servo to 90 degrees
}

void loop() {
  int irSensorValue = digitalRead(irSensorPin); // Read the IR sensor value
  if (irSensorValue == HIGH) { // If the IR sensor detects an object
    digitalWrite(buzzerPin, HIGH); // Turn the buzzer on
    myServo.write(0); // Turn the servo to 0 degrees
  } else {
    digitalWrite(buzzerPin, LOW); // Turn the buzzer off
    myServo.write(90); // Turn the servo to 90 degrees
  }
}

This code initializes the pins for the buzzer, IR sensor, and servo motor. In the setup function, the buzzer pin is set as an output, the IR sensor pin is set as an input, and the servo motor is attached to its pin and initialized to 90 degrees. In the loop function, the IR sensor value is read, and if an object is detected, the buzzer is turned on and the servo motor is moved to 0 degrees. If no object is detected, the buzzer is turned off and the servo motor is moved back to 90 degrees.