Week 7

Ideation

Tell us about your assignment's idea for this week. Why do you care about this idea? What inspired you? (Please include images or links to sources of inspiration)

Smart Home

Our assignment this week was to 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).


I worked on the smart home concept where it can solve some problems like switching on a fan depending on the temperature/ humidity conditions, and turning on the lights when it's dark.

Tool Chain

Which software/machines/materials did you use in the assignment? Why?

Software:

  • Tinkercad to test the circuit wiring.

  • Arduino IDE to write and upload the code

Materials:

  • Arduino UNO

  • Temperature & Humidity Sensor (DHT11) Module.

  • 4pin Photoresistor, LDR Module.

  • Relay Module 5Vdc/12V/24V .

    • DC fan motor.

    • DC Lamp

  • Breadboard.

  • Jumper wires.

  • Slide switch.

  • Push buttons.

  • 9v power adapter.

  • 5v power adapter.


Arduino UNO
-

Relay Module

Temperature & Humidity Sensor

LDR Module.

Arduino IDE

Design/Preparation Process

Explain the design and/or preparation process of your assignment. How did you use the tool or software to design and/or prepare your assignment before fabrication/implementation?

I didn't use any tool or software at this step.

did some research for pin out of modules that you can check below

🌐 One Channel Relay Module (OUTPUT) 📤

🌐 LDR Module (INPUT)📥

🌐 DHT 11 Sensor (INPUT)📥


Then I wired it to the Arduino which you can check in the next section.

Getting Components Ready

LDR Module Pinout

Relay Module Pinout

DHT-11 Module Pinout

Development/Implementation Process

Explain the development/implementation process of your assignment. How did you use the machine/tool to manufacture or implement the design of your assignment?

Wiring:

  • Started by designating a positive rail coming from 9v power source and another positive rail coming from Arduino 5v pin. made sure not to mix them up so I won't fry any components :D.

  • I connected both ground rails on the bread board with a jumper so we have one GND channel in the whole circuit for it to work.

  • connected both relay modules to the power source, then connected a Dc Lamp to the 1st one and a DC Fan to the 2nd .

  • took a signal input pin out of each module and connected to Arduino digital pin.

  • connected both LDR and DHT sensors to Arduino digital pins 12 and 10 respectively.

Pxl 20220227 115400126.Mp4~2-1.mp4

Video Showing both Manual and Automatic Mode

wiring on circuito

Code:

  • Started by working on the manual mode which was pretty straight forward .

  • it reads if a button is pushed or not and depending on it powers up the selected component.

  • Then I started working on the Automatic Mode.

  • same concept but instead of button it reads a sensor and acts based on an if condition.

  • have a switch between the modes was done using an (if) condition encapsulating both modes. so if a switch is HIGH it'll start Auto mode and vice versa.

Manual Mode

int lamp = 3;

int fan = 4;

int b1 = 9; // button 1 for lamp

int b2 = 8; // button 2 for fan

int lampstat = 0; // read lamp on/off

int fanstat = 0; // read fan on/off


void setup() {

pinMode(lamp, OUTPUT);

pinMode(fan, OUTPUT);

pinMode(b1, INPUT_PULLUP);

pinMode(b2, INPUT_PULLUP);

Serial.begin(9600);


}


void loop() {

//read button state turn on lamp

if (digitalRead(b1) == LOW) {

if (lampstat == 0) {

digitalWrite(lamp, HIGH);

Serial.println("b1 press,Lamp ON");

lampstat = 1;

} else {

digitalWrite(lamp, LOW);

lampstat = 0;

Serial.println("b1 press,Lamp OFF");


}

delay(500);

}

if (digitalRead(b2) == LOW) {

if (fanstat == 0) {

digitalWrite(fan, HIGH);

Serial.println("b2 press, Fan ON");

fanstat = 1;

} else {

digitalWrite(fan, LOW);

fanstat = 0;

Serial.println("b2 press,Fan OFF");

}

delay(500);

}

}

Automatic Mode

#include "DHT.h"

#define DHTPIN 12 // Digital pin connected to the DHT sensor

#define DHTTYPE DHT11 // DHT 11

DHT dht(DHTPIN, DHTTYPE);


int lamp = 3;

int fan = 4;

int b1 = 9; // button 1 for lamp

int b2 = 8; // button 2 for fan

int lampstat = 0; // read lamp on/off

int fanstat = 0; // read fan on/off

int modeswitch = 0; // 0 for manual 1 for auto

int tempsns = 12; // dht11

int lightsns = 10; // ldr



void setup() {

pinMode(lamp, OUTPUT);

pinMode(fan, OUTPUT);

pinMode(b1, INPUT_PULLUP);

pinMode(b2, INPUT_PULLUP);

pinMode(tempsns, INPUT);

pinMode(lightsns, INPUT);


Serial.begin(9600);

dht.begin();


}


