smart-bell
atmega328 smart-bell
0
Project description

๐ Overview
์ด ํ๋ก์ ํธ๋ AVR ATmega328P ๋ง์ดํฌ๋ก์ปจํธ๋กค๋ฌ๋ฅผ ๊ธฐ๋ฐ์ผ๋ก ํ ์ค๋งํธ ์ด์ธ์ข (Smart Bell) ํ์จ์ด ์์ ๋ก, ๋ฒํผ ์ ๋ ฅ์ ์ธํฐ๋ฝํธ๋ก ์ฒ๋ฆฌํ๊ณ ํ์ด๋จธ ๊ธฐ๋ฐ ์ ์ด๋ฅผ ํตํด ์ถ๋ ฅ ์ฅ์น๋ฅผ ๊ตฌ๋ํ๋ ๊ตฌ์กฐ๋ฅผ ๊ฐ๊ณ ์์ต๋๋ค. UART๋ฅผ ์ด์ฉํ ๋๋ฒ๊ทธ ์ธํฐํ์ด์ค์ SPI ํต์ ๊ณ์ธต์ ๊ธฐ๋ณธ์ผ๋ก ํฌํจํ๊ณ ์์ผ๋ฉฐ, W5500 ์ด๋๋ท ์ปจํธ๋กค๋ฌ์ ๊ฐ์ ์ธ๋ถ ํต์ ์นฉ์ ์ฐ๋ํ ์ ์๋๋ก ํ์ฅ ๊ฐ๋ฅํ ๊ตฌ์กฐ๋ก ์ค๊ณ๋์์ต๋๋ค.
๐ Features
- ์ธ๋ถ ์ธํฐ๋ฝํธ(INT0)๋ฅผ ์ด์ฉํ ๋ฒํผ ์ ๋ ฅ ์ฒ๋ฆฌ
- ํ์ด๋จธ ์ธํฐ๋ฝํธ ๊ธฐ๋ฐ์ ๋ฒจ ์ถ๋ ฅ ์๊ฐ ์ ์ด
- ์ถ๋ ฅ ํ(PB0)์ ํตํ ๋ถ์ , ๋ฆด๋ ์ด, LED ๋ฑ ์ ์ด ๊ฐ๋ฅ
- UART ๊ธฐ๋ฐ ์๋ฆฌ์ผ ๋๋ฒ๊ทธ ๋ฐ ๋ฐ์ดํฐ ์์ฝ ๊ธฐ๋ฅ
- SPI ํต์ ์ธํฐํ์ด์ค ์ ๊ณต (W5500 ๋ฑ ์ธ๋ถ ์นฉ ์ฐ๋ ๊ฐ๋ฅ)
- Watchdog Timer(WDT) ์ค์ ์ ํตํ ์์คํ ์์ ์ฑ ํ๋ณด
- C++ ๊ธฐ๋ฐ ๋ชจ๋ํ ๊ตฌ์กฐ๋ก ๊ฐ๋ ์ฑ๊ณผ ํ์ฅ์ฑ ๊ฐํ
- Circular Buffer ๋ฑ ์ฌ์ฌ์ฉ ๊ฐ๋ฅํ ์ ํธ๋ฆฌํฐ ํฌํจ
- CMake + Conan ๊ธฐ๋ฐ์ ํ๋์ ์ธ ์๋ฒ ๋๋ ๋น๋ ํ๊ฒฝ
- ์ ๋ ํ ์คํธ ์ฝ๋ ํฌํจ์ผ๋ก ์ ์ง๋ณด์ ๋ฐ ๊ฒ์ฆ ์ฉ์ด
๐ System Architecture
- MCU (ATmega328P)
- ์ธํฐ๋ฝํธ, ํ์ด๋จธ, GPIO, ํต์ ์ ์ด์ ์ค์ฌ ์ญํ ์ํ
- Input Layer
- ์ธ๋ถ ๋ฒํผ ์ ๋ ฅ์ INT0 ์ธํฐ๋ฝํธ๋ก ๊ฐ์ง
- Control Logic
- ์ธํฐ๋ฝํธ ์ด๋ฒคํธ ๊ธฐ๋ฐ ์ํ ์ ์ด
- ํ์ด๋จธ ์นด์ดํธ๋ฅผ ์ด์ฉํ ๋ฒจ ๋์ ์๊ฐ ๊ด๋ฆฌ
- Output Layer
- GPIO(PB0)๋ฅผ ํตํ ๋ฒจ/๋ฆด๋ ์ด/LED ์ถ๋ ฅ ์ ์ด
- Communication Layer
- UART: ๋๋ฒ๊ทธ ๋ฉ์์ง ์ถ๋ ฅ ๋ฐ ์๋ฆฌ์ผ ํต์
- SPI: W5500 ์ด๋๋ท ์ปจํธ๋กค๋ฌ ๋ฑ ์ธ๋ถ ๋๋ฐ์ด์ค ์ฐ๋์ฉ ์ธํฐํ์ด์ค
- System Services
- Watchdog Timer๋ฅผ ํตํ ์์คํ ๋ฆฌ์ ๋ฐ ์ค๋ฅ ๋ณต๊ตฌ
๐ Role and Application of the WIZnet's Chip
Source Link : https://github.com/Zombieanfuehrer/smart-bell/blob/W5500-support-lib/app/smart_bell_main.cpp
์ฌ์ฉ๋ WIZnet ์นฉ ๋ชจ๋ธ๋ช : W5500
๋คํธ์ํฌ์์์ ์ญํ :
- SPI ์ธํฐํ์ด์ค๋ฅผ ํตํด MCU์ ์ฐ๊ฒฐ๋์ด Ethernet ํต์ ์ ๋ฌผ๋ฆฌ ๊ณ์ธต ๋ฐ ์ ์ก ๊ณ์ธต(TCP/UDP)์ ๋ ๋ฆฝ์ ์ผ๋ก ์ฒ๋ฆฌ
- MCU๋ ์์ผ ์ ์ด ๋ฐ ๋ฐ์ดํฐ ์ก์์ ๋ช ๋ น๋ง ์ํํจ์ผ๋ก์จ ํ์จ์ด ๋ณต์ก๋์ CPU ๋ถํ๋ฅผ ์ต์ํ
- ์ด์ธ์ข ์ด๋ฒคํธ ๋ฐ์ ์, ๋คํธ์ํฌ๋ฅผ ํตํด ์ด๋ฒคํธ ์๋ฆผ, ์ํ ์ ์ก, ์๊ฒฉ ๋ชจ๋ํฐ๋ง ๊ธฐ๋ฅ์ ๊ตฌํํ ์ ์๋ ํต์ ์๋ํฌ์ธํธ ์ญํ
- ์์ ์ ์ธ ํ๋์จ์ด TCP/IP ์ฒ๋ฆฌ๋ก ์๋ฒ ๋๋ ํ๊ฒฝ์์๋ ์์ธก ๊ฐ๋ฅํ ๋คํธ์ํฌ ๋์๊ณผ ๋์ ์ ๋ขฐ์ฑ ํ๋ณด
๐ Market & Application Value
(by ChatGPT)
์ ์ฉ ๊ฐ๋ฅํ ์ฐ์ ๋ฐ ์์ฅ
- ์ฃผ๊ฑฐ/์ํ ์๊ฐ: ์ถ์ ์๋ฆผ(๋ฒจ/์ธํฐํฐ ๋ณด์กฐ), ๋ฐฉ๋ฌธ ์ด๋ฒคํธ ๋ก๊ทธ
- ๋ฌด์ธ ๋งค์ฅ/์ฐฝ๊ณ /์ฌ๋ฌด์ค: ์ถ์ ์ด๋ฒคํธ ๊ธฐ๋ก + ์๊ฒฉ ์๋ฆผ
- ์ฐ์ ํ์ฅ: ํธ์ถ๋ฒจ(Andon), ์์ /๋น์ ํธ์ถ, ์ค๋น ์ด๋ฒคํธ ํธ๋ฆฌ๊ฑฐ ์ ์ก
- โ์ค๋งํธ ๋ฒจโ์ ๊ธฐ๋ฅ์ ๋ถ์ด๊ธฐ ์์ํ๋ฉด ๋ก๊ทธ(์ด๋ ฅ), ์ฌ์ฉ์ ๊ด๋ฆฌ, ์๋ฆผ ์ฑ๋ ๋ค์คํ(์ฑ/๋ฉ์ ์ ), ์ฅ์น ์๊ฒฉ ์ค์ ์ผ๋ก ์๋น์คํ๊ฐ ๊ฐ๋ฅ
๐ Summary
๋ณธ ํ๋ก์ ํธ๋ ATmega328P ๊ธฐ๋ฐ์ ์ค๋งํธ ์ด์ธ์ข ๊ตฌํ์ ํตํด ์ธํฐ๋ฝํธ์ ํ์ด๋จธ๋ฅผ ํ์ฉํ ์์ ์ ์ธ ์ด๋ฒคํธ ์ ์ด ๊ตฌ์กฐ๋ฅผ ์ ์ํฉ๋๋ค. UART์ SPI ํต์ ๊ณ์ธต์ ํฌํจํ ํ์ฅ ๊ฐ๋ฅํ ํ์จ์ด ๊ตฌ์กฐ๋ก ์ค๊ณ๋์ด, ๋จ์ํ ๋ก์ปฌ ์ฅ์น๋ฅผ ๋คํธ์ํฌ ๊ธฐ๋ฐ IoT ๋๋ฐ์ด์ค๋ก ํ์ฅํ ์ ์์ต๋๋ค. WIZnet์ W5500 ์ด๋๋ท ์ปจํธ๋กค๋ฌ๋ ํ๋์จ์ด TCP/IP ์ฒ๋ฆฌ๋ฅผ ํตํด MCU์ ๋ถ๋ด์ ์ค์ด๊ณ ์์ ์ ์ธ ๋คํธ์ํฌ ํต์ ์ ๊ฐ๋ฅํ๊ฒ ํฉ๋๋ค. ์ด๋ฅผ ํตํด ์ด์ธ์ข ์ด๋ฒคํธ๋ฅผ ์๊ฒฉ์ผ๋ก ์ ์กํ๊ณ ๋ชจ๋ํฐ๋งํ ์ ์๋ IoT ์์ฉ์ด ๊ฐ๋ฅํฉ๋๋ค.
๐ FAQ
Q1. ์ Smart Bell ํ๋ก์ ํธ์์ WIZnet W5500์ ์ฌ์ฉํ๋์?
A: W5500์ ํ๋์จ์ด TCP/IP ์คํ์ ๋ด์ฅํ ์ด๋๋ท ์ปจํธ๋กค๋ฌ๋ก, MCU๊ฐ ๋คํธ์ํฌ ํ๋กํ ์ฝ์ ์ง์ ์ฒ๋ฆฌํ์ง ์์๋ ๋ฉ๋๋ค. Smart Bell๊ณผ ๊ฐ์ ์๋ฆผ ์์คํ ์ ๋ฒํผ ์ ๋ ฅ ํ ์๋ฒ ์ ์ก๊น์ง์ ์ง์ฐ๊ณผ ์์ ์ฑ์ด ์ค์ํ๋ฉฐ, W5500์ Wi-Fi ๋๋น ํจํท ์์ค๊ณผ ์งํฐ(jitter)๊ฐ ๊ฑฐ์ ์๋ ์ ์ ํต์ ์ ์ ๊ณตํฉ๋๋ค. ์ด๋ก ์ธํด CPU ๋ถํ ๊ฐ์์ ์์ธก ๊ฐ๋ฅํ ๋์์ ๋์์ ๋ฌ์ฑํ ์ ์์ต๋๋ค.
Q2. W5500์ ์ด Smart Bell ํ๋ก์ ํธ์์ ์ด๋ค ์ญํ ์ ํ๋์?
A: ์ด ํ๋ก์ ํธ์์ W5500์ ๋คํธ์ํฌ ์ ์ก ๊ณ์ธต(Network Transport Layer) ์ญํ ์ ๋ด๋นํฉ๋๋ค. ๋ฒจ ์ ๋ ฅ ์ด๋ฒคํธ๊ฐ ๋ฐ์ํ๋ฉด MCU๋ W5500์ ํตํด ์๋ฒ ๋๋ ๋ก์ปฌ ๋คํธ์ํฌ๋ก ๋ฐ์ดํฐ๋ฅผ ์ ์กํฉ๋๋ค. TCP/UDP ์์ผ ๊ด๋ฆฌ, ์ฌ์ ์ก, ์ฐ๊ฒฐ ์ ์ง ๋ฑ์ ์์ ์ W5500 ํ๋์จ์ด๊ฐ ์ฒ๋ฆฌํ๋ฏ๋ก, MCU๋ ์ ๋ ฅ ์ฒ๋ฆฌ์ ์ ํ๋ฆฌ์ผ์ด์ ๋ก์ง์ ์ง์คํ ์ ์์ต๋๋ค.
Q3. MCU์ W5500์ ์ด๋ป๊ฒ ์ฐ๊ฒฐ๋๋์?
A: W5500์ SPI ์ธํฐํ์ด์ค๋ก MCU์ ์ฐ๊ฒฐ๋ฉ๋๋ค. ๊ธฐ๋ณธ์ ์ผ๋ก MOSI, MISO, SCK, CS์ 4๊ฐ ์ ํธ์ ๋ง ํ์ํ๋ฉฐ, ์ธํฐ๋ฝํธ(INT) ํ์ ์ฌ์ฉํ๋ฉด ์ด๋ฒคํธ ๊ธฐ๋ฐ ํต์ ๋ ๊ฐ๋ฅํฉ๋๋ค. ์ด ๊ตฌ์กฐ๋ ํ ์๊ฐ ์ ํ๋ MCU์์๋ Ethernet ๊ธฐ๋ฅ์ ์ฝ๊ฒ ์ถ๊ฐํ ์ ์์ด, Smart Bell ๊ฐ์ ์ํ ์๋ฒ ๋๋ ์ฅ์น์ ์ ํฉํฉ๋๋ค.
Q4. Wi-Fi ๋์ Ethernet(W5500)์ ์ฌ์ฉํ ์ด์ ๋ ๋ฌด์์ธ๊ฐ์?
A: Smart Bell์ โํญ์ ๋์ํด์ผ ํ๋โ ์ฅ์น์ด๊ธฐ ๋๋ฌธ์ ์ฐ๊ฒฐ ์์ ์ฑ์ด ํต์ฌ์ ๋๋ค. Wi-Fi๋ ์ ํ ๊ฐ์ญ, AP ์ฌ์ฐ๊ฒฐ, ์ ์ ๊ด๋ฆฌ ์ด์๋ก ์ธํด ์ง์ฐ์ด๋ ์ฐ๊ฒฐ ๋๊น์ด ๋ฐ์ํ ์ ์์ต๋๋ค. ๋ฐ๋ฉด W5500 ๊ธฐ๋ฐ Ethernet์ ์ ์ ์ธ๊ฐ ํ ์ฆ์ ๋งํฌ ์ , 1ms ๋จ์์ ์์ ์ ์ธ ์๋ต, ๋คํธ์ํฌ ํ๊ฒฝ ๋ณํ์ ๋ ๋ฏผ๊ฐํ ํน์ฑ์ ์ ๊ณตํ์ฌ ์์ ๋๊ธฐํ IoT ์ฅ์น์ ์ ๋ฆฌํฉ๋๋ค.
Q5. ์ด ํ๋ก์ ํธ๋ฅผ W55RP20์ผ๋ก๋ ๊ตฌํํ ์ ์๋์?
A: ๋ค, ๊ฐ๋ฅํฉ๋๋ค. W55RP20์ RP2040 MCU์ W5500์ ๋จ์ผ ์นฉ์ผ๋ก ํตํฉํ ์ ํ์ผ๋ก, Smart Bell๊ณผ ๊ฐ์ ํ๋ก์ ํธ์ ํนํ ์ ํฉํฉ๋๋ค. ๋ณ๋์ MCU + Ethernet ์นฉ ๊ตฌ์ฑ ๋๋น BOM ๋น์ฉ ๊ฐ์, PCB ๋ฉด์ ์ถ์, SPI ๋ฐฐ์ ์ ๊ฑฐ๋ก ์ ๋ขฐ์ฑ ํฅ์์ด๋ผ๋ ์ฅ์ ์ด ์์ต๋๋ค. ๊ธฐ๋ฅ์ ์ผ๋ก๋ ๊ธฐ์กด W5500 ๊ธฐ๋ฐ ๊ตฌ์กฐ์ ๋์ผํ๊ฒ ๋์ํฉ๋๋ค.
๐ Overview
This project is a smart doorbell (Smart Bell) firmware example based on the AVR ATmega328P microcontroller, featuring a structure in which button inputs are handled via interrupts and output devices are driven through timer-based control. It includes a UART-based debug interface and an SPI communication layer by default, and is designed with an expandable architecture that allows integration with external communication chips such as the W5500 Ethernet controller.
๐ Features
- Button input handling using an external interrupt (INT0)
- Bell output duration control based on timer interrupts
- Control of buzzer, relay, LED, etc. via an output pin (PB0)
- UART-based serial debugging and data echo functionality
- SPI communication interface provided (enabling integration with external chips such as the W5500)
- System stability ensured through Watchdog Timer (WDT) configuration
- Improved readability and extensibility through a C++-based modular structure
- Inclusion of reusable utilities such as a circular buffer
- Modern embedded build environment based on CMake and Conan
- Included unit test code for easier maintenance and verification
๐ System Architecture
- MCU (ATmega328P)
- Acts as the central controller for interrupts, timers, GPIO, and communication control
- Input Layer
- Detects external button input via the INT0 interrupt
- Control Logic
- State control based on interrupt events
- Management of bell operation time using timer counts
- Output Layer
- Controls bell/relay/LED output via GPIO (PB0)
- Communication Layer
- UART: Debug message output and serial communication
- SPI: Interface for connecting external devices such as the W5500 Ethernet controller
- System Services
- System reset and error recovery through the Watchdog Timer
๐ Role and Application of the WIZnet's Chip
Source Link : https://github.com/Zombieanfuehrer/smart-bell/blob/W5500-support-lib/app/smart_bell_main.cpp
WIZnet chip model used: W5500
Role in the network:
- Connected to the MCU via an SPI interface and independently handles the physical layer and transport layer (TCP/UDP) of Ethernet communication
- By having the MCU perform only socket control and data transmission/reception commands, firmware complexity and CPU load are minimized
- Serves as a communication endpoint that enables event notifications, status transmission, and remote monitoring over the network when a doorbell event occurs
- Ensures predictable network behavior and high reliability in embedded environments through stable hardware-based TCP/IP processing
๐ Market & Application Value
(by ChatGPT)
Applicable industries and markets
- Residential / small retail spaces: Entry notifications (bell/intercom support), visitor event logging
- Unmanned stores / warehouses / offices: Access event recording and remote notifications
- Industrial sites: Call buttons (Andon), safety/emergency calls, transmission of equipment event triggers
- As a โsmart bellโ evolves by adding features, it can be developed into a service through event logging (history), user management, multi-channel notifications (apps/messengers), and remote device configuration
๐ Summary
This project presents a stable event control architecture using interrupts and timers through the implementation of a smart doorbell based on the ATmega328P. Designed with an extensible firmware structure that includes UART and SPI communication layers, it enables a simple local device to be expanded into a network-based IoT device. WIZnetโs W5500 Ethernet controller reduces the processing burden on the MCU through hardware-based TCP/IP handling and enables reliable network communication. As a result, IoT applications that remotely transmit and monitor doorbell events can be realized.
๐ FAQ
Q1. Why is the WIZnet W5500 used in the Smart Bell project?
A: The W5500 is an Ethernet controller with an embedded hardware TCP/IP stack, allowing the MCU to operate without directly handling network protocols. In notification systems like Smart Bell, low latency and high reliability from button input to server transmission are critical. Compared to Wi-Fi, the W5500 provides wired communication with virtually no packet loss or jitter, enabling both reduced CPU load and predictable system behavior.
Q2. What role does the W5500 play in this Smart Bell project?
A: In this project, the W5500 serves as the network transport layer. When a bell input event occurs, the MCU sends data to a server or local network via the W5500. Tasks such as TCP/UDP socket management, retransmission, and connection maintenance are handled by the W5500 hardware, allowing the MCU to focus on input handling and application logic.
Q3. How are the MCU and W5500 connected?
A: The W5500 is connected to the MCU via an SPI interface. Basically, only four signal linesโMOSI, MISO, SCK, and CSโare required, and event-driven communication is also possible using the interrupt (INT) pin. This structure makes it easy to add Ethernet functionality even to MCUs with limited pin counts, making it well suited for compact embedded devices like Smart Bell.
Q4. Why was Ethernet (W5500) chosen instead of Wi-Fi?
A: Smart Bell is an โalways-onโ device, so connection stability is essential. Wi-Fi can suffer from delays or disconnections due to radio interference, AP reconnections, and power management issues. In contrast, W5500-based Ethernet offers immediate link-up after power-on, stable responses on the order of 1 ms, and lower sensitivity to network environment changes, making it more suitable for always-ready IoT devices.
Q5. Can this project also be implemented with the W55RP20?
A: Yes, it can. The W55RP20 integrates an RP2040 MCU and a W5500 into a single chip, making it particularly suitable for projects like Smart Bell. Compared to a separate MCU + Ethernet chip configuration, it offers advantages such as reduced BOM cost, smaller PCB area, and improved reliability by eliminating SPI wiring. Functionally, it operates in the same way as an existing W5500-based architecture.
