Tutorials
Coding Via Arduino IDE
eeThis week contains 4 main milestone activities:
Midweek , EOweek Videos and tutorials include how to program an Arduino to control a single action component: LED, Buzzer, DC Motor, and Servo Motor using Code Blocks. View the Code blocks and transferring them to Ardunio IDE code.
practicing on some Exercises as Power an RGB LED using Ardunio Uno so that it lights up with different color tones. Also, powering a "8-segment display", so that it shows the descending numbers from 9 to 1. programming the ardunio with ultrasonic sensor with ledRGB, and LED with LDR.
Doing the Weekly assignment about building and programming a smart circuit using an Arduino UNO which reads a signal from an input component ultrasonic sensor and a switch to control an action component Motor and RGB LED using Code Blocks.
RGB light Red Fading
7 segment screen with Ardunio uno
Blocks Coding via tinker cad
Controlling Pizzo with Ardunio Uno
Practising Tutorials
For the materials: i used some electrical sets from the given Kit as follows:
Along the week Assignments
Arduino Uno
Motor Driver L298N
DC Motor 5V
Servo Motor
Buzzer
8 segment display
RGB, LED Lamps 2.2V
Slider Switch push buttons
DC Power Adapter 9 V
DC Jack to terminal block converter
Jumper Wires MM, MF
Screw Driver
Buzzer 5V
Potentiometer 1 K ohm
Resistor 220
Breadboard
USB Connection
LDR Sensor
Ultrasonic Sensor
Microwave Sensor
In the Smart Circuit i made, I used:
Arduino Uno
Resistor 220
Servo Motor
RGB LED Lamp
Ultrasonic Sensor
Jumper Wires MM, MF
USB Connection
Slider Switch
Ruler
For the software:
I used the tinkercad as a simulation program that used for simulating the electric circuits.
Arduino Uno IDE 1.8.15 programming Software.
HTML Color picker website in order to select the RGB of each color.
Arduino Uno
Motor Driver L298N
Arduino Uno IDE programming Software
HTML Color picker website
USB Connection From Arduino to Laptop
Screw driver
Led
Breadboard
Motor
Potentiometer
Resistors 220 ohm
Wires male male
Servo Motor
8_ Segment Screen
RGB LED
Mini Breadboard
Ultrasonic Sensor
Microwave Sensor
LDR Sensor
PIR Sensor
Card Board and Colored paper
Ex. 1: Programing Arduino board to control RGB LED so that it lights up with the following colors in order: Red, Blue, Green, Purple, Orange, and White.
I used the Tinker cad to simulate the circuit and building the coding of the Arduino Uno with the blocks code method.
First, i chose the Ardunio Uno, mini breadboard, RGB LED, and resistors of 220 ohm.
i placed the RGB LED in the breadboard along the lower side.
i connceted the Ground of the Ardunio with the -Ve side of the breadboard then to the Common Cathode of the RGB LED.
I added 220 ohm resistors along each color of the RGB LED connected to the other upper side of the Bread board.
Each color on the RGB LED RED, GREEN, BLUE by sequence, I supplied them to the analog pins on the Arduino Uno 3,6,9 respectively.
Then to the Coding step>>> i opened the Blocks code tab in the tinker cad, then I chose from the output panel < <set RGB LED in pins x,y,z to color F>> to the workspace.
By default, it is set to 3, 3, 3 and colour to red. i change the second 3 to 6 with green colorand the third 3 to 9 with blue color.
i entered the Pins i connected above with the RGB Colors by sequence as 3,6,9 in the code, then the color by sequence RED then GREEN Then BLUE.
I chose from the control coding panel << wait >> and set it as 1 sec.
This previous step was repeated 5 times with adjusting the color in each one as the following sequence>> Red, Blue, Green, Purple, Orange, and White <<<
I simulated the code to check all things gonna alright, and it is working well!
Then, I opened Arduino IDE and copied the text code from tinker to it.
then I saved the file, and upload it to the Actual Ardunio after porting it with the USB.
The next step was to implement it using physical components and the Arduino UNO board to build it.
Output Code Key
Simulating using the Tinker Cad
Simulation Video of Exercise one
"RGB LED + ARDUNIO UNO"
Demo Video of the Real Implemntation
"RGB LED + ARDUNIO UNO"
Ex. 2: Programing Arduino board to control 7-segment display so that it counts down from 9 to 1.
I used the Tinker cad to simulate the circuit and building the coding of the Arduino Uno with the blocks code method.
First, i chose the Ardunio Uno, mini breadboard, 7-segment screen, and resistors of 220 ohm.
i placed the 7-segment screen in the breadboard along the lower side.
i connceted the Ground of the Ardunio with the -Ve side of the breadboard then to the Common Cathode of the Display.
I supplied each node of the screen to another side of the breadboard, and crossed resistors 220 ohm over them.
then, from the other side of the resistors, I supplied each outer node of the screen with a wire to the analog pins on the Arduino Uno from 1to 8 respectively.
Then to the Coding step>>> i opened the Blocks code tab in the tinker cad, then I chose from the output panel < <set pin x to High/Low>> to the workspace.
I entered the pins numbers as i chose from 1to 8 respectively.
I chose from the control coding panel << wait >> and set it as 1 sec.
Then I searched for the reference of the code numbers in the display to settle each no. On mode segment with High and the off mode segment with Low.
This previous step was repeated 8 times by adjusting the segments with high or low.
I simulated the code to check all things gonna alright, and it is working well!
Then, I opened Arduino IDE after copying the code from tinker cad, and upload it to the Actual Ardunio after porting it with the USB.
The next step was to implement it using physical components and the Arduino UNO board to build it.
Code Key
Simulating using the Tinker Cad
Simulation Video of Exercise one
"7_segment Display + ARDUNIO UNO"
Output Code Key
Demo Video of the Real Implemntation
"RGB LED + ARDUNIO UNO"
IEx. 3: Programing Arduino board with an ultrasonic sensor to control RGB LED with the variation of distances through the sensor.
I used the Tinker cad to simulate the circuit and building the coding of the Arduino Uno with the blocks code method.
First, i chose the Ardunio Uno, mini breadboard, ultrasonic sensor PNG/ HC SR04, RGB LED, and resistors of 220 ohm.
i placed the RGB LED in the breadboard along the lower side.
i connceted the Ground of the Ardunio with the -Ve side of the breadboard then to the Common Cathode of the RGB LED.
I supplied each node of RGB colors RED, Green, Blue to another side of the breadboard, and crossed resistors 220 ohm over them.
In case of using the ultrasonic sensor PING:
then, from the other side of the resistors, I supplied each outer node of the screen with a wire to the analog pins on the Arduino Uno from 3,5,6 respectively.
Then I supplied the ultrasonic to the Arduino pins, the Grd with the ground of Arduino, the power of sensor with 5v, and the SIG pin with the Anlog in pin A0.
Then to the Coding step>>> i opened the Blocks code tab in the tinker cad, then I chose from the input panel < <Read the ultrasonic sensor on trigger pin A0, the echo on same trigger in Cm>> to the workspace. Then I used the Math equation of :
9- i replace the first one with the input read sensor i entered above, and the other one with 150 cm , this will be merged into IF statement, then it will be as follows:
10- From the output i chose the>>> Set pin to High<<, and i entered all the pins chosed above to this formula to be as follows:
11. This previous step was repeated 3 times by adjusting the segments with high or low. and the distance also of the sensor. I simulated the code to check all things gonna alright, and it is working well!
In the case of using the ultrasonic sensor HC SR04:
then, from the other side of the resistors, I supplied each outer node of the screen with a wire to the analog pins on the Arduino Uno from 11,9,10 respectively.
Then I supplied the ultrasonic to the Arduino pins, the Grd with the ground of Arduino, the power of sensor with 5v, and the Trig pin with the Digital pins 7 and the ECHo with 6.
Then to the Coding step>>> i opened the Blocks code tab in the tinker cad, then I chose from the input panel < <Read the ultrasonic sensor on trigger pin 7, the echo on 6 in Cm>> to the workspace. i set the 2 variables in this code, one of the X that refers to the sensor read and the other for the distance measurement that I fixed to 200 cm.
i made three equations as follows:
5- After that, i chose the output pins 9,10,11High/LOW to make the light colors emitting from RGB LED. The full path can be illustrated as follows:
6. I simulated the code to check all things gonna alright, and it is working well!
7. Then, I opened Arduino IDE after copying the code from tinker cad, and upload it to the Actual Ardunio after porting it with the USB.
8. The next step was to implement it using physical components and the Arduino UNO board to build it.
Ex. 4: Programing Arduino board with an LDR Sensor to control LED in case of no light/ light in the space.
I used the Tinker cad to simulate the circuit and building the coding of the Arduino Uno with the blocks code method.
First, i chose the Ardunio Uno, mini breadboard, LDR sensor, red LED, and resistors of 220 ohm.
i placed the LED and sensor in the breadboard along the upper side.
i connceted the Ground of the Ardunio with the -Ve side of the breadboard then to the Cathode of the LED.
then, from the other side of the resistors, I supplied node of the led to pin 3 in Arduino, and for the Sensor, I supplied one leg into the power of Arduino and the other with the analog pin A0.
Then to the Coding step>>> i set a variable of the photosensor Ldr read, to read the analog in A0.
i chose the print to monitor to read the serial numbers on the screen>> the output was numbers of 0 to 1023>> so I chose the map equation to scale these numbers from 0 to 255.
when I simulated this, I see that the light is all on with no variations so I added a resistor for this LED to minimize the current crossing the sensor.
The code definition on the Tinker Cad
9. I simulated the code to check all things gonna alright, and it is working well!
10. Then, I opened Arduino IDE after copying the code from tinker cad, and upload it to the Actual Ardunio after porting it with the USB.
11. The next step was to implement it using physical components and the Arduino UNO board to build it.
Demo for the Circuit Simulation
4- Assignment of the smart Circuit using an Arduino UNO
The main idea: I made the automatic complete mode of the circuit of my final project.
Concept: It begins with taking input motion signals from the distance between the users' workflows and the wall by using ultrasonic sensors. It will differ its opening angle according to the distance of the occupants. and The wall will emit different lights according to its opening angle states. The fully Closed state 0 for detecting no one in space with a far distance of more than 40 cm / the light will be purple then- semi-opened/closed state 45 for detecting a near body from the wall between 40 and 20 cm and the color will be cyan color Fully opened state 90 for detecting a very near body less than 20 cm with green color.
The technical components: the ultrasonic sensor and the slider switch is as input component, the output component: motion and light, the action components are done by using servo motor and RGB LED, The brain is the Ardunio UNO, power management: the breadboard will take the power from Ardunio UNO that is taken from the laptop by using USB.
Main components I used: Ardunio UNO, slider switch, ultrasonic sensor, Slider Switch RGB LED, and the Servo motor.
The Datasheets of each component are as follows:
Arduino Datasheet
From Datasheets>>>For RGB LED:
Required Blue color voltage= 3.2 V
Required Red color voltage= 2 V
Required Green color voltage= 3.2 V
For Servo motor:
Required voltage= 5V
Angles from 0 to 180 degrees.
For Ultrasonic sensor:
Required voltage= 5V
Current =15 mA max
Input of Arduino = 5Volt
5-3.4=40/100R
R= 230-320 Ohm ( for RGB LED resistors).
Steps of implementation on Tinker cad
I used the Tinker cad to simulate the circuit and building the coding of the Arduino Uno with the blocks code method.
First, I chose from the panel: the Ardunio Uno, mini breadboard, Slider Switch, Servo Motor, Ultrasonic sensor, RGB LED, and resistors of 220 ohms.
I supplied the 5 V power pin from Arduino to the + side of the Breadboard and the GRD to the -Ve side of the Breadboard respectively.
Then I settled the slider switch and connect the 2 terminals of it to the +ve and -ve sides of the breadboard. The common middle terminal to pin 2 of the Arduino.
5. i placed the RGB LED in the bread board and supplied the common cathode of it with the -Ve of the breadboard. Also for the anodes colors i crossed resistors of 220 ohms along them then to the Arduino digital pins as 9,10,11 respectively.
6. i connected the servo motor to the breadboard by supplying the power pin to the +ve and the GRD to the -Ve of the breadboard. And, the signal pin to the the Digital pin 3 on Arduino.
7.Then, i connected the ultrasonic sensor to the circuit. By supplying the power pin to the +ve and the GRD to the -Ve of the breadboard. And the Echo, trigger pins to pin 6 and 7 respectively.
Screen Shot of the Full Circuit
8. After conducting all the circuit in the view board, i began to building the coding of the Arduino using the blocks method in Tinker cad from the code panel.
9. i opened the Blocks code tab in the tinker cad, then I chose from the input panel <<Read the ultrasonic sensor on trigger pin 7, the echo on 6 in Cm>> to the workspace. i set the 2 variables in this code, one of the X that refers to the sensor read and the other for the distance measurement that I fixed to 40cm. it is shown as follows:
10. i made an IF, Else condition, the main order is to open the slider switch to let the other steps done. So i typed If Read on pin 2 is High (as opened) so make the following steps.
11. Then inside IF, Else condition, i wrote an IF condition to restrict the RGB color and the motor angle. this is done by adding the Distance order as follows:
12. After that, i chose the output pins 9,10,11 with High/LOW to make the light colors emitting from RGB LED. The full path can be illustrated as follows:
13. I simulated the code to check all things gonna alright, and it is working well
14. The next step was to implement it using physical components and the Arduino UNO board to build it.
Block Code _ Part one
Block Code _ Part two
Demo for the Circuit Simulation
First, I conducted the power by using MM jumper wires on one side along with the mini breadboard and the other on 5V of the Arduino. the same was done for the GRD side.
Then, I put the slider switch on the lower part of the breadboard.
3- i connected the slider switch terminals with the Arduino by supplying the power and GRD to the upper slots in breadboard and the common pin with the Digital pin 2.
4-i connected the Servo motor to the circuit, by adding the power and ground of the motor to the line of the upper slots in the breadboard. Also, the signal pin to the Digital pin 3 on Arduino.
5- Then i began to connect the Ultrasonic sensor to the breadboard by supplying the power and GRD to the upper slots in breadboard. And the Echo, trigger pins to pin 6 and 7 respectively.
6- i placed the RGB LED in the breadboard and supplied the common cathode of it with the -Ve of the breadboard. Also for the anodes colors i crossed resistors of 220 ohms along them then to the Arduino digital pins as red, blue, green 9,10,11 respectively.
7- Then, I opened Arduino IDE after copying the code from tinker cad, and upload it to the Actual Ardunio after porting it with the USB.
Snapshots of the Code in the Arduino IDE ( the Full File is in the Ass files section)
Demo for the Circuit implementation
State 1 (Near position with Green Light)
State 2 (Middle position with cyan color)
State 3 ( Far position with purple color)
Manual mode
Actually in the off-session exercise, i learned a new tip for setting the servo motor. we made a hand that is waving according to the distance settled between the user and the artificial hand. Randa who was my partner in the team had a suggession to settle the servo motor on the card board. this was to remove the bolt in its rotating element and reconnect it again. This works very well! Also for settling the hand over the servo motor my instructor told us a tip of fixing it by using the bolt.
i get a lot of ideas from it,, this helped me to be able to think about the placing of each part of the designed model. especially the sensor position.
Automatic Mode
The Circuit Built inside
Also, in the Midweek and Eoweek we reviewed our work through the week, i got some ideas from others in performing the circuits. such as in the equation of the ultrasonic distance with using IF Else instead of IF then. it is showed as follows:
IF- Else State
IF -Then state
While practicing the Midweek tutorials, i supplied the servo motor with the Arduino as videos. then, i began to wonder if i can add the potentiometer in this circuit too, in order to practise my final project manual idea. In order to control the angle of movement manually. Also, I used google search for helping me in understanding the way that will be done along the coding process. But i did not able to write the code on the tinker cad at first. Then I tried to transfer the code of Arduino to the blocks code.
Servo Motor + potentiometer With Arduino
Servo Motor With Arduino
2- Problem: In the Exercise of the LDR photosensor, After i made the code in Tinker cad, the RGB was continually on with no changing in the light. So i searched more about the concept behind the LDR sensor,, then i got to the reverse state between the resistor and the light in it,, how it takes the electrons from the light and this affect the resistance value,, so i recognized that the resistance needs to be a bit high to low down the electrons effect.
the solution was to add a resistor 220 ohm between the line of LDR sensor and the pin in the Arduino.
LDR without Resistor
LDR With using Resistor
3- Problem: In the Exercise of the ultrasonic sensor with RGB LED, After i made the code in Tinker cad, I used in the first state the ultrasonic PINg, all things go well. but in the implementation and after uploading the code to the Arduino>>> No thing is changing, the light is continuously on!! then I recognized that there is a pin in the ultrasonic of my Kit Is called ECHo pin,, it wasn't in the tinker block i chosed>> so i searched for another sensor block. and i found it.
the solution: there are 2 types of ultrasonic PING with no Echo and the HC SR04 with Echo pin, this type is more advanced than the first one. Ping has the transmitter and reciever in the same module but the HC SR04 has a seperate of transmitter (trig) and the receiver (ECHo).
The ultrasonic PING
The ultrasonic HC SR04
4- problem: in the off session hand Exercise, the ultrasonic sensor were receiving a continuous sensing action even if it is far from the fixed distance in the code. so, i checked its reading with the serial monitor output, i read that it reverses the numbers that must be read.
the solution: that I reversed the output of the equation and this works well.
State 1_ working
State 2- Not working
Programming the Arduino Board
Servo motor with a potentiometer
This will sure help me to transfer my project prototype to a smart one that could sensing and translating it into an interactive actions. by using the tinker cad simulation and Arduino IDE programming softwares and the different skills we learned through this week.
In the Assignment of this week, I succeeded to do the circuit of my final project by connecting the servo motor with the ultrasonic sensor and RGB LED.
Also, I practised my project manual mode of connecting the servo motor with the potentiometer.
the most coolest thing of this week that i could Simulate my final project circuits on Tinker cad and make sure it is functional and Build different circuits on a breadboard and test it.
Also, turning it into a prototype as in the Hand Wave Ex. that could perform actions. that was awesome!
Smart Circuit Ass. Output
Practicing the Tutorials through Tinker cad and real implementations.
I also watched some helpful videos about Ardunio uno and coding.
LED Fade light
Playing music by controlling a Buzzer with an Arduino board using Tinker Cad
Servo Motor Videos
Pizzo Buzzer with the Arduino
Motor Driver with Arduino
Pizzo Buzzer with the Arduino
LED Red Light with Arduino
Text Code by Tinker Cad
Blocks Code by Tinker Cad
practicing the Exercises