void loop() {

//Begin DHT Segment

float h = dht.readHumidity();

float t = dht.readTemperature();

float f = dht.readTemperature(true);

float hic = dht.computeHeatIndex(t, h, false);


delay(1000); // wait for measurment

Serial.print(F("Humidity: "));

Serial.print(h);

Serial.print(F("% Temperature: "));

Serial.print(t);

Serial.print(F("°C "));

Serial.println();


if (t >= 40 || h >= 80) {

digitalWrite(fan, HIGH);

Serial.println("Hot ,fan ON");

} else {

digitalWrite(fan, LOW);

Serial.println("cold ,fan OFF");

}

//Begin LDR Segment

if (digitalRead(lightsns) == HIGH) {

digitalWrite(lamp, HIGH);

Serial.println("Low Light,Lamp ON");

} else {

digitalWrite(lamp, LOW);

Serial.println("High Light,Lamp OFF");

}

}

Full Code with slide switch between modes

#include "DHT.h"

#define DHTPIN 12 // Digital pin connected to the DHT sensor

#define DHTTYPE DHT11 // DHT 11

DHT dht(DHTPIN, DHTTYPE);


int lamp = 3;

int fan = 4;

int b1 = 9; // button 1 for lamp

int b2 = 8; // button 2 for fan

int lampstat = 0; // read lamp on/off

int fanstat = 0; // read fan on/off

int modeswitch = 0; // 0 for manual 1 for auto

int tempsns = 12; // dht11

int lightsns = 10; // ldr

int switchA = 6;




void setup() {

pinMode(lamp, OUTPUT);

pinMode(fan, OUTPUT);

pinMode(b1, INPUT_PULLUP);

pinMode(b2, INPUT_PULLUP);

pinMode(tempsns, INPUT);

pinMode(lightsns, INPUT);


Serial.begin(9600);

dht.begin();


}


void loop() {


if (digitalRead(switchA) == HIGH) {

//Begin DHT Segment

float h = dht.readHumidity();

float t = dht.readTemperature();

float f = dht.readTemperature(true);

float hic = dht.computeHeatIndex(t, h, false);


delay(1000); // wait for measurment

Serial.print(F("Humidity: "));

Serial.print(h);

Serial.print(F("% Temperature: "));

Serial.print(t);

Serial.print(F("°C "));

Serial.println();


if (t >= 40 || h >= 80) {

digitalWrite(fan, HIGH);

Serial.println("Hot ,fan ON");

} else {

digitalWrite(fan, LOW);

Serial.println("cold ,fan OFF");

}

//Begin LDR Segment

if (digitalRead(lightsns) == HIGH) {

digitalWrite(lamp, HIGH);

Serial.println("Low Light,Lamp ON");

} else {

digitalWrite(lamp, LOW);

Serial.println("High Light,Lamp OFF");

}

} else {

if (digitalRead(b1) == LOW) {

if (lampstat == 0) {

digitalWrite(lamp, HIGH);

Serial.println("b1 press,Lamp ON");

lampstat = 1;

} else {

digitalWrite(lamp, LOW);

lampstat = 0;

Serial.println("b1 press,Lamp OFF");


}

delay(500);

}

if (digitalRead(b2) == LOW) {

if (fanstat == 0) {

digitalWrite(fan, HIGH);

Serial.println("b2 press, Fan ON");

fanstat = 1;

} else {

digitalWrite(fan, LOW);

fanstat = 0;

Serial.println("b2 press,Fan OFF");

}

delay(500);

}

}


}
































Cardboard Enclosure

Inshot 20220302 184229032-1.mp4

Community of Learning

Did you ask for feedback? What are the ideas that others have contributed or suggested? What was someone else’s idea that you built upon? How did you help your peers? How did your peers help you?

Asking for help on Slack

  • I had some problems with the button state to keep it on, But over slack I asked and Ahmed helped me figure it out.

Ahmed Reminded me of using a state inside an If condition to keep the Lamp/Fan On

Overcoming Challenges

When you got stuck, what/who did you turn to? At what point did you have to pause to research or learn more before moving on? What are some mistakes, pitfalls, or challenges that others can avoid if they were doing this assignment?

The only challenge were that during the offline session, my teammate had to leave due to being sick, so I didn't get a chance to apply the exercise, that's why I decided to make it my week's assignment after my supervisor permissions, Nada also provided me with a 2nd relay module so I would be able to do the assignment.

Final Project

How can you use the skills and knowledge that you've acquired this week in your final project?

I think I can use the acquired knowledge about power management and wiring different components in my final project.

WOW!

What is the coolest thing that you've learned this week? What is something that you will never forget from this week?

Take a minute or two to check this documentary, it's great.

Shock and Awe: The Story of Electricity -- Jim Al-Khalili BBC Horizon

Weekly Digest [OPTIONAL]

Tell us about any other cool things that you've made this week: in the Hands-on activity, tutorial examples, exercises, or any other cool mini-project that you tried out aside from the assignment.


Title of Media

Assignment Design Files