Tag Archive: HOME AUTOMATION


For HOME AUTOMATION project we use a 4 channel Relay board of 5v Relays.

This is LOW enabled , a LOW at input makes the RELAY ON.

So on start up these input pins must be pulled HIGH.

NodeMCU is loaded with ESPEASY FIRMWARE . You can check this post on how to load.

The Relay board requires a separate power source of 5 volt.

The GND of 5v supply to be made common with the GND of Nodemcu.

RELAY BOARD   NODEMCU

IN1     ——- GPIO 16

IN2     ——- GPIO 14

IN3    ——- GPIO 12

IN4    ——- GPIO 13

 

 

hat

 

DOMOTICZ Service is running on Raspberry PI which is on the same LAN as my PC.

The Domoticz server is accessed by typing in the RPI’s IP address followed by port no. 8080

192.168.0.150:8080

Click on Setup – > Hardware and create Type DUMMY for Relay 1 , name it as RL1.Click ADD

Same way create 3 more Type Dummy for other 3 Relays RL2, RL3 & RL4.

Image 10

 

 

Image 12

On top a list of Types created is displayed.

 

Image 8

Click on Create Virtual Sensor for RL1.

Image 15

Select Sensor type as SWITCH and name it as RL1.

Image 13

Similarly create Sensor type Switches for other 3 ,  RL2,RL3 & RL4

Image 14

Under setup –> Devices all the 4 switches are listed out with INDEX (IDX) numbers.

Note these IDX numbers , as we have to set the same IDX number in ESPEASY Setup.

Image 9

Under SWITCHES tab you can see the VIRTUAL SWITCHES created.

Image 3

Click on EDIT button on RL1

Switch ICON is a bulb by default.You can select any one from the drop down list.

Under ON Action feed in the IP address of ESPEASY with HTTP command

http//192.168.0.110/control?cmd=gpio,16,0

Note the usage of 0 for ON , as the relay board is LOW enabled.

Against OFF action

http://192.168.0.110/command?cmd=gpio,16,1

Click SAVE

Image 4

Same way click on other Relay switches EDIT button and feed in the HTTP command including the correct GPIO number.

 

Image 5

 

Image 6

 

 

Image 7

Once the HTTP commands are saved , you can go to ESPEASY Dashboard by typing in the IP address on browser.

Here mine is 192.168.0.110

 

Under CONTROLLERS select the protocol as DOMOTICZ HTTP

Provide the IP address of DOMOTICZ and its port no. 8080

Click ENABLED.

Image 7

 

Under HARDWARE make the GPIO pins used to OUTPUT HIGH on Boot.

As the RELAY Board is LOW enabled , this is necessary.

GPIO16 by default is HIGH on Boot , so there is no settings for GPIO 16.

Image 8

 

Under DEVICES select the DEVICE as SWITCH INPUT – SWITCH

Provide a name RL1

Click ENABLED.

RL1 is connected to GPIO 16 , select it.

Provide the IDX number as 1.

Internal pull up is similar to OUTPUT HIGH , not needed for GPIO 16.

Image 2

 

As done for RL1 repeat for other relays

RL2 –GPIO14 , iNTERNAL PULL UP –Yes, IDX 2

Image 3

 

Image 4

RL3 –GPIO12 , iNTERNAL PULL UP –Yes, IDX 3

Image 5

RL2 –GPIO13 , iNTERNAL PULL UP –Yes, IDX 4

Image 6

 

Now all the settings are done.

Image 1

Go to DOMOTICZ Dashboard and click on SWITCHES tab.

From here you can Switch ON OFF the relays and the load connected to it.

 

Image 11

VIDEO :

 

blog_image

 

 

 

title_iot2

This post is on Home Automation project where we control 2 devices from a mobile App. over Local Area Network.

NodeMCU with Arduino core installed is used with relay board.

You can watch this video on how to install Arduino core on NodeMCU.

https://www.youtube.com/watch?v=BbiLBiFvlsI

Android Mobile Application is developed using MIT APP INVENTOR , a WEB Application IDE.

https://appinventor.mit.edu/

For Arduino code we will use the one from my previous post

https://alselectro.wordpress.com/2017/11/08/nodemcu-arduino-core-2-led-on-off-from-webbrowser/

Download code for web browser LED On/Off HERE

This code is to control an LED from a Web browser on LAN.

We shall modify the code to work for Home Automation.

Arduino Code , Android App. (both .aia , .apk) files can be downloaded HERE

To start with connect a Red LED at D2 (which will be replaced with a DC Fan load)

A green LED at D4  ( will be replaced with CFL lamp AC Load)

 

I41

——————————————

#include <ESP8266WiFi.h>
#define FAN D2
#define LIGHT D4
const char* ssid = “Saravana”;
const char* password = “######”;

