This week's assignment idea was to build and Program a smart circuit using an Arduino UNO which reads a signal from 2 input component (Sensor, Switch, or variable resistor) to control an action 2 component (Motor, Buzzer, LED...etc) using Code Blocks.
The idea for the week was inspired by the traffic light and the fire alar
https://www.bing.com/videos/search?q=+the+fire+alarm&&view=detail&mid=3D48B021B94916E47D483D48B021B94916E47D48&&FORM=VRDGAR&ru=%2Fvideos%2Fsearch%3Fq%3D%2Bthe%2Bfire%2Balarm%26FORM%3DHDRSC3
"I was inspired by the circuit i made for week 6 assignment that included an ultrasonic sensor as an input and 2leds and a buzzer as output components gave 3 different actions according to different distances from the ultrasonic sensor and I wanted to modify this circuit to show a warning sentence on a LCD screen to cover all sides of warning and knew what ranges are NOT AIIOWED
component :
Arduino UNO
BREADBOARD
JUMPERS
2 REDLEDs
ULTRASONIC DISTANCE SENSOR
2 (220OHM) RESISTORS
LCD
SLIDER SWITCH
BUZZER
Ultrasonic Sensor:
Trigger--> on Arduino pin 11
Echo--> on Arduino pin 10
VCC terminal--> +5v
Ground terminal-->GND
led1
cathode terminal --> GND
Anode terminal --> 3
led2
cathode terminal --> GND
Anode terminal --> 4
SWIRCH
cathode terminal --> GND
Anode terminal --> 6
buzzer
ground to the (-) of the breadboard
positive to pin A0 of the arduino
Software:
"For Design the circuit "
i used tinkercade to but the circuit and make sure i don't fry more components
I used Arduino IDE to program the Arduino .
Material:
CARDBOARD.
TAPE
GLUE
RULERS
CUTTER
Wooden sticks
"TINKER CAD" Software:
TINKER CAD Software: (Design the circuit)
I have designed the circuit on tinker cad to see if is going to work or not
I brought my components and start to wire them
laid the breadboard
laid the arduino
powered the breadboard by wiring the (+) to the (5v) pin of the arduino and (-) to the ground of the arduino.
put the red LEDs
added the resistors and wired the first leg at the anode legs of the LEDs
wired the other leg to the pins (3,4) of the arduino.
added an ultrasonic sensor and wire it's
1-(vcc) to the (+) of the breadboard
2-ground to the (-) of the breadboard
3- echo to pin(10) of the arduino
4-tris to pin (11) of the arduino
Buzzer
ground to the (-) of the breadboard
positive to pin A0 of the arduino
Programing and Coding :
I used arduino ide
stared to build the code
wrote the void setup syntax for arduino input-output pins and lcd setup.....
#include <LiquidCrystal_I2C.h>
LiquidCrystal_I2C lcd(0x27, 16, 2);
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);
}
getting a digital signal from the slider switch make me use if condition the default one is to be shutted down and all pins are low..
void setup()
{
pinMode(6, INPUT);
pinMode(3, OUTPUT);
pinMode(4, OUTPUT);
pinMode(5, OUTPUT);
pinMode(10, OUTPUT);
pinMode(11, OUTPUT);
lcd.init();
lcd.backlight();
lcd.clear();
lcd.setCursor(4,0);
}
for else i wanted to make 2 conditions with 2 different distances so i used 2 (if condition) .
the input was 2 different distances (close-veryclose) so I choose for the first condition (CLOSE) is when the input of the 2 pins is =30cm--- the first led will be high, the others will be low and the buzzer is off as you can see and print " NOT ALLOWED " on the screen.
for the second condition (veryclose) is when the input of the 2 pins is ->20 --- the 2 leds will be high, the buzzer is on as you can see and print " STOP " on the screen.
void loop()
{
if (digitalRead(6)==LOW){
digitalWrite(4,LOW);
digitalWrite(3,LOW);
digitalWrite(5,LOW);
digitalWrite(10,LOW);
digitalWrite(11,LOW);
} else {
if (0.01723 * readUltrasonicDistance(10, 11) > 30) {
digitalWrite(3, HIGH);
digitalWrite(4, LOW);
analogWrite(5, 0);
lcd.setCursor(11,0) ;
lcd.print("NOT ALLOWED");
}
if (0.01723 * readUltrasonicDistance(10, 11) < 20) {
digitalWrite(4, HIGH);
analogWrite(5,150);
delay(1000);
analogWrite(5,50);
delay(1000);
analogWrite(5, 150);
lcd.clear();
lcd.setCursor(2,0) ;
lcd.print("STOP");
}
}
}
TINKER CAD Software: (simulation)
I used the small breadboard to make my project compact like a save
Cardboard
had some troubles with the circuit but finally it worked as it should.
I used the cardboard box to cramp all components and made some cuts and opening for power jack and led
This week I with FAREDA formed a team in Wednesday's lecture She helped me
with coding
MICHAEL helped me on cooding Help me a lot with the mistakes i have in the code.
I've had a lot of problems making the project curcit, and I've changed that over and over again until I get to the final solution.
I had a lot of problems this week cause I don't have an coding or programing background. So, first of all, i couldn't finish the exercises on my own i did make the electric circuit but didn't complete the code because i downloaded the wrong LCD library but i searched again for it again
Now I'm able to design a circuit with arduino for the final project.
during the week I was learning how to write Arduino codes an the process wasn't easy I had a lot of pugs but finally, the code worked and the project worked as I imagined and it was cool