In the last few years I was fascinated by the smart or automated switches, imagine that you can control any electric device using your mobile without even standingup from your comfy bed or sofa, and now I had a chance to make one of these switches so I do my research and find out that there's a company that calls sonoff that make this switches and start to implement it at once
fritzing to make the circuit before doing it
Arduino ide to build and upload code to the board
Arduino bluecontrol app to control the Arduino through sending to the serial
Small breadboard to connect all components solderless
Some jumpers
Resistor to adjust the voltage and current (3*1k to Bluetooth rxd)
1 channel relay module rm1v
Arduino UNO r3 to control all the components with code
piezo buzzer
16*2 lcd with I2C module
start to connect the relay with the Arduino power and signal pin
then a little piezo to let me know that the command is taken by a little peep sound
then connect a 220v ac power and a lamp (connect one lamp line to the NO or the normally open and the other direct to the ac , doesn't matter the gnd or vcc cause it's ac)
then connect a LCD to welcome me back and make it even cooler 😎
and at last connect an hc-05 Bluetooth module to connect the lamp state through my mobile
First I included the liquid crystal library to control the LCD , then defined the lamp pin to control the relay state and the piezo pin , and define a character variable to put the incoming data in it
then give a pin mode to each of the pins (output or input)
in the void loop I identify the incoming data to read the serial every time I send something to it.
and make an if condition, if I send number 1 the piezo make a peep and the LCD show a welcome message and turn the lamp on
and if I send number 2 the piezo make a longer peep and the LCD show bye bye message and turn the lamp off
First I want to know how to connect the relay to the Arduino so I do my research and find out that the VIN mean the 5v that comes from Arduino, the GND also come from Arduino power , and the IN terminal is the signal that come from the digital pin in the controlling pins from Arduino.
and then connect the 220v ac to the other side of the relay
the 220v have 2 lines L & N (various in other countries) grab and of the lines it doesn't matter I prefer the L put it does't matter cause it's AC and but it in the gnd and take it from the normally open terminal to the lamp
and the other line from the ac connect directly to the lamp just like a switch
the HC-05 is a little tricky so i grab this diagram to make it easy
the VCC and GND is it's power so it's obvious that it goes to the Arduino power
then the Tx goes to Rx in Arduino
the Bluetooth Rx is a little confusing here , it takes 3.3v so we take it and connect it to 2k and 1k resistors, the 2k side goes to ground and the 1k goes to the Arduino Tx
then connect the LCD with i2c like above diagram
and VOLAA all the components are together
I think that my relay was broken😅, until I discovered that I have to make the jumper at 5v cause I powered it through Arduino and I know this from it's datasheet here
BEWARE that I used a 220v AC and it's a high voltage and it can give you an electric shock like it gives me, so put a tape or something to covers the terminals and always beware
all is done and now I can use my mobile to control any thing that uses 220v AC , a lamp, fan and a lot of other electric devices (maximum 10A)