Project Idea:-
The Assignment idea(Smart Motor controller device, With LEDs (Green, Yellow, and Red )changes when an object comes at varying distances from an Ultrasonic sensor module.
To Control the movement of servomotors by two modes:-
Controlling by Potintometer
Controlling by ultrasonic sensor
I care about this idea: to know the basic principles of electrical circuits and electronics which will help me Creating simple Smart Devices that replicate specific functions or perform cool functions. and it's good to make an alarm device and simple piano.
I Searched on the Internet about smart Arduino Device Ideas, I Inspired by this Project:
https://www.youtube.com/watch?v=nia_w1AXFA8
I had thought that It will be better If I changed the idea by adding LEDs, both LEDs and Servo can be controlled by input from the movement of the potentiometer wiper or sensing from the Ultrasonic sensor
Components List For Project:-
I Used:-
Arduino Uno3 as a Micro Controller.
(ultrasonic sensor - potentiometer - switch bottom) as an Input Components
Servo Motor and RGB LEDs as Output Components
Resistors (220 Ohms) to set the current of the LEDs (Proppant Current)
Bread Board & Jumper Wires
I Used Tinkercad as the Software of Design and Simulate as Tinkercad has many features such as:
Tinkercad is very easy to use. Most of the 3d design software have steep learning curves.
It is compatible with 3d printing. It is a proper tool that gives you solid 3d files needed for 3d printing.
Tinkercad is fun to use. There are tones of 3d models created by the community. You could share your designs or even collaborate on designs.
Tinkercad can simulate all the electrical circuits with all the components.
Design Process of the Project:-
I searched on the internet about the Sample project circuits Ideas
I imagined the schematic diagram of the circuit in my mind, then I sketched it using paper and pen.
I searched about the datasheets of all the components to know the (operating voltage and current) and to know to connect the Components together with the Arduino.
I opened the Tinkercad
I dragged all the components that I will use into the Working Area.
I Connected the 5v of Arduino to + on Breadboard and the GRD to the -.
I Connected The LEDs with the Resistors to the Breadboard and to the Arduino as it is on the wiring diagram for components with the Arduino board.
I Connected The switch to the GND on the breadboard and Vcc with the Arduino.
I Connected The Ultrasonic Sensor as it is on the wiring diagram for components with the Arduino board. (VCC to +, GND to -, Trigger to 3 and Echo to 6)
I Connected The potentiometer to the GND on the breadboard and Vcc with the Arduino and Signal to A0.
I Connected TheServo Motor to the GND on the breadboard and Vcc with the Arduino. Signal to pin 5.
I Coding the Arduino MicroController to make the Function of the Device
After finishing. I simulated the circuit to make sure that all is ok.
The Coding sequence and Logic:-
Set the (Reading of Ultrasonic Distance Sensor) and potentiometer readings as the Input Data of the Device.
Define the Input Data
due to the mode, the servo motor will move
switch between (Potentiometer control mode & Ultrasonic sensor controlling mode ) by Switch buttom.
Fabrication Process:-
I Used the Simulated diagram for components with the Arduino board to make it.
I collected all the parts that I will use to make the circuit device.
I joined and assembled the parts of the design together to show the final design of the project on the breadboard.
After making sure that all the connections are ok such as the Simultaed device on the Tinkercad.
I Connect the Arduino to My PC
I Opened Arduino IDE
I Uploaded the Programming code to The Arduino Micro Controller.
Start powering
Here we have the device.
we supported each other to know how to deal with the Electronics and connections and use them, Moreover we helped each other with a lot of problems which occur during the connecting and design.
We supported and helped each other in The Coding Process and we search and find fritzing has all components needed and we can program and export schematic diagrams from it.
The instructors helped us on how to make the week Exercies Projects.
I had some problems with the internet connection and on Recording the Simulation from Pc Screen.
I had some problems with understanding how to connect the Sensors to the Arduino and The Coding Part , After research and (Try & Error) all became ok.
I learned how to:-
Understand Arduino Code structure and write Arduino C code syntax correctly
Create and Use Variables to store and manipulate different types of data in Arduino C
Use Interrupts to do multitasking in Arduino C
Understand how code blocks translate into Arduino C programming language
Use Looping (for & while) for repeating actions in Arduino C
After this week I learned how to design and program a smart device that performs a certain function or solve a problem: program Arduino UNO to read signals from multiple input components (Sensor, Switch, or variable resistor) to control multiple action components (Motor, Buzzer, LED...etc) using Arduino C Text Code.
The Coolest Thin that I have learned is Coding With IDE.
The Thing that I Will never Forget from this week is (LED Toggling Riddle and Smart home project )
The diagram for components with Arduino board
The Tex Code
The video recording of the complete project in action
The simulation on tinkercad
The code:-
#include <Servo.h>
int distance = 0;
int distance_range = 0 ;
int y = 0;
int x = 0;
int x_range = 0 ;
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);
}
Servo servo_5;
void setup() {
servo_5.attach(5, 500, 2500);
pinMode(8, OUTPUT);
pinMode(9, OUTPUT);
pinMode(10, OUTPUT);
pinMode(11, OUTPUT);
pinMode(12, OUTPUT);
pinMode(2, INPUT);
pinMode(A0, INPUT);
Serial.begin(9600);
}
void loop() {
distance = 0.01723 * readUltrasonicDistance(6, 3);
distance_range = map(distance, 0, 1023, 0, 180);
y = digitalRead(2) ;
if (y == HIGH ) {
distance = 0.01723 * readUltrasonicDistance(6, 3);
distance_range = map(distance, 0, 60, 0, 180);
servo_5.write(distance_range);
Serial.println(distance);
if (distance_range <= 45) {
digitalWrite (8, HIGH);
digitalWrite (9, LOW);
digitalWrite (10, LOW);
digitalWrite (11, LOW);
digitalWrite (12, LOW);
}
else if (distance_range <= 90 ) {
digitalWrite (8, HIGH);
digitalWrite (9, HIGH);
digitalWrite (10, LOW);
digitalWrite (11, LOW);
digitalWrite (12, LOW);
}
else if (distance_range <= 135 ) {
digitalWrite (8, HIGH);
digitalWrite (9, HIGH);
digitalWrite (10, HIGH);
digitalWrite (11, LOW);
digitalWrite (12, LOW);
}
}
else {
x = analogRead(A0);
x_range = map(x, 0, 1023, 0, 180);
servo_5.write(x_range);
Serial.println(x_range);
if (x_range <= 45) {
digitalWrite (8, HIGH);
digitalWrite (9, LOW);
digitalWrite (10, LOW);
digitalWrite (11, LOW);
digitalWrite (12, LOW);
}
else if (x_range <= 90 ) {
digitalWrite (8, HIGH);
digitalWrite (9, HIGH);
digitalWrite (10, LOW);
digitalWrite (11, LOW);
digitalWrite (12, LOW);
}
else if (x_range <= 120 ) {
digitalWrite (8, HIGH);
digitalWrite (9, HIGH);
digitalWrite (10, HIGH);
digitalWrite (11, LOW);
digitalWrite (12, LOW);
}
else if (x_range <= 135 ) {
digitalWrite (8, HIGH);
digitalWrite (9, HIGH);
digitalWrite (10, HIGH);
digitalWrite (11, HIGH);
digitalWrite (12, LOW);
}
else if (x_range <= 180 ) {
digitalWrite (8, HIGH);
digitalWrite (9, HIGH);
digitalWrite (10, HIGH);
digitalWrite (11, HIGH);
digitalWrite (12, HIGH);
}
}
}