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

Arduino 101-Based Smart Alarm Clock with Ultrasonic Sensor and IR Remote Control

View and Edit Project In Cirkit DesignerImage of Arduino 101-Based Smart Alarm Clock with Ultrasonic Sensor and IR Remote Control

Circuit Documentation

Summary

This circuit is an alarm system that utilizes an Arduino 101 microcontroller to control various components including an LCD display, an ultrasonic sensor, a piezo buzzer, an IR receiver, and an RTC module. The system displays the current time and alarm time on the LCD, and the alarm can be set and controlled using an IR remote. The alarm is activated at a specified time and can be deactivated by moving an object within a certain distance from the ultrasonic sensor.

Component List

  1. Arduino 101

    • Description: Microcontroller board based on the Intel Curie module.
    • Pins: A5/SCL, A4/SDA, AREF, GND, D13/SCK, D12/MISO, D11 PWM/MOSI, D10 PWM/SS, D9 PWM, D8, D7, D6 PWM, D5 PWM, D4, D3 PWM, D2, D1/TX, D0/RX, AIN, ioref, RESET, 3V3, 5V, VIN, A0, A1, A2, A3, ICSP MISO, ICSP SCK, ICSP MOSI
  2. Piezo Buzzer

    • Description: A small speaker that generates sound.
    • Pins: pin 1, pin 2
  3. HC-SR04 Ultrasonic Sensor

    • Description: Sensor that measures distance by using ultrasonic waves.
    • Pins: VCC, TRIG, ECHO, GND
  4. MKE-M07 LCD1602 I2C

    • Description: 16x2 character LCD display with I2C interface.
    • Pins: GND, 5V, SDA, SCL
  5. 4xAA_JST

    • Description: Battery pack with JST connector.
    • Pins: POS, NEG
  6. RTC DS3231

    • Description: Real-time clock module.
    • Pins: 32K, SQW, SCL, SDA, VCC, GND
  7. IR Receiver

    • Description: Infrared receiver for remote control signals.
    • Pins: DATA, VCC, GND

Wiring Details

Arduino 101

Piezo Buzzer

HC-SR04 Ultrasonic Sensor

MKE-M07 LCD1602 I2C

4xAA_JST

RTC DS3231

IR Receiver

Documented Code

#include <Wire.h>
#include <LiquidCrystal_I2C.h>
#include <RTClib.h>
#include <IRremote.h>
#include <NewPing.h>

// Pin definitions
#define IR_RECEIVE_PIN 2
#define TRIGGER_PIN 3
#define ECHO_PIN 4
#define BUZZER_PIN 5

// Constants
#define MAX_DISTANCE 300 // Maximum distance to measure (in cm)
#define ALARM_DISTANCE 300 // Minimum distance to deactivate alarm (in cm)
#define POWER_BUTTON_CODE 0xFFA25D
#define VOLUME_UP_BUTTON_CODE 0xFF629D
#define VOLUME_DOWN_BUTTON_CODE 0xFFE21D

// Initialize LCD
LiquidCrystal_I2C lcd(0x27, 16, 2);

// Initialize RTC
RTC_DS1307 rtc;

// Initialize IR Receiver
IRrecv irrecv(IR_RECEIVE_PIN);
decode_results results;

// Initialize Ultrasonic Sensor
NewPing sonar(TRIGGER_PIN, ECHO_PIN, MAX_DISTANCE);

// Variables
int alarmHour = 7; // Default alarm hour
int alarmMinute = 0; // Default alarm minute
bool alarmSet = false;
bool alarmActive = false;

void setup() {
  Serial.begin(9600);
  lcd.begin();
  lcd.backlight();
  irrecv.enableIRIn(); // Start the IR receiver
  pinMode(BUZZER_PIN, OUTPUT);
  rtc.begin();
  if (!rtc.isrunning()) {
    rtc.adjust(DateTime(F(__DATE__), F(__TIME__)));
  }
}

void loop() {
  // Get current time
  DateTime now = rtc.now();

  // Display current time on LCD
  lcd.setCursor(0, 0);
  lcd.print("Time: ");
  if (now.hour() < 10) {
    lcd.print("0");
  }
  lcd.print(now.hour());
  lcd.print(":");
  if (now.minute() < 10) {
    lcd.print("0");
  }
  lcd.print(now.minute());

  // Display alarm time on LCD
  lcd.setCursor(0, 1);
  lcd.print("Alarm: ");
  if (alarmHour < 10) {
    lcd.print("0");
  }
  lcd.print(alarmHour);
  lcd.print(":");
  if (alarmMinute < 10) {
    lcd.print("0");
  }
  lcd.print(alarmMinute);

  // Check if alarm should be active
  if (now.hour() == alarmHour && now.minute() == alarmMinute && !alarmActive) {
    alarmActive = true;
    tone(BUZZER_PIN, 1000); // Sound the buzzer
  }

  // Check IR remote for alarm setting
  if (irrecv.decode(&results)) {
    handleIRInput(results.value);
    irrecv.resume(); // Receive the next value
  }

  // Check distance to deactivate alarm
  if (alarmActive) {
    int distance = sonar.ping_cm();
    if (distance > ALARM_DISTANCE) {
      noTone(BUZZER_PIN); // Stop the buzzer
      alarmActive = false;
    }
  }

  delay(1000); // Update every second
}

void handleIRInput(unsigned long value) {
  switch (value) {
    case POWER_BUTTON_CODE: // Power button
      alarmSet = !alarmSet;
      break;
    case VOLUME_UP_BUTTON_CODE: // Volume up button
      alarmHour = (alarmHour + 1) % 24;
      break;
    case VOLUME_DOWN_BUTTON_CODE: // Volume down button
      alarmMinute = (alarmMinute + 1) % 60;
      break;
    // Add more cases for other buttons as needed
  }
}

This code initializes and controls the various components connected to the Arduino 101. It sets up the LCD, RTC, IR receiver, and ultrasonic sensor, and includes logic for setting and activating the alarm. The alarm can be controlled using an IR remote, and it will deactivate when an object is detected within a specified distance by the ultrasonic sensor.