Design and program a smart device that perform 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).
A transport vehicle carrying the components of the circuit
The described
This project aims to control the direction of the motor in the event of an error, meaning that the sensor if an object is found in front of it stops in forward mode and I cannot do any operation except to move the motor in the opposite direction by using the switch
From my electronics kit
1- breadboard
2- voltage source (9 & 12 volte from my own tools in home )
3- red and green LED
4- yellow DC Motor
5- jumper wires
6- on/off slid switch
7- push buttons
8- 220 ohm resistance
9. Arduino uno
10. h-bridge motor drive
11- RC car body frame
12- cardboard
13- zip ties
Arduino ide
wheels
video of the design
Step 1 :
I assemble all the components using Tinkercad to make sure of the connection method and I know the correct wire connection methods
From my electronics kit
1- breadboard
2- "voltage source (9 & 12 volte)"
3- red and green LED
4- yellow DC Motor
5- jumper wires
6- on/off switch
7- Arduino uno
8- 220 ohm resistance
9- ULTRASONICK SENSOR
10- motor drive
step 2 :
We use IF-condition for programming based on "C" language
int red led = 10;
int yellow led = 11;
int var = 0;
int if2 = 0;
long readUltrasonicDistance(int triggerPin, int echoPin)
{
pinMode(triggerPin, OUTPUT);
digitalWrite(triggerPin, LOW);
delayMicroseconds(2);
digitalWrite(triggerPin, HIGH);
delayMicroseconds(10);
digitalWrite(triggerPin, LOW);
pinMode(echoPin, INPUT);
return pulseIn(echoPin, HIGH);
}
void setup()
{
pinMode(3, INPUT);
Serial.begin(9600);
pinMode(11, OUTPUT);
pinMode(10, OUTPUT);
pinMode(9, OUTPUT);
pinMode(7, OUTPUT);
pinMode(8, OUTPUT);
}
void loop()
{
if (digitalRead(3) == HIGH) {
var = 0.01723 * readUltrasonicDistance(6, 5);
Serial.println(var);
if (var <= 20) {
digitalWrite(11, LOW);
digitalWrite(10, HIGH);
analogWrite(9, 90);
digitalWrite(7, LOW);
digitalWrite(8, LOW);
} else {
digitalWrite(9, HIGH);
digitalWrite(11, HIGH);
digitalWrite(10, LOW);
analogWrite(9, 90);
digitalWrite(7, HIGH);
digitalWrite(8, LOW);
}
} else {
digitalWrite(11, HIGH);
digitalWrite(10, HIGH);
analogWrite(9, 90);
digitalWrite(7, LOW);
digitalWrite(8, HIGH);
}
delay(10);
}
The code divided to 3 parts
1- the first part : Define the entries and their libraries
int red led = 10;
int yellow led = 11;
int var = 0;
int if2 = 0;
long readUltrasonicDistance(int triggerPin, int echoPin)
{
pinMode(triggerPin, OUTPUT);
digitalWrite(triggerPin, LOW);
delayMicroseconds(2);
digitalWrite(triggerPin, HIGH);
delayMicroseconds(10);
digitalWrite(triggerPin, LOW);
pinMode(echoPin, INPUT);
return pulseIn(echoPin, HIGH);
2- the 2nd part : Define the inputs and the outputs
the output like (led and motor drive )
the input like (ultrasonic and switch)
void setup()
{
pinMode(3, INPUT_PULLUP);
Serial.begin(9600);
pinMode(11, OUTPUT);
pinMode(10, OUTPUT);
pinMode(9, OUTPUT);
pinMode(7, OUTPUT);
pinMode(8, OUTPUT);
}
3- the 3rd part : code the main task by using the if condition in void loop
void loop()
{
if (digitalRead(3) == HIGH) {
var = 0.01723 * readUltrasonicDistance(6, 5);
Serial.println(var);
if (var <= 20) {
digitalWrite(11, LOW);
digitalWrite(10, HIGH);
analogWrite(9, 90);
digitalWrite(7, LOW);
digitalWrite(8, LOW);
} else {
digitalWrite(9, HIGH);
digitalWrite(11, HIGH);
digitalWrite(10, LOW);
analogWrite(9, 90);
digitalWrite(7, HIGH);
digitalWrite(8, LOW);
}
} else {
digitalWrite(11, HIGH);
digitalWrite(10, HIGH);
analogWrite(9, 90);
digitalWrite(7, LOW);
digitalWrite(8, HIGH);
}
delay(10);
}
describe of the design process
1- i used Tinkercad software to simulate the electric circuit components and make sure it work like my design and also help me to fix any problem easily
2- integrate all parts on components very easy and give my image about how it will be look in real
3- i used the push button in the circuit as loop cable replacement
step 1: wiring the circuit like in the tinker cad and start with h-bridge motor drive
step 2 : connect the motor drive to the Arduino and connect the ground from l298 drive with the of Arduino and supply and connect it to the yellow motor and powered the motor drive with 12v power supply
step 3 : wire the other outputs like ( led and motor ) and input like ultrasonic sensor and slid switch
1- connect the leds in series with the resistance and feed 5 volt from Arduino
2- connect the ultra sonic sensor the two terminals in the center 2&3 to give the signal and number 1&4 to feed the power
step 4 : integrate all parts with Arduino and upload the code to it from the Arduino IDE and use 9 volt supply with Arduino and 12 volt for the h-bridge motor drive
step 5 : test the code with all components
ultra sonic sensor for stop the motor if any body come in front of it by 20 cm
switch to switching the direction from forward and reverse
The smart device is functional and does its intended objective
step 6 : put all parts on the body frame of the car and install the Arduino on the top of bread board and the motor on the bottom of it by using zip ties .
In the case of forward the yellow led will light up and the motor are going to be work
until any body become front of the sensor by 20 cm the motor will stop and the yellow led also , and the red led will light up
in this case you will have only one choose , make it go reverse by switch the slide switch , it will go in the opposite way and the two leds will light up
Like every week of the week, Esraa cooperated with me and helped me solve the problems that I encountered. The problem this time is that the circuit was not working even though the code was correct, but the defect was in the connection of the motor dirve because the ground of the circuit was different from that of the motor and I should have singled them out .
i I discovered that the wires are too short, so they could not move the body easily, so I had to increase the length of the wires to allow me to move the mermaid
also i tried to put all components inside the body frame of this pickup truck but it didn't fit , i turn from being rear wheel base into a forward wheel base .
Also the wheels which i used was soo weak so i don't recommend it in any project , it broke easily and didn't rotted
also the white bread board was soo big to be fit on the body so i use the yellow small one
A transport vehicle carrying the components of the circuit
This project will benefit me because I have been trained to implement an idea from scratch and do it with the tools that I had in addition to learning how to connect electrical circuits and implement ideas. All these skills will help me in the final project
in this week i complete about 40% of the final project idea and i know from where i will start in the final project
Title of Media