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.
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
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 .
Connect IN1 of relay board to D2 of NODEMCU
IN4 to D4, GND to GND.
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.
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.
Now let us develop our Android Mobile Application using on line MIT APP INVENTOR.
Click on Start a New project and provide a Project name. Space and Hyphen not alloed in name , but underscore allowed.
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.
From LAYOUT drag and drop a HORIZONTAL ARRANGEMENT
Set the Height under properties to 10 percent , Width TO FILL PARENT
This is to provide space at top of screen.
Then drag and drop LABEL from User Interface
Set Width TO FILL PARENT , Text to Heading of App. , alignment center ,Fontsize to 25
and background color to yellow.
Next drag and drop TABLE ARRANGEMENT from LAYOUT.
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.
Drag and drop an IMAGE component from User Interface.
Under Properties set the Height to 15 percent, Width to 30 percent.
Under Picture property click Upload File and select the image to upload.
Now drag and drop 2 buttons next to image 1.
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.
Select the properties of Buttons
You need to change the Text and the background COLOR.
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.
Now click on the BLOCKS button at the right top corner.
Select Button1 from the left side Blocks.
You will see a list of options.
Select the When..Do ..Button..Click block.
Next click on WEB .
Select the set..web1..url..to block
Third block to select is under TEXT
Select an empty Text block for text.
Finally from WEB
select call..web..get block.
Following are the blocks we selected.
Assemble the blocks as shown.Just drag and fix at the connecting points.
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.
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 :