Welcome 😊
This week we had to build and program a smart circuit using an Arduino UNO.
This week our assignment is to build and program a smart circuit using an Arduino UNO which it has two input components and two action components and programming it using Arduino C code.
My inspiration came from my final project as it uses the some of the same components.
Wokwi used to design my circuit diagram.
Arduino IDE used to program the Arduino UNO.
Wokwi circuit
I start by using Wokwi to build my circuit diagram.
Wokwi Components that I used during designing:
Arduino UNO
LCD Screen + I2C Module
Keypad 4x3
Push Button
Buzzer
Braking Down:
I connect the LCD Screen to the Arduino by connecting VCC to 5V pin, GND to GND pin, SDA to A4 pin and SDL to A5 pin.
I connect the Keypad to the Arduino using digital pins from D3 to D9.
I connect the Push Button to D2 and GND.
I connect the the anode terminal of the Buzzer to D11 and cathode to GND pin.
NotBinaryGame.ino code
pitches.h & tunes.h code
I start by install and including the libraries needed for the Keypad and the LCD Screen, then defined some variables that I'm gone need during writing my code and also assign pins numbers to variables to make it easier to debug later if needed.
Then I start by creating some functions that would make my life easy as It would reduce the line of code by write the function code once and re-use it every time I need it instead of writing it all over again when I need the same part of code.
Functions quick brake down:
getbinary() : It takes a integer parameter then translate it to it binary representation then return it back as a string.
newsround() : It start by assign values to some variables and generate random number between 0 & 255 and assign it to a variable then print the text and some variables value on the LCD Screen.
checknum() : It start by convert numbers string data type variable to integer value and assign it to a variable and then inside if condition it check if the value of a variable is equal to specific value then it assign a specific value to a specific variable else it wound check other if condition that checks it two variables have the same value then it would assign a specific value "1" to specific variable else it wound assign different specific value "2" to specific variable.
setup() : It start by initialize communication between the Arduino and the LCD screen, then set pin mode and set the serial communication speed and set "random seed" then call "newsround()" function to start a new round once the Arduino is powered up.
loop(): Here all the previse functions are used with each other in a infinity loop first it define an interruption function that only when it triggered it call specific function. After that it reads the value from the keypad and assign it to a variable then if that key is pressed in enters an if condition that checks if the counter is lower that a specific number it it update and print of screen with every key press of the keypad and sore that pressed key in an array to be used later then after that there are three if conditions that check if the user enter the correct answer or not or does the use enter the easter egg code. and depending of those if conditions it call the right functions to execute its code
Note:
pitches.h file & tunes.h are ready made code that I used and tinker with to fit my needs in this project.
I used the same components as on Wokwi I wire it all and I placed the buzzer directly on the Arduino connecting it to D11 and GND pins then I connect the Arduino to the computer and upload my code.
When powering on the Arduino the game start by giving the user binary number on the LCD screen and waiting for the user to convert the binary number to decimal number and type it using the keypad and as the user typing the screen updates showing the user input in real time and after that user would submit the answer using the push button. If it is correct the LCD screen would display "CORRECT!" and cheer him up by playing a tune from the buzzer and if the answer was incorrect the LCD screen would display "INCORRECT!" and ask him to try again. Also there is an easter egg mode when the user enter the secret code 3122 the program would enter infinity loop and stuck there while display a massage and playing a tune over and over at this point there is no escape but luckily if the user press the push button the Arduino would do a soft reset and the game would start again.
No Binary Game
❤️
Me and my team-mate Basem. We managed to build and program a simple smart home system using Arduino during EoWeek activity.
I showed Amani, Ibrahim and the rest of my group my project for this week and they like it and enjoy playing with it.
Also me and colleagues, we all like to talk and sharing knowledge & ideas.
❤️
While I was tasting my code. I was using attachInterrupt() to be triggered when I press the push button so I pressed the push button but nothing happed 😅. so I checked the code but it looks fine trying again still nothing then I start to test my connection using multimeter continuity test but everything is connected so it must be the code🤦🏻♂️after searching and reading the Arduino reference page of that function I found out that function only works with two pins only (D2,D3 on Arduino UNO) and I was connecting my push button on a different pin 😅 so I change the connection and it work right away.
The skills & knowledge I have acquired this week would help me using the Arduino and the LCD Screen in my project.
The LCD Screen is not that hard to use especially with I2C module.
I was looking for some website or software that is free and easy to use to design my circuit and after so searching I stumbled upon Wokwi