Inspired by cubetto
I used tinkercad to simulate the circuit
I used
bread board
dc motor
5v adaptor
arduino
h bridge L -298N
SWITCH
2 led lamps
crocodile wires
ldr sensor
IR sensor
lCD
arduino ide soft ware
I started by simulating the circuit on tinker cad that at first, I connected the5V bin and the ground of the Arduino with the breadboard
then connected the Vcc and the ground of the sensors to the Arduino
also connected the dc motors and the power supply with l293d and connected the enable with bin and connected the inputs with pins and also connected it with the ground and the 5v of the Arduino
also connected the slide switch with the ground and 5v and bin 2 of the Arduino
also connected red led with the ground and bin 4 of the Arduino
Then I wrote the code on Arduino UNO to move to forward when I cover the LDR sensor and move to back when I cover the IR sensor and when I cover both sensors it will move to the front then to back
#include <LiquidCrystal_I2C.h>
LiquidCrystal_I2C lcd(0x27, 16, 2);
int LDR = 8;
int IR = 6;
int LED = 7;
int Switch = 9;
byte customChar[8] = {
0b00000,
0b00000,
0b10101,
0b01110,
0b11111,
0b01110,
0b10101,
0b00000
};
void setup() {
lcd.init();
lcd.backlight();
pinMode(LDR, INPUT);
pinMode(IR, INPUT);
pinMode(LED, OUTPUT);
pinMode(LDR, INPUT);
pinMode(2, OUTPUT);
pinMode(3, OUTPUT);
pinMode(4, OUTPUT);
pinMode(5, OUTPUT);
pinMode(10, OUTPUT);
pinMode(11, OUTPUT);
pinMode(Switch, INPUT);
lcd.createChar(0, customChar);
}
void loop() {
if (digitalRead(9) == HIGH) {
lcd.setCursor(2, 0);
lcd.write((byte)0);
lcd.setCursor(3, 0);
lcd.print("Open");
if (digitalRead(LDR) == HIGH && digitalRead(IR) == HIGH) {
lcd.clear();
lcd.setCursor(3, 0);
lcd.print("move forward");
analogWrite(10, 90);
digitalWrite(2, HIGH);
digitalWrite(3, LOW);
digitalWrite(LED, HIGH);
analogWrite(11, 180);
digitalWrite(4, HIGH);
digitalWrite(5, LOW);
delay(3000);
analogWrite(10, 0);
digitalWrite(2, LOW);
digitalWrite(3, LOW);
digitalWrite(LED, HIGH);
delay(1000);
digitalWrite(LED, LOW);
delay(1000);
analogWrite(11, 0);
digitalWrite(4, LOW);
digitalWrite(5, LOW);
delay(3000);
}
else if (digitalRead(LDR) == HIGH && digitalRead(IR) == LOW) {
lcd.clear();
lcd.setCursor(3, 0);
lcd.print("move forward");
analogWrite(10, 90);
digitalWrite(2, HIGH);
digitalWrite(3, LOW);
digitalWrite(LED, HIGH);
analogWrite(11, 180);
digitalWrite(4, HIGH);
digitalWrite(5, LOW);
delay(3000);
lcd.clear();
lcd.setCursor(3, 0);
lcd.print("move BACK");
analogWrite(10, 90);
digitalWrite(2, LOW);
digitalWrite(3, HIGH);
digitalWrite(LED, HIGH);
analogWrite(11, 180);
digitalWrite(4, LOW);
digitalWrite(5, HIGH);
delay(3000);
lcd.clear();
analogWrite(10, 0);
digitalWrite(2, LOW);
digitalWrite(3, LOW);
digitalWrite(LED, HIGH);
delay(1000);
digitalWrite(LED, LOW);
delay(1000);
analogWrite(11, 0);
digitalWrite(4, LOW);
digitalWrite(5, LOW);
delay(3000);
}
else if (digitalRead(IR) == LOW && digitalRead(LDR) == LOW) {
lcd.clear();
lcd.setCursor(3, 0);
lcd.print("move BACK");
analogWrite(10, 90);
digitalWrite(2, LOW);
digitalWrite(3, HIGH);
digitalWrite(LED, HIGH);
analogWrite(11, 180);
digitalWrite(4, LOW);
digitalWrite(5, HIGH);
delay(3000);
analogWrite(10, 0);
digitalWrite(2, LOW);
digitalWrite(3, LOW);
digitalWrite(LED, HIGH);
delay(1000);
digitalWrite(LED, LOW);
delay(1000);
analogWrite(11, 0);
digitalWrite(4, LOW);
digitalWrite(5, LOW);
delay(3000);
}1
else {
lcd.clear();
lcd.setCursor(2, 0);
lcd.write((byte)0);
lcd.setCursor(3, 0);
lcd.print("stop");
lcd.setCursor(2, 1);
lcd.write((byte)0);
lcd.setCursor(3, 1);
lcd.write((byte)0);
lcd.setCursor(4, 1);
lcd.write((byte)0);
lcd.setCursor(5, 1);
lcd.write((byte)0);
lcd.setCursor(6, 1);
lcd.write((byte)0);
lcd.setCursor(7, 1);
lcd.write((byte)0);
lcd.setCursor(8, 1);
lcd.write((byte)0);
lcd.setCursor(9, 1);
lcd.write((byte)0);
analogWrite(10, 0);
digitalWrite(2, LOW);
digitalWrite(3, LOW);
digitalWrite(LED, HIGH);
delay(1000);
digitalWrite(LED, LOW);
delay(1000);
analogWrite(11, 0);
digitalWrite(4, LOW);
digitalWrite(5, LOW);
}
}
else {
lcd.clear();
analogWrite(10, 0);
digitalWrite(2, LOW);
digitalWrite(3, LOW);
digitalWrite(LED, HIGH);
delay(1000);
digitalWrite(LED, LOW);
delay(1000);
analogWrite(11, 0);
digitalWrite(4, LOW);
digitalWrite(5, LOW);
}
}
the code didn't work and I couldn't figure out what the problem was so asked on slack and I found out that I wrote digitalWrite instead of digital read.
also, I had a lot of troubleshoots with the code and the instructor helped me to solve it.
we learned how to make a smart home simulation in the EO week session by using a DHT sensor
At first, the code didn't work so I rebuilt the circuit and rewrote the code several times until it worked well
also, the Arduino didn't work well I searched for the problem I found out that the switch was making a short circuit so the Arduino didn't work so I used a slide-switch instead of it to solve the problem
WOW now I can say that I can code the final project the I have imagination about how 70% of the code will be
MY Assignment
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
I made a Cooling system using DHT sensor with the help of my teammates
Arduino - Cooling System using DHT Sensor | Arduino Tutorial (arduinogetstarted.com)