:: this week we are required to Design and program a smart device that performs a certain function using an Arduino UNO which reads a signal from an input component to control an action component using Arduino C (Text Code).
the inspiration this time came from one of the projects I made with kids in a robotics course and I wanted to try it in reality with an Arduino and see what happens, I'll trust the process.
Things don't make themselves, You need some tools and smart software to be able to create your device
Software
From now on, the Tinkercad will become your new friend.
Tinkercad is used for creating digital designs that are ready to be 3D printed or to simulate electric circuits and/or code them. we will use it to simulate an electric circuit before making it in real to test wiring and avoid components burning.
This week we are going to start coding as text code not blocks
Arduino IDE is used for writing code and connecting with an Arduino bored to get actions done, this time we do not write code but turn the coding blocks into written code in IDE.
Electronics tools
INPUT: simple switch to control some aspect of a machine or a process, When the pushbutton is open (unpressed) there is no connection between the two legs of the pushbutton, so the pin is not connected to the ground and we read a HIGH. When the button is closed (pressed), it makes a connection between its two legs, connecting the pin to the ground, so that we read a LOW, so we use this term in code (INPUT_PULLUP) to be reversed.
INPUT: This is an electronic device that measures and detects infrared radiation in its surrounding environment, it gives an electrical signal as an output when an object comes in front of it so this can be translated as LOW in coding.
OUTPUT: consists of seven LEDs. Each of the seven LEDs is called a segment, As each LED has two connecting pins, one called the “Anode” and the other called the “Cathode”, there are therefore two types of LED 7-segment display called: Common Cathode and Common Anode. we use a common cathode, which means all the cathode connections of the LED segments are joined together to ground
OUTPUT: to move things by converting signals into rotational angular velocity
jumper wires have 3 types male-male wires, male-female wires, and female-female wires. All of these connect two points to each other and make the circuit closed
to-use programmable open-source microcontroller board that can be integrated into a variety of electronic projects.
is used for building circuits, and demonstrating its action
to reduce current flow, and divide voltages
crafting tools
we need some material to aid us in enclosure such as: -cardboard -glue gun -cutter -scissors
you will be exposed to this program interface of Tinkercad when you decide to create a simulation circuit
after you choose the circuit button, you get free space for designing and wiring. let's get to know the buttons that make it easier to use the program:
first you will find and search for any components here
if you need to back-step or clear all steps, choose these arrows
you can color wires and make a color coding through the tap of coloring
finally after finishing the circuit wiring, start the simulation to make sure that the wiring is right or has an error
the breadboard has 3 sized types, you can choose any type of them but in this project, I chose a full-size breadboard because I had more terminals of components and to make the wiring clear
here is the final wiring, I used color coding, red for positive and black for negative.
servo motor and PIR sensor have three terminals, one for 5V, another for Ground, and a third for pins, while the push button has two just terminals one for ground and another for pins. I need to light LED from 0 to 9 so I added 8 resistors (7 for LEDs, the last for DP) to 7 segment, the resistors are 220 Ohm. Each resistor connected to the segment and pin
::Note the resistor of DP isn't important
Tinkercad wiring shows the connection of pins :
servo motor: Pin 4
push button: Pin 3
PIR sensor: Pin 5
7 segment: ( A to 11) (B to 10) (C to 7) (D to 8) (E to 9) (F to 12) (G to 13)
I used an Avometer to ensure that resistors are near to 220 Ohm.
firstly prepare your components:
breadboard - IR sensor - Push button- Servo motor -7 segment -Arduino- jumper wires
start matching Arduino with components in the breadboard: this photo shows the physical wiring typically the wiring in Tinkercad software.
note that in physical, I didn't consume the DP resistor, there are 7 resistors for each segment.
firstly I open the example of the servo code
and choose the terms I needed in my code then copy and paste them in my sketch
myservo. attach (the pin servo connected), myservo.write (the angle of rotation)
it's an integer variable from 6 to 13 for each segment, these variables don't have the right pins, it's just arrange the number.
I defined each pin as output or input in the void setup.
from the 7 segment code it functions for each number from 0 to 9, so I can replace each function with its number only
in the Void loop, I made the If function include other If function:
the 7 segment light number 0 by the default
waits for 1 sec
then If the push-button pressed
the servo will rotate to 90 degree
waits 1 sec
and then the other if function starts, so if the IR senses the ball
the 7 segments will count from 1 to 9
else the sensor senses nothing
the 7 segment returns to 0
all functions will be achieved until the push button is unpressed
when the push button is unpressed, the servo returns to 0 degrees.
the numbers 1, 5, and 6 weren't lit correctly, but I checked the code and found that there is a mistake in the order of the segments. the segment has to be high took a low order and vice versa.
the IR sensor didn't feel surrounded, but the instructor fixed it in the way shown in the figure.