This week, we have to use Arduino to control 2 different input components and 2 output components with enclosure. Depending on my last experience and to improve the last project of week 6, I imagined that I can add some cool features and control the new components by coding as we learned this week. The project that I'd like to have is a smart device that transforms any device in our homes into a smart device that can be easily controlled using the IR sensor. I planned to include a buzzer into it to alert the user when he opens or closes it. Also, I will add a yellow led to turn on when the device is opened and turn off when the device is closed.
Components
The medium size to be suitable for the enclosure.
For the arduino.
To control the project (relay, bluetooth,...etc)
Arduino can't control more than 12v device, but by the relay we can control any DC device which need 220v or 110v.
To control the project through waving our hand or by using the remote control.
An example for 220v device which the project can control.
To supply the lamp with the power.
To supply the lamp with the power.
To connect the components all together.
To connect the switch with the vcc and gnd.
To turn on and off the whole project.
To make an alarm when the user open the device or close it.
Materials
To build the enclosure.
Software
To design the circuit and test it on it.
To code Arduino to do the functions of the project.
To upload the code on it to be open source.
To find answers to my questions during the work.
Input components: IR and switch.
Output components: Relay, bulb, buzzer, led.
Relay (OUTPUT): terminal 1 to the negative in the power supply, terminal 5 to pin 6 in Arduino, terminal 7 to terminal 1 in the bulb, and terminal 8 to gnd.
IR (INPUT): on pin 7 in Arduino, vcc to 5v pin in arduino, gnd to gnd.
Buzzer: vcc to pin 5 in Arduino, gnd to gnd.
Led: Anode to the resistor, from the resistor to pin 4 in Arduino, cathode to gnd.
220 ohm Resistor: to let the led open without damage.
Bulb: terminal 1 to terminal 7 in the relay, and terminal 2 to positive in the power supply.
ON/OFF switch: connecting terminal 1 to pin 3, common to gnd, and terminal 2 to 5v.
First, I defined 6 vars {
Relay: connected to pin 6;
IR: connected to pin 7;
Buzzer: connected to pin 5;
Led: connected to pin 4;
Switch: connected to pin 3;
Counter: to use it in the loop;
}
Second, I setup 5 things:
The serial communication to connect between the Arduino and the Bluetooth and the android phone. The speed is 9600.
I defined the relay, buzzer, and led as OUTPUT components.
I defined the IR and the on/off switch as INPUT components.
The first part in the loop 'while' turning on the device:
First, I used "if" to open the circuit when the switch is opened, then in "else" I wrote the code of the other input components and highlight all the conditions.
Second, I let the arduino to get the signal of the IR, then to "Read" it.
"If" the value of the IR is (0) the buzzer will do a sound for 250 m.sec and close. The led and the relay will turn on which will let the connected device to the project (the bulb) turns on.
I used the counter to 'stat' the value like it is without changing after the user passes his hand around the IR,
Then I ordered arduino to print "on" when it gets (0) value.
The second part in the loop is rest of 'if' condition which is 'else':
If the user do another action, like passing his hand again around the IR, I ordered the arduino to let the buzzer do a double sound and close. The led and the relay will turn off which will let the connected device to the project (the bulb) turns off.
I used the counter again to 'stat' the new value like it is without changing it after the user passes his hand around the IR,
Then I ordered arduino to print "off".
Connecting the 5v pin and the gnd to the breadboard
Connecting the 2 wires to the bareeza
Connecting the power cable to the bareeza
Relay Wiring ..
Connecting the power cable to NO and CM ports
Connecting the relay to the Arduino by jumper wires: Vin to 5v pin, gnd in the relay to the gnd in arduino, and in to pin 6
Total view to relay wiring
Connecting the ir to the arduino: vcc to 5v pin, gnd in the ir to the gnd pin in the arduino, and out to pin 7
Over view to the circuit
Connecting on/off switch to breadboard using the crocodile wires and jumper wires
Adding the buzzer to the circuit: anode to pin 5 and cathode to gnd in the arduino
Adding the led to the circuit by using the resistor to the breadboard and male/female jumper wires
Connecting the anode to pin 4 through the resistor and cathode to gnd
led: pin 4, buzzer: pin 5, relay: pin 6, ir sensor: pin 7
Cardboarding
preparing the cardboard for the project
All the components and tools used in the project
mountain the components to the bottom of the design
A closer look to stabilizing the Arduino
Arduino ports: power and USB
wiring and top view for the project
A view of the on/off switch and a hole of the 220v power cable
The first input (On/Off Switch)
The second input (IR sensor)
After adding the code of the led and while I was checking the circuit, the led didn't turn on and the buzzer did a long sound without closing it while I coded that the buzzer should close after 250m.sec. I checked stack overflow, but I found nothing to help me.
I checked the wiring by Avometer and everything were working perfectly. I double checked the code and I found that I forgot to set the led as OUTPUT in void setup, so the code of the led worked for the buzzer and this was the reason of the non stopping sound that happened from the buzzer. I setup the led as OUTPUT and the issue was fixed and the code ran well.
As we learned to code this week, I became able to code different components at the same time and be able to make a smart circuit. code-blocks are great but the coding is greater XD