WiFiServer server(80);

void setup() {
Serial.begin(115200);
pinMode(FAN, OUTPUT);
pinMode(LIGHT, OUTPUT);
digitalWrite(FAN,HIGH);
digitalWrite(LIGHT,HIGH);

Serial.println();
Serial.println();
Serial.print(“Connecting to “);
Serial.println(ssid);
WiFi.begin(ssid, password);
while (WiFi.status() != WL_CONNECTED)
{
delay(500);
Serial.print(“.”);
}
Serial.println(“”);
Serial.println(“WiFi connected”);
server.begin();
Serial.println(“Server started”);
Serial.println(WiFi.localIP());
}

void loop() {
WiFiClient client = server.available();
if (!client) {
return;
}

Serial.println(“new client”);
while(!client.available())
{
delay(1);
}
String req = client.readStringUntil(‘\r’);
Serial.println(req);
client.flush();

if (req.indexOf(“/fanon”) != -1)
{

digitalWrite(FAN,LOW);
Serial.println(“FAN ON”);
}
else if(req.indexOf(“/fanoff”) != -1)
{
digitalWrite(FAN,HIGH);
Serial.println(“FAN OFF”);
}

if (req.indexOf(“/lighton”) != -1)
{
digitalWrite(LIGHT,LOW);
Serial.println(“LIGHT ON”);
}
else if(req.indexOf(“/lightoff”) != -1)
{
digitalWrite(LIGHT,HIGH);
Serial.println(“LIGHT OFF”);
}
String web = “HTTP/1.1 200 OK\r\nContent-Type: text/html\r\n\r\n”;

client.print(web);
}

————————————————-

upload the above code and open the serial monitor to note the IP address allotted to NodeMCU.

Note that all devices NODEMCU ,PC & mobile are connected to same Router.

The IP address allotted is DYNAMIC ,meaning , it may change on next power up.

To make it STATIC , you can set Address Reservation setting under Routers settings.

l3

Once the IP is allotted , open up the WEB browser and type in IP/fanon

for e.g  192.168.1.107/fanon

Initially both the LEDs will be ON .As we will use a LOW enabled input Relay board, these LEDs are made ON indicating the devices are OFF initially.

On sending the string fanon from browser , the RED LED will go OFF.

On sending 192.168.1.107/lightoff , the Green LED will go off.

Similarly  fanoff string will make Red LED ON , lightoff string will make Green LED ON.

 

Now the code is working perfectly, we shall replace the LEDs with actual devices to be controlled.

A 4 channel 5 volt Relay module is used to connect the actual devices .We use a DC FAN 5v at relay contact 1 and a CFL bulb AC at RELAY 4

 

I42

For power source a MB102 PSU board is used on MB102 Bread board.This board can be easily plugged on to MB102 Breadboard and has jumpers.One jumper (top)  is set to  5v and the bottom jumper set to 3.3v.

An external adapter of 9v 1amp is used .

I43

Connect IN1 of relay board to D2 of NODEMCU

IN4 to D4,  GND to GND.

I40

While connecting Load to relay board, always connect the power to load at POLE.

Actual Load is connected to NO Normally Open pin of relay contact.

While handling AC loads, take precaution to insulate relay board within a plastic box and do not touch the relay board.

It is safer to connect Neutral to POLE and AC Phase to other end of Load.

I45

Also remove the jumper on relay board.

Connect 3.3v to Vcc and 5v to JD-Vcc

This enables error free operation , as the NODEMCU is a 3.3v device.

jdvcc

 

Now let us develop our Android Mobile Application using on line MIT APP INVENTOR.

 

Image 3

Click on Start a New project and provide a Project name. Space and Hyphen not alloed in name , but underscore allowed.

 

Image 5

You will be presented with development screen which has 4 columns.

1st Column is Palette with all User Interfaces and components to build the App.

2nd Column is the actual Screen viewer.

3rd Column displays all the selected Components.

4th Column shows the Properties of the selected Components.

Image 6

From LAYOUT drag and drop a HORIZONTAL ARRANGEMENT

Image 7

Set the Height under properties to 10 percent , Width TO FILL PARENT

This is to provide space at top of screen.

Image 8

Then drag and drop LABEL from User Interface

Image 9

Set Width TO FILL PARENT , Text to Heading of App. , alignment center ,Fontsize to 25

and background color to yellow.

Image 10

Next drag and drop  TABLE ARRANGEMENT from LAYOUT.

Image 11

Set properties , COLUMNS to 3 and ROWS to 2,  Width to FILL PARENT, Height to Automatic.

2 Rows required for 2 device control.

3 columns  for image , on button and off button.

 

Image 12

