This week is inspired by the terrifying deadlines, the procrastination masters, the perfectionism freaks, and finally by Asker & Mego warnings in week 7.
I was thinking if there's a device that warns us like a danger bell before deadlines. Still, it takes action, so the main idea was to create a device that senses movement(ultrasonic sensor) and then senses light(LDR sensor), if there's light, the buzzer works. The servo motor start rotating the human from left to right, but I had many challenges-will be mentioned below- in the creation, so I changed the idea.
Still a danger bell, but also works as a reminder and motivational coach, it senses a movement, it asks you if you finished your work, if the answer is "YES", the LCD screen shows you a motivational sentence, if the answer is "NO", the buzzer makes sound and the LCD screen shows a different motivational sentence.
Woody Woodpecker - نقار الخشب
I started with creating the wiring on TinkerCad.
Using the on/off switch and the ultrasonic sensor(inputs); to open and detect if there's any object near or at the range of 30 cm -my body-, and using an on/off switch as an action button, the LCD screen and the buzzer(outputs); to display motivational quotes and make sound.
Writing the code in our language, it helps in searching for what you need or inspires you by using some examples from Arduino Uno.
So here's what I thought of:
On/Off switch for opening and closing the device works as a 1st input.
If the circuit is closed (the device is ON), the ultrasonic sensor will start sensing, if there's any movement near it (<30 cm) works as a 2nd input, and another circuit will open.
If the action button is ON -works as 3rd input-, the LCD screen will display "3ash ya fnana <33", and it works as a 2nd output.
If the action button is OFF , the LCD screen will display "tb ma tgrb ya5y! 3ndk 7aga t5srha??", and the buzzer will start making noise -works as the 3rd output-.
Started with testing the LCD screen by using "hello example", Asker's video, will drop the link below, starting from 2:30 minutes.
After writing the code, I tested the LCD screen alone with the Arduino Uno.
I learned something new here - also the wiring of the LCD screen
lcd.clear();
is important, as it allows the screen to switch between two sentences I guess.
lcd.setCursor (0,0);
is for the position of the characters, but also it must be before the writing not after.
After that, I started wiring the on/off switch and the ultrasonic as inputs, and searched for the coding of the ultrasonic sensor.
The button below includes the code on Arduino Uno ⬇️
#include <LiquidCrystal_I2C.h>
LiquidCrystal_I2C lcd(0x27, 16, 2);
long readUltrasonicDistance(int triggerPin, int echoPin) {
pinMode(triggerPin, OUTPUT); // Clear the trigger
digitalWrite(triggerPin, LOW);
delayMicroseconds(2);
// Sets the trigger pin to HIGH state for 10 microseconds
digitalWrite(triggerPin, HIGH);
delayMicroseconds(10);
digitalWrite(triggerPin, LOW);
pinMode(echoPin, INPUT);
// Reads the echo pin, and returns the sound wave travel time in microseconds
return pulseIn(echoPin, HIGH);
}
// Pin definitions
const int powerButtonPin = 2; // Button to turn the device on/off
//const int sensorPin = 7; // Sensor to detect presence
const int actionButtonPin = 3; // Button to control LCD message and buzzer
const int buzzerPin = 5; // Buzzer
bool deviceOn = false;
void setup() {
pinMode(powerButtonPin, INPUT_PULLUP);
//pinMode(sensorPin, INPUT);
pinMode(actionButtonPin, INPUT_PULLUP);
//initialize lcd screen
pinMode(buzzerPin, OUTPUT);
lcd.init();
// turn on the backlight
lcd.backlight();
lcd.setCursor(0, 0);
}
void loop() {
// Check if the power button is pressed
if (digitalRead(powerButtonPin) == LOW) {
deviceOn = !deviceOn; // Toggle the device state
delay(300); // Debounce delay
}
if (deviceOn) {
if (0.01723 * readUltrasonicDistance(6, 7) < 30) {
// Someone is detected
if (digitalRead(actionButtonPin) == LOW) { //action button is on
lcd.clear();
//lcd.setCursor(2, 1);
lcd.print("3ash ya fanana");
lcd.setCursor(2, 1);
lcd.print(" <333");
digitalWrite(buzzerPin, LOW); //turn off the buzzer
//lcd.setCursor(0, 2);
//delay(1000);
//wait for a second
} else { // actionButtonPin is off
lcd.clear();
lcd.print("tb ma tgrb ya5y!");
lcd.setCursor(1, 1);
lcd.print("5sran kol 7aga!");
digitalWrite(buzzerPin, HIGH); //turn on the buzzer
//lcd.setCursor(0, 1);
//delay(1000);
}
} else {
// No one is detected
lcd.clear();
lcd.noBacklight();
lcd.print("No presence");
digitalWrite(buzzerPin, LOW); // Ensure buzzer is off
}
} else {
// If the device is off, clear the LCD and turn off the buzzer
lcd.clear();
digitalWrite(buzzerPin, LOW);
}
delay(100); // Small delay to stabilize the loop
}
Wiring Details:
Power Button Pin connected to the digital pin 2 on Arduino
Ultrasonic sensor is connected to pin 6 from TRIG and to pin 6 from ECHO.
Action Button Pin is connected to pin 3 on Arduino.
The buzzer is connected to pin 5 in Arduino from the +ve side, and the -ve side to GND.
The LCD screen has 4 wires, the SDA with A4, the SCL with A5, the VCC with the +ve rail on the breadboard, and the GND with the -ve rail on the breadboard which is connected to the GND
A product that you put beside your bed, once it senses you, it asks if you finished all your tasks, if you answered YES by pressing on 1, the screen displays "3ash ya fnana! <33" , the other case, the buzzer will start making you hate your life, and the screen displays "tb ma tgrb ya a5y! 5sran kol 7aga!"
The reference <33
The making process was not easy actually..
But here's some stuff I learned, the box of the components has to be big & wide; because the wiring kept missing.
Measuring the components helps a lot.
You have to make space for the wires of the sensor and the LCD, so you can check that they are connected.
والله انني وصلت لهنا, دا كان تحدي أصلاً, يلا الحمدلله :""
الwiring هيجنني يا مُعتز
Even after taping the wires, it kept loosing.
Me reading the missing lines in my code from Chatgpt
Generating code for every component wasn't easy for me, but the hardest part was making the push button and the action button work.
Honestly, I used Chatgpt, and it helped me out.
Not testing problems, made me waste 4 days of generating code that didn't work; because the LDR sensor wasn't working.
Changing the idea, after trying for 5 days in other idea, and I had to change it eventually.
Top el top bgd
Generating a code from the beginning.
Sticking to an idea that doesn't work, be flexible to change some features in order to work.
Using Chatgpt to debug my code.
Be patient in learning codes
What BUG means or came from
نمشي عمياني ورا الفيديوهات - فيلم الكيت كات 😍
I was crying; because I felt very stupid in every step.
Then Menna told me, that it was okay, and we can copy-paste from examples and the codes we generated before, that helped me a lot.