This shows you the differences between two versions of the page.
|
pm:prj2026:jan.vaduva:33160 [2026/05/09 22:40] tudor_mihai.petcu |
— (current) | ||
|---|---|---|---|
| Line 1: | Line 1: | ||
| - | ====== Smart Puzzle Game ====== | ||
| - | |||
| - | ===== Introduction ===== | ||
| - | |||
| - | The purpose of this project is to build an interactive puzzle box based on the ATmega328P Xplained Mini microcontroller. When the user presses the start button, the box opens using a servo motor and starts a timed puzzle challenge. The system displays the current level and the remaining time on an LCD, and it uses LEDs and a buzzer to signal success or failure. | ||
| - | |||
| - | The main idea behind the project is to combine a simple game-like experience with embedded control, timing, sound feedback, and multiple difficulty levels. The project started from the idea of a simple access system, but it later evolved into a puzzle-based interactive system, which is more interesting from both the hardware and software point of view. | ||
| - | |||
| - | We chose this idea because it is interactive, easy to demonstrate, and allows us to combine several topics studied during the laboratory sessions, especially interrupts, timers/PWM, and UART for debugging. We think the project is useful for us because it gives us practical experience with both hardware and software integration. | ||
| - | |||
| - | ===== General Description ===== | ||
| - | |||
| - | The project is built around the ATmega328P Xplained Mini, which controls all the hardware components. The system has the following main modules: | ||
| - | |||
| - | * **Main control unit** – the ATmega328P Xplained Mini microcontroller coordinates the entire system. | ||
| - | * **Input module** – one button starts the game, one button confirms the end of the round, and one reset/next button can be used to restart or move to the next level. | ||
| - | * **Display module** – a 16x2 LCD shows the current level, remaining time, and result messages. | ||
| - | * **Actuation module** – a servo motor opens the box when the game starts. | ||
| - | * **Feedback module** – LEDs and a buzzer indicate game status, success, timeout, or errors. | ||
| - | * **Game logic module** – software manages the countdown, level difficulty, state transitions, and result validation. | ||
| - | |||
| - | A simple logical flow of the system is the following: | ||
| - | |||
| - | * the system waits in an idle state | ||
| - | * the user presses the **Start** button | ||
| - | * the servo opens the box | ||
| - | * the LCD shows the current level and the countdown timer | ||
| - | * the user completes the challenge | ||
| - | * the user presses the **Finish** button | ||
| - | * if the challenge is completed before timeout, the system shows success and moves to the next level | ||
| - | * if the timer reaches zero first, the system signals failure | ||
| - | |||
| - | The project can be described using the following software states: | ||
| - | |||
| - | * **Idle** | ||
| - | * **Opening Box** | ||
| - | * **Game Running** | ||
| - | * **Success** | ||
| - | * **Fail / Timeout** | ||
| - | * **Next Level / Reset** | ||
| - | |||
| - | ==== Block Diagram ==== | ||
| - | |||
| - | The following block diagram presents the main hardware modules of the system and the way they interact. The ATmega328P Xplained Mini is the central control unit. It receives input from the buttons, controls the LCD, drives the servo motor, activates the buzzer and LEDs, and can optionally communicate with a PC through UART for debugging. | ||
| - | |||
| - | <html> | ||
| - | <!DOCTYPE html> | ||
| - | <html> | ||
| - | <head> | ||
| - | <title>Untitled Diagram.drawio.html</title> | ||
| - | <meta charset="utf-8"/> | ||
| - | </head> | ||
| - | <body> | ||
| - | <div class="mxgraph" style="max-width:100%;border:1px solid transparent;" data-mxgraph="{"highlight":"#0000ff","nav":true,"resize":true,"xml":"<mxfile host=\"app.diagrams.net\"><diagram name=\"Page-1\" id=\"ISBjk71iAZlT5E4kvOMc\"><mxGraphModel dx=\"814\" dy=\"616\" grid=\"1\" gridSize=\"10\" guides=\"1\" tooltips=\"1\" connect=\"1\" arrows=\"1\" fold=\"1\" page=\"1\" pageScale=\"1\" pageWidth=\"850\" pageHeight=\"1100\" math=\"0\" shadow=\"0\"><root><mxCell id=\"0\"/><mxCell id=\"1\" parent=\"0\"/><mxCell id=\"eeTA-m969tc2DToLa9s2-1\" parent=\"1\" style=\"rounded=1;whiteSpace=wrap;html=1;fillColor=#fff2cc;strokeColor=#d6b656;\" value=\"\" vertex=\"1\"><mxGeometry height=\"60\" width=\"150\" x=\"350\" y=\"140\" as=\"geometry\"/></mxCell><mxCell id=\"eeTA-m969tc2DToLa9s2-2\" parent=\"1\" style=\"text;html=1;whiteSpace=wrap;strokeColor=none;fillColor=none;align=center;verticalAlign=middle;rounded=0;fontSize=16;fontColor=#FFB366;\" value=\"Power Supply\" vertex=\"1\"><mxGeometry height=\"30\" width=\"110\" x=\"370\" y=\"155\" as=\"geometry\"/></mxCell><mxCell id=\"eeTA-m969tc2DToLa9s2-4\" edge=\"1\" parent=\"1\" style=\"endArrow=classic;html=1;rounded=0;\" value=\"\"><mxGeometry height=\"50\" relative=\"1\" width=\"50\" as=\"geometry\"><mxPoint x=\"424\" y=\"200\" as=\"sourcePoint\"/><mxPoint x=\"424\" y=\"270\" as=\"targetPoint\"/></mxGeometry></mxCell><mxCell id=\"eeTA-m969tc2DToLa9s2-5\" parent=\"1\" style=\"rounded=1;whiteSpace=wrap;html=1;fillColor=#dae8fc;strokeColor=#6c8ebf;\" value=\"\" vertex=\"1\"><mxGeometry height=\"60\" width=\"190\" x=\"330\" y=\"270\" as=\"geometry\"/></mxCell><mxCell id=\"eeTA-m969tc2DToLa9s2-6\" parent=\"1\" style=\"text;html=1;whiteSpace=wrap;strokeColor=none;fillColor=none;align=center;verticalAlign=middle;rounded=0;fontSize=20;fontColor=#7EA6E0;\" value=\"ATmega328P Xplained Mini\" vertex=\"1\"><mxGeometry height=\"30\" width=\"60\" x=\"395\" y=\"285\" as=\"geometry\"/></mxCell><mxCell id=\"eeTA-m969tc2DToLa9s2-8\" edge=\"1\" parent=\"1\" style=\"endArrow=classic;html=1;rounded=0;\" value=\"\"><mxGeometry height=\"50\" relative=\"1\" width=\"50\" as=\"geometry\"><Array as=\"points\"><mxPoint x=\"220\" y=\"300\"/></Array><mxPoint x=\"220\" y=\"200\" as=\"sourcePoint\"/><mxPoint x=\"330\" y=\"300\" as=\"targetPoint\"/></mxGeometry></mxCell><mxCell id=\"eeTA-m969tc2DToLa9s2-10\" parent=\"1\" style=\"rounded=1;whiteSpace=wrap;html=1;fillColor=#d5e8d4;strokeColor=#82b366;\" value=\"\" vertex=\"1\"><mxGeometry height=\"60\" width=\"120\" x=\"160\" y=\"140\" as=\"geometry\"/></mxCell><mxCell id=\"eeTA-m969tc2DToLa9s2-11\" parent=\"1\" style=\"text;html=1;whiteSpace=wrap;strokeColor=none;fillColor=none;align=center;verticalAlign=middle;rounded=0;fontSize=20;fontColor=#97D077;\" value=\"Buttons\" vertex=\"1\"><mxGeometry height=\"30\" width=\"60\" x=\"190\" y=\"155\" as=\"geometry\"/></mxCell><mxCell id=\"eeTA-m969tc2DToLa9s2-13\" edge=\"1\" parent=\"1\" style=\"endArrow=classic;html=1;rounded=0;\" value=\"\"><mxGeometry height=\"50\" relative=\"1\" width=\"50\" as=\"geometry\"><Array as=\"points\"><mxPoint x=\"610\" y=\"300\"/></Array><mxPoint x=\"520\" y=\"300\" as=\"sourcePoint\"/><mxPoint x=\"610\" y=\"200\" as=\"targetPoint\"/></mxGeometry></mxCell><mxCell id=\"eeTA-m969tc2DToLa9s2-14\" parent=\"1\" style=\"rounded=1;whiteSpace=wrap;html=1;fillColor=#e1d5e7;strokeColor=#9673a6;\" value=\"\" vertex=\"1\"><mxGeometry height=\"60\" width=\"120\" x=\"550\" y=\"140\" as=\"geometry\"/></mxCell><mxCell id=\"eeTA-m969tc2DToLa9s2-15\" parent=\"1\" style=\"text;html=1;whiteSpace=wrap;strokeColor=none;fillColor=none;align=center;verticalAlign=middle;rounded=0;fontSize=16;fontColor=#B5739D;\" value=\"LCD 16x2 Display\" vertex=\"1\"><mxGeometry height=\"30\" width=\"100\" x=\"560\" y=\"155\" as=\"geometry\"/></mxCell><mxCell id=\"eeTA-m969tc2DToLa9s2-16\" parent=\"1\" style=\"text;html=1;whiteSpace=wrap;strokeColor=none;fillColor=none;align=center;verticalAlign=middle;rounded=0;\" value=\"5V Power\" vertex=\"1\"><mxGeometry height=\"30\" width=\"60\" x=\"425\" y=\"220\" as=\"geometry\"/></mxCell><mxCell id=\"eeTA-m969tc2DToLa9s2-17\" parent=\"1\" style=\"text;html=1;whiteSpace=wrap;strokeColor=none;fillColor=none;align=center;verticalAlign=middle;rounded=0;\" value=\"GPIO/Interrupts\" vertex=\"1\"><mxGeometry height=\"30\" width=\"60\" x=\"220\" y=\"240\" as=\"geometry\"/></mxCell><mxCell id=\"eeTA-m969tc2DToLa9s2-18\" parent=\"1\" style=\"text;html=1;whiteSpace=wrap;strokeColor=none;fillColor=none;align=center;verticalAlign=middle;rounded=0;\" value=\"GPIO\" vertex=\"1\"><mxGeometry height=\"30\" width=\"60\" x=\"600\" y=\"240\" as=\"geometry\"/></mxCell><mxCell id=\"eeTA-m969tc2DToLa9s2-19\" edge=\"1\" parent=\"1\" style=\"endArrow=classic;html=1;rounded=0;\" value=\"\"><mxGeometry height=\"50\" relative=\"1\" width=\"50\" as=\"geometry\"><mxPoint x=\"424\" y=\"330\" as=\"sourcePoint\"/><mxPoint x=\"424\" y=\"520\" as=\"targetPoint\"/></mxGeometry></mxCell><mxCell id=\"eeTA-m969tc2DToLa9s2-20\" edge=\"1\" parent=\"1\" style=\"endArrow=classic;html=1;rounded=0;\" value=\"\"><mxGeometry height=\"50\" relative=\"1\" width=\"50\" as=\"geometry\"><Array as=\"points\"><mxPoint x=\"220\" y=\"420\"/></Array><mxPoint x=\"425\" y=\"420\" as=\"sourcePoint\"/><mxPoint x=\"220\" y=\"520\" as=\"targetPoint\"/></mxGeometry></mxCell><mxCell id=\"eeTA-m969tc2DToLa9s2-21\" edge=\"1\" parent=\"1\" style=\"endArrow=classic;html=1;rounded=0;\" value=\"\"><mxGeometry height=\"50\" relative=\"1\" width=\"50\" as=\"geometry\"><Array as=\"points\"><mxPoint x=\"610\" y=\"420\"/></Array><mxPoint x=\"425\" y=\"420\" as=\"sourcePoint\"/><mxPoint x=\"610\" y=\"520\" as=\"targetPoint\"/></mxGeometry></mxCell><mxCell id=\"eeTA-m969tc2DToLa9s2-22\" parent=\"1\" style=\"rounded=1;whiteSpace=wrap;html=1;fillColor=#e3c800;fontColor=#000000;strokeColor=#B09500;\" value=\"\" vertex=\"1\"><mxGeometry height=\"60\" width=\"120\" x=\"160\" y=\"520\" as=\"geometry\"/></mxCell><mxCell id=\"eeTA-m969tc2DToLa9s2-23\" parent=\"1\" style=\"text;html=1;whiteSpace=wrap;strokeColor=none;fillColor=none;align=center;verticalAlign=middle;rounded=0;fontSize=16;fontColor=#FFFF99;\" value=\"SERVO\" vertex=\"1\"><mxGeometry height=\"30\" width=\"60\" x=\"190\" y=\"535\" as=\"geometry\"/></mxCell><mxCell id=\"eeTA-m969tc2DToLa9s2-24\" parent=\"1\" style=\"rounded=1;whiteSpace=wrap;html=1;fillColor=#e51400;fontColor=#ffffff;strokeColor=#B20000;\" value=\"\" vertex=\"1\"><mxGeometry height=\"60\" width=\"120\" x=\"550\" y=\"520\" as=\"geometry\"/></mxCell><mxCell id=\"eeTA-m969tc2DToLa9s2-25\" parent=\"1\" style=\"text;html=1;whiteSpace=wrap;strokeColor=none;fillColor=none;align=center;verticalAlign=middle;rounded=0;fontColor=#00FF00;fontSize=16;\" value=\"LEDS\" vertex=\"1\"><mxGeometry height=\"30\" width=\"60\" x=\"580\" y=\"535\" as=\"geometry\"/></mxCell><mxCell id=\"eeTA-m969tc2DToLa9s2-26\" parent=\"1\" style=\"rounded=1;whiteSpace=wrap;html=1;fillColor=#76608a;fontColor=#ffffff;strokeColor=#432D57;\" value=\"\" vertex=\"1\"><mxGeometry height=\"60\" width=\"120\" x=\"365\" y=\"520\" as=\"geometry\"/></mxCell><mxCell id=\"eeTA-m969tc2DToLa9s2-27\" parent=\"1\" style=\"text;html=1;whiteSpace=wrap;strokeColor=none;fillColor=none;align=center;verticalAlign=middle;rounded=0;fontSize=16;fontColor=light-dark(#c01c28, #ededed);\" value=\"&lt;div&gt;Buzzer&lt;/div&gt;\" vertex=\"1\"><mxGeometry height=\"30\" width=\"60\" x=\"395\" y=\"535\" as=\"geometry\"/></mxCell><mxCell id=\"eeTA-m969tc2DToLa9s2-28\" parent=\"1\" style=\"text;html=1;whiteSpace=wrap;strokeColor=none;fillColor=none;align=center;verticalAlign=middle;rounded=0;\" value=\"&lt;div&gt;GPIO&lt;/div&gt;\" vertex=\"1\"><mxGeometry height=\"30\" width=\"60\" x=\"210\" y=\"460\" as=\"geometry\"/></mxCell><mxCell id=\"eeTA-m969tc2DToLa9s2-29\" parent=\"1\" style=\"text;html=1;whiteSpace=wrap;strokeColor=none;fillColor=none;align=center;verticalAlign=middle;rounded=0;\" value=\"GPIO\" vertex=\"1\"><mxGeometry height=\"30\" width=\"60\" x=\"420\" y=\"460\" as=\"geometry\"/></mxCell><mxCell id=\"eeTA-m969tc2DToLa9s2-31\" parent=\"1\" style=\"text;html=1;whiteSpace=wrap;strokeColor=none;fillColor=none;align=center;verticalAlign=middle;rounded=0;\" value=\"GPIO\" vertex=\"1\"><mxGeometry height=\"30\" width=\"60\" x=\"600\" y=\"460\" as=\"geometry\"/></mxCell><mxCell id=\"eeTA-m969tc2DToLa9s2-32\" edge=\"1\" parent=\"1\" style=\"endArrow=classic;html=1;rounded=0;\" value=\"\"><mxGeometry height=\"50\" relative=\"1\" width=\"50\" as=\"geometry\"><mxPoint x=\"424\" y=\"580\" as=\"sourcePoint\"/><mxPoint x=\"424\" y=\"720\" as=\"targetPoint\"/></mxGeometry></mxCell><mxCell id=\"eeTA-m969tc2DToLa9s2-33\" parent=\"1\" style=\"rounded=1;whiteSpace=wrap;html=1;fillColor=#f5f5f5;gradientColor=#b3b3b3;strokeColor=#666666;\" value=\"\" vertex=\"1\"><mxGeometry height=\"60\" width=\"120\" x=\"365\" y=\"720\" as=\"geometry\"/></mxCell><mxCell id=\"eeTA-m969tc2DToLa9s2-34\" parent=\"1\" style=\"text;html=1;whiteSpace=wrap;strokeColor=none;fillColor=none;align=center;verticalAlign=middle;rounded=0;fontColor=#666666;fontSize=16;\" value=\"&lt;div&gt;UART&lt;/div&gt;\" vertex=\"1\"><mxGeometry height=\"30\" width=\"60\" x=\"395\" y=\"735\" as=\"geometry\"/></mxCell><mxCell id=\"eeTA-m969tc2DToLa9s2-35\" parent=\"1\" style=\"text;html=1;whiteSpace=wrap;strokeColor=none;fillColor=none;align=center;verticalAlign=middle;rounded=0;\" value=\"UART\" vertex=\"1\"><mxGeometry height=\"30\" width=\"60\" x=\"420\" y=\"630\" as=\"geometry\"/></mxCell></root></mxGraphModel></diagram></mxfile>","toolbar":"pages zoom layers lightbox","page":0}"></div> | ||
| - | <script type="text/javascript" src="https://app.diagrams.net/js/viewer-static.min.js"></script> | ||
| - | </body> | ||
| - | </html> | ||
| - | |||
| - | ===== Hardware Design ===== | ||
| - | |||
| - | ==== Components list ==== | ||
| - | |||
| - | * 1 x ATmega328P Xplained Mini development board | ||
| - | * 1 x micro-USB data cable | ||
| - | * 1 x 4x4 keypad | ||
| - | * 1 x 16x2 LCD, 5V | ||
| - | * 1 x SG90 micro servo motor | ||
| - | * 1 x active buzzer | ||
| - | * 1 x bi-color LED (red/green, 3 pins) | ||
| - | * 2 x 220 Ohm resistors | ||
| - | * 1 x 10 kOhm potentiometer | ||
| - | * 1 x breadboard | ||
| - | * jumper wires | ||
| - | |||
| - | ==== Hardware description ==== | ||
| - | |||
| - | The ATmega328P Xplained Mini is the main controller and will be placed on a breadboard together with the supporting passive components. A 16 MHz crystal and two 22 pF capacitors will be used for stable clock generation. The reset pin will use a push button and a 10 kOhm pull-up resistor. | ||
| - | |||
| - | The LCD will display the current level, the timer, and game messages such as: | ||
| - | * "Press Start" | ||
| - | * "Level 1" | ||
| - | * "Time left: 45 s" | ||
| - | * "Success" | ||
| - | * "Time over" | ||
| - | |||
| - | The servo motor will be used to physically open the box. Because the servo may create small voltage fluctuations, a larger capacitor (100 uF) will be placed on the power rail for stabilization. | ||
| - | |||
| - | The buzzer will provide sound notifications: | ||
| - | * game start | ||
| - | * warning near timeout | ||
| - | * success | ||
| - | * failure | ||
| - | |||
| - | The LEDs will provide simple visual feedback: | ||
| - | * green LED = success | ||
| - | * red LED = failure or timeout | ||
| - | |||
| - | The buttons will be used as follows: | ||
| - | * **Start** button – starts the round and opens the box | ||
| - | * **Finish** button – confirms the end of the round | ||
| - | * **Reset / Next** button – moves to the next level or restarts the game | ||
| - | |||
| - | ==== Covered laboratory topics ==== | ||
| - | |||
| - | The project is designed to cover at least three laboratory topics from the course, not counting Lab 0. | ||
| - | |||
| - | * **Lab 1 – UART** | ||
| - | * sending debug messages to a PC terminal | ||
| - | * printing the current state of the system | ||
| - | * displaying information such as level, remaining time, success, or failure | ||
| - | |||
| - | * **Lab 2 – Interrupts** | ||
| - | * handling button events | ||
| - | * reacting to time-based events more efficiently | ||
| - | * improving responsiveness of the game logic | ||
| - | |||
| - | * **Lab 3 – Timers / PWM** | ||
| - | * implementing the countdown timer | ||
| - | * generating the PWM signal for servo control | ||
| - | * controlling timing for buzzer and visual feedback | ||
| - | |||
| - | Optionally, the project may also include: | ||
| - | |||
| - | * **Lab 6 – I2C** | ||
| - | * if an I2C LCD adapter is used, the display can be controlled through the I2C interface | ||
| - | |||
| - | Although GPIO is naturally used in the project for buttons, LEDs, and basic control signals, the core requirement of covering at least three laboratories is satisfied through UART, Interrupts, and Timers/PWM. | ||
| - | |||
| - | ===== Software Design ===== | ||
| - | |||
| - | The firmware will be developed in C for AVR using PlatformIO as the main development environment. PlatformIO is useful for this project because it offers an easier build system, project structure, library management, serial monitor support, and firmware upload integration. | ||
| - | |||
| - | At this stage, the implementation is still in progress, so this section presents the general software structure and the main ideas that will be used in the final version. | ||
| - | |||
| - | ==== Development environment ==== | ||
| - | |||
| - | * **PlatformIO** – used for project management, building, uploading, and serial monitoring | ||
| - | * **AVR toolchain** – used for compiling the firmware for the ATmega328P | ||
| - | * **AVRDUDE** – used for uploading the compiled code to the development board | ||
| - | * **UART serial monitor** – used for debugging and hardware testing during development | ||
| - | |||
| - | ==== Libraries and external resources ==== | ||
| - | |||
| - | For the moment, the project mainly relies on standard AVR headers and basic low-level control of the microcontroller peripherals. Depending on the final implementation, simple helper modules may be added for: | ||
| - | * LCD control | ||
| - | * keypad scanning | ||
| - | * servo control using PWM | ||
| - | * UART debugging | ||
| - | |||
| - | At this stage, the focus is on understanding and controlling the hardware directly, without relying too much on complex third-party libraries. | ||
| - | |||
| - | ==== General software structure ==== | ||
| - | |||
| - | The software will be organized into simple functional modules, each responsible for one part of the system. A possible structure is the following: | ||
| - | |||
| - | * `main.c` – main program flow and initialization | ||
| - | * `keypad.c / keypad.h` – keypad scanning and key detection | ||
| - | * `lcd.c / lcd.h` – LCD control and message display | ||
| - | * `servo.c / servo.h` – servo control using PWM | ||
| - | * `buzzer.c / buzzer.h` – buzzer control and sound signals | ||
| - | * `led.c / led.h` – bi-color LED control | ||
| - | * `timer.c / timer.h` – countdown and timing logic | ||
| - | * `uart.c / uart.h` – debugging through serial communication | ||
| - | * `game.c / game.h` – state machine and game rules | ||
| - | |||
| - | The exact number of source files may change during implementation, but the software will follow this modular idea. | ||
| - | |||
| - | ==== Main algorithms and planned logic ==== | ||
| - | |||
| - | The project will be based on a **finite state machine**, because the application naturally moves through several distinct stages. The most important software states are: | ||
| - | |||
| - | * **Idle** – the system waits for user input | ||
| - | * **Start / Opening** – the game starts and the servo opens the box | ||
| - | * **Running** – the challenge is active and the countdown is displayed | ||
| - | * **Success** – the user finishes in time | ||
| - | * **Fail / Timeout** – the user does not finish before the timer expires | ||
| - | * **Next Level / Reset** – the system prepares the next round | ||
| - | |||
| - | The main software logic will include: | ||
| - | * keypad input reading | ||
| - | * LCD message updates | ||
| - | * countdown handling using timers | ||
| - | * servo activation through PWM | ||
| - | * buzzer and LED feedback | ||
| - | * level progression and reset logic | ||
| - | * UART-based debugging during testing | ||
| - | |||
| - | ==== Planned firmware behavior ==== | ||
| - | |||
| - | At a general level, the firmware is expected to work as follows: | ||
| - | |||
| - | * initialize all hardware modules | ||
| - | * wait for the user to start the game | ||
| - | * open the box using the servo motor | ||
| - | * show the current level and remaining time on the LCD | ||
| - | * read user commands from the keypad | ||
| - | * detect whether the challenge is completed in time | ||
| - | * signal success or failure using the buzzer and bi-color LED | ||
| - | * optionally move to the next level or restart the system | ||
| - | |||
| - | ===== Conclusions ===== | ||
| - | |||
| - | ===== Jurnal ===== | ||