Here we were testing the servo motor connected to the Arduino. It was our first try with the hardware, and it felt exciting to see the servo actually moving as we controlled it by coding in Arduino IDE app.
**How the Code Works 💻:
_The servo motor is controlled using the Servo library.
_ At the beginning, the servo rotates from 0° to 180° step by step, simulating a “looking forward” motion.
_Then, the servo rotates back from 180° to 0°, simulating a “looking back” motion. This is considered the first level.
_After completing the back motion, the system pauses for 60 seconds before repeating the movement again.
_This creates a repeated pattern of the servo head scanning forward and back with delays, imitating a head movement mechanism.
This time we tested the LCD with the Arduino. It was a fun moment to finally see text showing up on the screen after connecting and uploading the code. This step was important because later the LCD would be used to display the levels in our main project.
*Connections:🔌
_SDA → A4
_SCL → A5
_power (VCC to 5V) and GND from the Arduino
**How the Code Works 💻:
_The code uses the (LiquidCrystal\_I2C.h) to control the LCD.
-> In the setup() function:
_The LCD is initialized using mydisplay.init().
_The backlight() is turned on.
-> In the `loop()` function:
_The LCD displays “level 1” at position (column 5, row 1) and keeps it for 60 seconds.
_After that, it updates the screen to show “level 2” for 30 seconds.
_Finally, it shows “level 3” for 10 seconds.
_This sequence simulates game levels that change automatically with different waiting times.
tested the OLED. Since it wasn’t included in our sessions, I had to look it up on my own to understand how it works and how to code it. I went through several tutorials, collected different code snippets, and finally managed to make it run. Because the OLED isn’t available on Tinkercad, I used Wokwi to simulate it and check if everything was working fine. This step was a bit challenging for me. And i succeeded in showing the shapes we need for our project.
*Connections:🔌
_SDA → A4
_SCL → A5
_power (VCC to 5V) and GND from the Arduino
**How the Code Works 💻:
_the code uses Adafruit_GFX and Adafruit_SH110X (SSD1306 driver) libraries to control the OLED.
In the loop() function, three different shapes are displayed one after another:
_Rectangle: A border rectangle is drawn around the edges of the screen.
_Circle: A circle with a radius of 30 pixels is drawn at the center of the screen (64,32).
_Triangle: A triangle is drawn with its vertices at the top center (63,0), bottom left (0,63), and bottom right (127,63).
_After each shape is drawn, the screen is updated with display.display(), kept for 2 seconds, then cleared using display.clearDisplay() before the next shape appears.
This video was helpful for me in this coding
Next, we tested the laser module. It was a simple but exciting step, just turning the laser on and off through the Arduino. This test was also important because in the main project the laser will be used as one of the key features, so making sure it worked properly from the beginning was a must.
tested the ultrasonic sensor. The goal was to check if it could measure distance accurately or not. During the test, we observed the readings changing as we moved objects closer and farther away, which helped us confirm that the sensor was working correctly.
created a simulation of the full circuit on Tinkercad and also wrote the code to make sure everything was working correctly before starting the hardware assembly. This task was divided between me and Hagar: she was responsible for the wiring, while I focused on the coding. The circuit included an Arduino, a servo motor, an ultrasonic sensor, a PIR sensor, two LEDs acting as lasers, and an LCD to display the levels. All the sensors were connected to the Arduino, and the whole system was controlled by a switch that turns the circuit on and off when needed
The logic of the game starts with a welcome message and the press of a start . Once activated, the doll turns to the wall, and the music begins to play, giving players the chance to move forward. When the doll turns back, the music stops, and players must freeze immediately. If any movement is detected outside the safe zone, the system displays a message on the LCD and eliminates the player. Otherwise, the player continues to the next level until reaching the safe zone.
libraries & define pins
The Servo library controls the servo motor.
LiquidCrystal_I2C manages the LCD display.
DF Player Mini plays sound effects (MP3).
defined variables using (int).
Ultrasonic function & setup:
Coding Ultrasonic measurement function.
Sensors (PIR, IR, Ultrasonic) are set as inputs, motors and lasers as outputs
_MP3 Module Setup
_Switch Control
Levels & Looping:
_The loop organizes the project into different levels.