The assignment for this week was to Build and Program a smart circuit using an Arduino UNO which reads a signal from an input component to control an action component using Code Blocks.
I used code block to program Arduino but I need to write some lines of code in Arduino IDE.
The idea of my assignment is to make a game...
A long hand rotate in front of Ultrasonic sensor
I should press the button in the right time (the hand should cover the Ultrasonic sensor)
When I press in the wrong time my score return to zero
A 7-segment component show my score
Green LED lights when the game is on
Red LED light when u gain a point
I used Tinkercad first to build my circuit
and Arduino IDE to edit my code and upload it to Arduino
Components:
Arduino Uno
Red LED & Green LED
7-Segment
Servo motor
Ultrasonic sensor
250 & 550 ohm resistor
Buzzer (in tinkercad only as my buzzer is damaged XD:)
I start on tinkercad step by step in order not to be confused...
I add Arduino, breadboard, Ultrasonic sensor, red LED and a buzzer then I test them first, then buzzer and red LED work when Ultra sensor read distance below 20cm
I add Servo motor and make it move when ultrasonic sensor read distance less than 20cm
I add a push-button, which function is when it's pressed the buzzer and red LED work
I add the "7-segment " component and I program it when the Ultrasonic sensor read distance below 20cm and the push-button is press the player gain one point and the "7-segment" count up
I add 7-segment code in Arduino IDE, I didn't use code-blocks to program it because it would be very complicated to make it in code-block
Coding steps:
make variable called "angle" which determine the angle of the servo motor
make variable called "dir" which determine the direction of the servo motor (up or down)
if direction is "1" the angle will decrease and if the direction is "2" the angle will increase
then I put a condition to control the variable "angle" to be within (0-180) degree
When I press the button when the ultrasonic sensor reads distance below 20cm the buzzer and the LED pin will be set to "HIGH" then will wait 0.3 second then the buzzer and the LED will be turned off
the I move to the 7-segment coding... I didn't code the 7-segment with code block, instead I write the code in Arduino IDE
I make a function called "_7segment" with a variable called "num", and when I pass a number from 0 to 9 to this function the 7-segment will show this number
After the circle worked of tinker cad I copied the code and pest it in Arduino IDE and make some changes and edits in the code like the function for the "7-segment" and the duration
I was also wiring the circuit step by step as the same steps above in the tinker cad
Finally - Play the game
The Saturday's session was great and we make a shaking hand with manual and automatic mode. I got a lot of help from Sara Alaa and ideas to make the code more simple.
Also some of my teammates face problems and I try to help them solving their issue.
I faced a strange problem, the two videos below explain the problem
I tried many timer till I found the solution, but I didn't know why this problem happened
I will use the servo motor to control the weight to direct my spherical robot right and left
I will use the Ultrasonic sensor to see if the robot is near to a wall or barrier then it will stop or reverse direction
What was very cool and nice was the hand shaking that we made in the lap
I made it with Sara Alaa
Title of Media