Drag and drop an IMAGE component from User Interface.

Image 13

Under Properties set the Height to 15 percent, Width to 30 percent.

Under Picture property click Upload File and select the image to upload.

Image 14

 

Image 15

Now drag and drop 2 buttons next to image 1.

Image 16

Drag and drop another IMAGE component, below the first imge.

Set properties accordingly and upload the second image.

Drag and drop 2 more buttons as shown below.

 

Image 18

Select the properties of Buttons

You need to change the Text and the background COLOR.

Image 19

Next drag and drop a WEB component from CONNECTIVITY.

As this one is a Non Visible component , it will show up at the bottom of the screen.

Image 22

Now click on the BLOCKS button at the right top corner.

Image 23

Select Button1 from the left side Blocks.

You will see a list of options.

Select the When..Do ..Button..Click block.

Image 24

Next click on WEB .

Select the set..web1..url..to block

Image 25

Third block to select is under TEXT

Select an empty Text block for text.

Image 26

Finally from WEB

select  call..web..get   block.

Image 27

Following are the blocks we selected.

Image 28

Assemble the blocks as shown.Just drag and fix at the connecting points.

Image 29

Click on Text block and type in

http://192.168.1.5/fanon

Your IP may be different.Change the IP according to the one shown at serial monitor of

Arduino, after uploading code.

Image 30

The first block is ready.

Right click and select DUPLICATE.

 

Image 31

Change the Text for other blocks as shown.

Image 32

Now click on BUILD App TO SAVE .apk file to computer.

You can transfer this .apk file to mobile using SHAREIT or any application.

Image 34

Also you can export the .aia file.

.apk file is for Android mobile.

.aia file is the one you can import on your MIT APP and do the necessary modifications

and then finally generate your own .apk file.

Also you can install MIT AI2 Companion on mobile to view Real Time development.

By this application you can view the real time changes on mobile , as you develop

appplication on MIT APP Inventor.

Image 36

Now open the Application on mobile.

Touch on the buttons to see the project working.

IMG_20191219_132341

VIDEO TUTORIAL

 

 

blog_image

 

Image 2

 

Image 1

 

Introducing a new ESP8266 Development Board with an ESP-12, a 3x AA battery holder, a voltage regulator, an RGB LED, several red LEDs, and a light sensor LDR on the ADC input all on one board.

The board can be controlled by an open source Android App which is available from the AI-THINKER Website.

GPIO pins are extended with berg pins for easy external connections. RXD,TXD & GND pins are provided for programming / firmware upgrading. A yellow jumper is provided to pull GPIO0 pin to GND during programming. During normal operation this jumper must be removed.

The board is powered by 3 nos AA batteries , for which a battery box is already wired. On board 3.3v regulator is provided for a stable power supply.

No power switch or Reset switch is provided. To switch off you need to pull out one of the batteries.

The board comes pre-loaded with a demo which does actually seem to work.  If you have an Android based phone or tablet you can download AI-Thinker’s app to control and mix the color balance on the RGB LED and to switch the other LEDs on and off.

The Android Application can be downloaded from :

https://play.google.com/store/apps/details?id=com.duvallsoftware.iotdemoapp

 

There are also 6 red LEDs fixed with the necessary resistors connected to GPIO16, GPIO14, GPIO5, GPIO4, GPIO0 and GPIO2. A BLUE LED is always ON if the board is powered.

The GPIO13, GPIO12 and GPIO15 are connected to a RGB LED which allows you color mixing using PWM.

ADC

The analog-digital converter is also available on a pin & connected to a light resistor. This lets you quickly test the ADC and you still can clip the resistor off if you want to measure another analog source.Remember the range of ADC is max 1v & not 0 to 3.3v

If you don’t want to use the light sensor or the LEDs you can simply clip them off. Then you’ll just have an  ESP8266 with 3xAA power supply, 9 available GPIO pins and one ADC.

On the playstore of your Android device search for  IOT DEMO App & install it.

Open the Settings & enable WIFI of the Android phone.Now power on the ESP board to see the AI-THINKER SSID on your mobile.

PAIR this with the ESP board using password ai-thinker

Now open the app & touch on LED 1 to 6 , to see the corresponding light glowing on the ESP board.On the top you can see 3 icons with sliders in the App. Use this to mix colors on the 3 color LED of ESP board.

Once the functioning of board is verified , you can proceed to connect the GPIO pins of ESP board with a 4 channel Relay board.

The 4 channel relay board used requires a separate power source of 5V, 1amp.For demo 2 of the GPIO pins are connected to relay 1 & relay 3.The GND pins of both ESP & the Relay. board to be made common.

You can watch this video to learn the home automation basics with ESP board :

 

 

 

cooltext753793315    cooltext753790696