Latest Entries »



ESP32 is a powerful device for IOT development with WIFI & Bluetooth.Compared to NodeMCU it has more ADC pins , DAC & much more.

ESP32 can be programmed by many ways including Arduino core.

This post is on programming ESP32 using MICROPYTHON.

MicroPython is a lean and fast implementation of the Python 3 programming language that is optimised to run on a microcontroller.

MicroPython has advantages over traditional programming software such as C/C++ because it is essentially a live development environment and you write and debug code much faster…in fact 5-10 times faster than C++.

when a device boots up using MicroPython it does not consume much memory and thus doesn’t incur current drain.Micropython also has a number of Micropython specific libraries for accessing hardware level features.

Adafruit also introduced  CircuitPython ,Soon after MicroPython started picking up the pace. However,  CircuitPython offers support for the Adafruit range of hardware only.

Python allows for rapid feedback. This is because you can interactively enter commands and get a response using the  REPL –read–eval–print loop. You could even tweak your code and run it right away, rather than iterating through code-compile-upload-execute cycles.


This post is on implementing MICROPYTHON on ESP32.



As a programming environment , many IDE s are available , of which THONNY IDE is simple & powerful.

Thonny IDE : An integrated development environment (IDE– Integrated Development Environment) for Python that is designed for beginners. It stands out for its simplicity of installation and use, ease of writing and debugging of code, possibility of incorporating plugins and its good documentation.

uPyCraft IDE : It is anIDE specifically oriented for MicroPython, which makes it one of the besteditorsfor this use. It allows you to upload the MicroPython firmware to the microcontroller in a very simple way (as an alternative

Visual Studio Code (VSCode) , using the PyMakr extension: It is avery sophisticatedIDE , which supports many practical functionalities working with code, but is only recommended for advanced users

PYCHARM is for advanced users.There is community edition for free.There’s a PyCharm plugin that adds MicroPython support to your IDE. It’s available right in the plugin marketplace

visit  & download the installer relevant for you (available for Windows,Mac & Linux)

Image 4

Install THONNY IDE by double clicking the downloaded installer.

Image 5


Image 6


The top portion is the EDITOR where you write your Micropython code.

Bottom is the SHELL.

As we’ve not yet installed Micropython interpreter, the Shell displays the default Python prompt.

‘>>>’ is the prompt of the interactive Python interpreter, meaning that the interpreter is ready to get Python statements typed in.



Image 7

To get the Micropython prompt, click on Tools –> Options

Image 8

Under options window click on INTERPRETER.

Image 9

Under first drop down menu select MICROPYTHON (ESP32)

Under Port , select the port number where ESP32 is connected.

Click on Firmware install bar.

Image 10r

Micropython firmware .bin file can be downloaded from

Under ESP32 select the GENERIC .bin file & download it.

Now , from the Thonny install firmware window , click browse and locate the downloaded .bin file.


Image 13

Click on install button to start the firmware installation.

You need to press & hold the BOOT button on ESP32 module for a moment.

Image 14

You may get an error stating ESPTOOL is not installed.

From within Thonny IDE itself you can install it.

Click Tools  –>  Manage Plug ins..

Image 11

Under plug in window search for esptool & install it.

Image 12

Now if you install firmware , you can see the writing starts at location 0x1000

Image 15


Image 16

Once the firmware is installed you can see the Micropython prompt under SHELL.

Image 17

You can type in help() to see a list of python commands to access modules ,network, etc..

Image 18


displays the list of modules available.

Image 19

machine, uos, esp , time , network are some of the frequently used modules.

Image 20


To control GPIO pins you need to import machine module.

the  machine module of MicroPython, which is the  “library”  of functions and  classes , to control the hardware of the microcontroller.

The machine module  has 12 functions and 12 classes :

  • Functions : reset (), reset_cause (), enable_irq (), disable_irq (), freq (), idle (), time_pulse_us (), sleep (), lightsleep (), deepsleep (), wake_reason () and unique_id ().
  • Classes : Timer (), WDT (), Pin () , Signal (), TouchPad (), ADC (), DAC (), I2C (), PWM (), RTC (), SPI () and UART () ) .

We can see this listing in Thonny using the function help(machine).

Image 1

To control an LED on / off, the following must be done:

  • First, the Pin class of the machine module is imported , which allows controlling the inputs / outputs (General Purpose Input / Output – GPIO -) of the microcontroller – and therefore, of its corresponding pins on the board. Since pin 02 ( GPIO 02 ) is connected to the integrated LED, you also have control over it.
  • Then an object that we will call pin_02 is  initialized to identify it, turning GPIO 02 “2” into an output pinPin.OUT ”.

Among the classes of the module, the class


is used to create objects to control inputs / outputs of the microcontroller ( GPIO ), which will help us to turn on /off the LED.

Additionally, if we ask for information about the class Pin() we can see that it has 5 methods – Pin.init (), Pin.value (), (), Pin.on () and Pin.irq () – :


In order to use this class , we need to know how your constructor  and its methods work .

The constructor is the subroutine whose mission is to initialize the object . The constructor of the Pin class is:

class machine.Pin (id, mode, pull, *, alt)

The arguments of the constructor are:

The arguments to turn on the blue LED integrated in the ESP32 DEVKIT  board  will be the following:

  • id 2 ” since the on board LED is connected with pin 02 ( GPIO 02 ).
  • mode Pin.OUT ” to make pin 02 become a voltage output pin .
  • pull None ” to not configure pull-up or pull-down resistors (they are only useful in the case of being an input pin Pin.IN -). It is not necessary to define this argument.
  • value 1 ” to turn on the LED-3.3V voltage output.

Once the code has been executed, we will have initialized an object , which has been assigned the name pin_02 , whose initial values convert pin 2 (GPIO 02) into an output pin and its status is on (3.3V voltage) .

The methods that we can use once the object is created  allow us to manipulate (modify) its functionalities . In the Pin class we have the following:

  • Pin.init () : Modify theinitial arguments of the constructor . You can modify the mode , pull , * (value) and alt argumentswhen new values ​​are defined.
  • Pin.value () : allows you to read the presence / absence of input voltage of the pin (without an argument is provided) or set an output voltage on the pin providing the argument. The arguments can be “ 0 ” off (0.0V) and “ 1 ” on (3.3V). Booleans can be usedas arguments.
  • () : Sets a pin output voltage of 0.0V- off.
  • Pin.on () : sets an output voltage of the 3.3V pin – on -.
  • Pin.irq () : enables external interruptions in the pin , as long as it is an input pin .

Put together

First from machine module import the class Pin.

Then assign the built in LED GPIO pin 2 & declare it as Pin.OUT

The pin that is connected to the led is instantiated & the second argument is set as OUT ,indicating

that the pin acts as OUTPUT.

tImage 21

Now  led.value(1) makes the on board LED ON.

led.value ( 0) makes it OFF.

We have controlled the LED from Interpreter. Now we shall write the complete code in the EDITOR Section to blink the LED repeatedly.

Here we make use of the sleep class of time function to introduce delay.

Never ending loop is created using

while True:

Notice the loop starts by  colon :  & instead of braces micropython uses indentation.


Image 22

Click File  –>  Save as

& select Micropython device


Image 23

Provide the file name as

You can notice , by default already is available on device.

Micropython will first execute & then looks out to execute file named

So you cannot upload file in other name to execute.If you use some other name , then the file will be executed once.After power reboot it will not execute.

Image 24

Once the file is stored click on F5 or the Run green button.

Image 25

The script is uploaded and the on board LED blinks.

To stop execution you can press the STOP Red button.

Now the chevrons >>> appear at the shell.

You can write new code & save it to device , again in the name

This is how to upload new code.

Image 26




Node-RED is an example of a flow-based programming model .NODE RED is a powerful tool for building Internet of Things (IoT) applications by simply connecting & wiring together of code blocks & carry out tasks.It uses a visual programming approach that allows developers to connect predefined code blocks, known as ‘nodes’, together to perform a task.

The connected nodes, usually a combination of input nodes, processing nodes and output nodes, when wired together, make up a ‘flows’. Flows consist of multiple nodes wired together, with output tabs linked to input tabs of the next node in the flow. Messages flow along the nodes carrying data from node to node.

Today there is a vibrant user and developer community, with a core group working on the Node-RED code itself and most developers contributing nodes or flows to the flow library.


Image 4

In this post we use Raspberry PI 4 as hardware with Rasbian BURST OS & demonstrate a flow to control an LED connected to a GPIO pin of RPI.

Node RED is PRE-installed in Raspbian operating system by default.

Image 1


I’m accessing RPI from my Windows machine over WI-FI.

Both RPI & Windows PC are connected over WIFI to same Router.XRDP is installed on RPI & from Windows machine access is through Remote Desktop.

You can check out my previous blog on how to do this.


Image 3

Though NODE RED comes preinstalled with Raspbian , you need to update initially.

Before starting Node Red , open Terminal & type in this command :

sudo apt-get install build-essential

—  to ensure npm is able to build any binary modules it needs to install. npm is Node Package Manager for the JavaScript .

Next Run the  following command to download and run the script

bash <(curl -sL

This script will remove the pre-packaged version of Node-RED and Node.js if they are present &

install the current Node.js LTS release using the NodeSource.

It also installs the latest version of Node-RED using npm ,setup Node-RED to run as a service and provide a set of commands to work with the service



This action will take around 10 minutes.



Auto start on boot

If you want Node-RED to run when the Pi is turned on, or re-booted, you can enable the service to autostart by running the command:

sudo systemctl enable nodered.service

To disable the service, run the command:

sudo systemctl disable nodered.service

To start NODE RED  by clicking on NODE RED under Programming.As it starts running you can see an IP address link ending :1880  which is the default port of Nodered.

Once Node-RED is running you can access the editor in a browser.

Image 2

If you are using the built in browser on the Pi desktop, you can open the address:


I recommend using a browser outside of the PI and pointing it at Node-RED running on the Pi.

When browsing from another machine you should use the hostname or IP-address of the Pi: http://<hostname&gt;:1880.

You can find the IP address by running

hostname –I

on the Pi. In my case host name is , so I open browser on Windows and type in :

where 1880 is default port of NodeRed.

Now the NODE RED Window opens with colored NODES on the left side Palette.Center portion is the Flow Canvas where you create the flow by dragging in the nodes.Right side pane is for INFO & dEBUG MESSAGES.

Image 3

Scroll down the nodes to locate Raspberry PI.

rpi gpio  node is frequently used to control GPIO Pins of RPI , which has 2 options.

Image 11


One with the RPI icon to left of node is INPUT node (like button input) & the other with icon to Right is for OUTPUT node (like LED control).

Image 4


Input nodes allow you to input data into a Node-RED application or “flow”. They have at least one output endpoint represented by the small grey square only on their right side. You use input nodes to connect data from other services, for example the  Twitter, Google, serial, websockets or tcp nodes, or to manually input data into a flow using the inject node.

Output nodes allow you to send data outside of a Node-RED flow. They have a single input endpoint on their left side. You use output nodes to send data to other services, for example via Twitter, tcp, serial or email nodes, or to use the debug node to output to the debug pane

In this demo we control an LED connected to GPIO pin17 of RPI.




For this task we need an OUTPUT Node.


Image 5

Drag an Output Node to the canvas.

The output node with name PIN: is displayed with one RED triangle & a BLUE Circle over RPI icon.

The red triangle indicates that the properties are not yet set & the blue circle indicates that the node is not yet deployed to server.

Image 6


Double click on the Node to get PROPERTIES window.

As we have connected an LED at GPIO 17 (PIN 11) , select this pin.

Image 7

Select the type as DIGITAL OUTPUT.

Leave the Initial level of pin as LOW & provide a name as Red Led


Image 8

Click on DONE to see the RED Triangle disappear.

As we have not yet Deployed the node , the Blue circle remains.

Image 9

To feed a message we need an Input node like INJECT.

Drag and drop Inject node.It appears as timestamp node with a Grey button on left folloed by an Arrow.


Image 10

Double click on this Inject node to set properties.

Under PayLoad select String.


Image 11

Provide value of Payload as 1 & give a name as ON.

This is to inject 1 to RPI output node to make LED ON.

Click Done.

Image 12

Now drag on the small grey circle seen to the right of our ON inject node & connect to the RPI node Red Led.

The nodes for switching ON the LED are ready now.

Image 13

Next we need to create a node to switch OFF the LED.

Drag an input INJECT node again.

Image 14


Double click on this node and set the PayLoad String to 0.

Provide a name , like OFF.

Image 21

Connect the OFF node to Red Led node .

Now the FLOW is ready to be DEPLOYED.

Image 16

Click ON the red DEPLOY button on top right corner.


Image 17

The blue circles on Nodes disappear & you get Successfully Deployed message.


Image 19

Click on the Grey square button seen to the left of ON node.

This injects a String 1 to Red Led node , making the LED at gpio17 ON.


Image 20



To make the LED OFF , click the grey button of OFF node.This injects string 0 , switching OFF the LED.

You can see the string o at the bottom of Red Led node when it receives the payload.

Image 22

Next drag a DEBUG node from Output list.

Image 23

No properties setting for this node.Just connect both the ON & OFF nodes to the

debug node (msg payload)


Image 24

At the right top click on the DEBUG icon to see the debug messages.

Clicking on the ON or OFF nodes will control the LED , as well display the debug messages.

Image 25

Next we shall add a BUTTON to control LED.

Remove the ON & OFF nodes we created earlier , by selecting the node and hitting Delete button.

Drag and drop an Input GPIO node from Raspberry PI list.


Image 27

Double click on node to set properties.

Select GPIO 13 , as we connect a button to this GPIO pin.


Image 28



The LED is connected to GPIO 17  as shown below.

A 2 leg reset button is used , one end of button goes to 3.3v & the other end through a resistor to GND.

The junction point is connected to GPIO 13.


Image 20                    Image 30

Under properties select PULL DOWN , which applies an internal resistor to GND to the button.For safety we use an external resistor too.

Select Read initial state of pin & provide a name as Button.

Image 29

Connect the node to Red Led node & Click on Deploy.

Image 30

When the button is pressed a HIGH is applied to GPIO 13 , which in turn switches ON the LED ta GPIO 17.


Image 31

To import new NODES or to install DASHBOARD click on settings button next to Deploy button & select MANAGE PALETTE.


Image 8

To search for new nodes , you can click on NODES & download.

To install dashboard , click the install button & search for dashboard.

Select node red dashboard & install.


Image 9


Node-RED Dashboard is a module that provides set of nodes  to  create a live data dashboard.

To open the Node-RED UI, type your Raspberry Pi IP address in a web browser

followed by     :1880/ui

With Dashboard you can select your own nodes and create your own User Interface.

To access the settings file of Node Red

use command

ls –a

to list hidden files.

Then change directory to  .node-red

Here you can see the settings.js file where you can provide password for access to node red.

Image 40




Previous post was on controlling home devices using BLYNK CLOUD.

Instead of controlling manually we can use voice commands to operate devices.For this we use the GOOGLE ASSISTANT on mobile phone.

Google assistant cannot directly communicate with BLYNK. For making a chain link between Google assistant and Blynk we use IFTTT.

If This Then That, also known as IFTTT, is a free web-based service to create chains of simple conditional statements, called applets. An applet is triggered by changes that occur within other web services such as Gmail, Facebook, Telegram, Instagram,etc.

In this project we make use of WEBHOOKS on IFTTT to handle a web service , which is BLYNK.

The hardware setup is same as in previous post.




Create a new project on BLYNK.



Get the Authorized Token ID.


Create 2 button widgets , one for fan control and the other for light control.



Fan to be connected at digital pin D2 through relay board.


Light connected to digital pin D4 through relay board.




Once the settings on BLYNK application is completed we can close it.Need not be operated manually.

We shall use IFTTT  to make a chain between Google assistant and Blynk.




Image 4


Click on CREATE.


Image 7

You see a + symbol before THIS.

Click on that.

Image 8

Choose a service ,GOOGLE ASSISTANT

Image 9

Choose a method to trigger , Say a simple phrase.

Image 10

Next page is to complete trigger fields with options like what you want to say & what Google Assistant should reply.

Image 11


Complete the fields for FAN ON control as shown below & click Create Trigger


Image 13


Now you can see the GOOGLE ASSISTANT Logo at the THIS position.

Click on the + symbol before THAT



Image 15

Search for WEBHOOKS and select it.

Image 16

Then click on “ Make a WEB REQUEST”.

Image 17

On next page you’ve to complete action fields.

Image 18

Under URL, you need to provide the IP address of

This can be achieved by opening Command prompt &



Image 2


URL Format is

http://IP of blynk-cloud/auth id/update/digital pin

Authorized ID is the one you received in mail while creating your BLYNK project.

The digital pin to be controlled is that of Arduino. As we use NODEMCU hardware , check the pin out as below to select the correct digital pin.

For e,g we used D2 to connect Fan control.In NODEMCU pinout D2 is GPIO4 , so you need to input D4 .

Image 12


Method to be selected is PUT

content type is : application/json

& the body is [“0”]

A 0 within double quotes & square brackets used to switch on the relay.As the 4 channel relay board we used is a LOW enabled ( LOW at input switches ON the relay) we need to feed 0 for ON.

Image 19


Now the first APPLET is created and Connected.


Image 20

Click on FINISH.

Image 21

In the same way we need to create 3 more Applets for FAN OFF,LIGHT ON & LIGHT OFF.

Note that in Body you should send a 1 under double quotes & square brackets for switching OFF the relay.

Image 22


Image 23


Image 24



Image 26


Finally click on your account & MY APPLETS to see the applets you created.

Image 29

Image 28


Now open your Arduino IDE & under examples –> BLYNK –>  BOARDS WIFI –> NODEMCU

Do the following modifications in code & upload to NODEMCU.


Image 14

Finally install GOOGLE ASSISTANT from play store on your mobilr & open.

GOOGLE ASSISTANT will be running at the background.

You need to say OK GOOGLE or HEY GOOGLE to start the interaction.

Following is the screen shot on the commands given and the response from Google Assistant

Accordingly the devices will be made ON or OFF.









In the previous post , we worked on a home automation project and Android mobile application & controlled devices locally .ie., over Local Area Network.

In this post we will see how to make the home automation project to control from anywhere in the world. IOT CLOUD Platform BLYNK is used for implementing this.BLYNK is the most popular IoT platform to connect your devices to the cloud,

BLYNK  is a digital dashboard where you can build a graphic interface for your project by simply dragging and dropping widgets.It supports a wide range of Hardware including Arduino,Nodemcu,Raspberry PI & others.

First  install BLYNK on your mobile phone by signing up with your EMAIL ID.

Open BLYNK application.Touch on NEW PROJECT.


Provide a name to the project & select hardware.Here Im using NODEMCU.




Connection type is WIFI .

Touch on CREATE button.



An authorized token ID will be sent to your registered EMAIL.



Now we shall see the WIDGET BOX to add some elements.Each element of WIDGET BOX has got an ENERGY LEVEL.

While starting up you will be provided a free energy level of 2000.According to the usage of widgets this energy level will be deducted.



For e.g , add a BUTTON to your project.


An energy level of 200 will be deducted.If you want you can BUY Energy level by touching on the ADD button.





Add 2 buttons as shown below.



To set the properties of first button , touch on that button.




Provide a name to the button 1.

Touch on PIN to select pin.As we control a dc fan through relay board which is connected to D2 of Nodemcu , select DIGITAL PIN D2.

There are also VIRTUAL PINS Upto 255 , which are specific to BLYNK firmware. These virtual pins are NOT Physical pins , but are handy to send data or message to them and then control physical pins from within code.


Slide the MODE setting to SWITCH which makes the button at as ON or OFF.



Similarly for the Button 2 set the PIN to digital D4 where we control an AC load through the relay board.





Now touch on the Back arrow to go to the start up page.

On touching the PLAY Icon , a message indication stating Not yet online is displayed.As we are yet to upload code on to Nodemcu , the setting is OFF line for now,

From your PC side , open the Arduino IDE.

For setting NODEMCU to Arduino core ,open File & under Preferences paste this json link


Image 5

Then open Tools –> Boards Manager , search for ESP8266 & install.

Image 29

Also from Sketch – > Manage Libraries –> Library

search fro BLYNK & install the library.

Image 31

Once the library is installed you can see under Examples —> Blynk

Open the NodemCU Example code.


You need to replace with your Authorized token ID which you received in Email while creating the Blynk project.

Provide your WiFi credentials ,SSID & password of Router to which Nodemcu will be connected.

Also under setup() make the digital pins D2 & D4 HIGH.

This step is to make the loads connected to relays initially OFF.

As the relay board we are using is a LOW ENABLED , a LOW at input energizes the Relay and a HIGH makes it OFF.


We make use of MB102 PSU board on a MB102 bread board.This MB102 board has got jumper settings to make one rail as 5v & the other rail as 3.3v.

A jumper seen at he relay board can be removed.

Connect Vcc to 3.3v & JD-Vcc to 5v rail of bread board.

Image 32

The loads can be connected as shown below.Always connect the power source  on which the load operates to the POLE pin.Actual load is connected to Normally Open contact.

Image 37

Connect NODEMCU to PC , from ARDUINO IDE select the board as NODEMCU & select the port allotted.For this you must have already installed driver for CP2102.

Upload the code & then disconnect USB cable.

Provide 12v 1amp or 9v 1amp adapter to MB102 PSU board.

Allow some time for NODEMCU to join the SSID mentioned in the code.

While using AC load ,take care not to touch the relay board and insulate properly the relay board inside a plastic box.

Image 38

Now open the BLYNK Application and touch on the project you created.On top right corner touch on the PLAY Icon.

Once you see ONLINE indication , you can touch on the buttons created to control the loads.

video tutorial :




In Raspberry PI 3 & 4 the physical UART at GPIO14/GPIO15 is disabled.

In new machines the mapping is as follows.

/dev/ttyAMA0 -> Bluetooth
/dev/ttyS0 -> GPIO serial port   (referred to as the “mini uart”) disabled by default.

The powerful ttyAMA0 is assigned to Bluetooth & the limited frequency ttyS0 is assigned to UART.

Board pin 8 (GPIO14)  Tx
Board pin 10 (GPIO15) Rx

older Raspberry Pi it will point to the hardware UART and /dev/ttyAMA0


In this post , let us see how to enable UART and then overcome the Permission denied problem by swapping the ttyAMA0 & ttyS0.



While connecting the GSM with RPI use level shifter, as the TTL level of PI is 3.3 volt & that of GSM is 5v.

The Tx of PI (physical pin 8) goes directly to Rx of GSM. As GSM accepts 3.3v as High, you can connect this straight .

But the Rx (physical pin 10) pin needs alevel shifter before connecting to Tx of GSM

A simple 1k resistor in series and a 2k2 to GND will solve the purpose.


To enable the serial0 edit config.txt file using nano editor.


Navigate to the end of file and add


ctrl+x & Yes to save the file


use command

ls –l /dev

to read the devices.You can see serial0 is now enabled and mapped to ttyS0.

Image 4

Open picocom to communicate with GSM

picocom –baud 9600 /dev/ttyS0

Permission is Denied.



You can change permissions with sudo chmod command.But on next reboot this will change.

Also assigning groups dialout & tty to user PI does not help.

Image 2

In Raspberry Pi , you can use the serial port as a terminal to log in.
Even if you don’t have a network connection,you can connect to another computer via their serial ports and run a terminal software like putty  on the other computer to get a login prompt.

By default the Raspberry Pi uses the serial port for this “console” login
and via a software service called “getty”.

if we want to use the serial port to get data from a GPS or GSM, we need to disable
the console login so that gsm/gps alone get control of the port.

use the following commands

sudo systemctl stop serial-getty@ttyS0.service
sudo systemctl disable serial-getty@ttyS0.service

First command is to STOP the service of getty & the second one disables it.

Image 5


Finally Remove the console service by editing cmdline.txt




remove the line:


and save , reboot for changes to take effect.





Image 6


To use BLUETOOTH add the following line to the /boot/config.txt

sudo nano /boot/config.txt



Add this line at the end




Now mini uart is assigned to Bluetooth function.



After reboot you can check the devices

ls –l /dev

to see serial0 is assigned to ttyAMA0 & serial1 to ttyS0


Image 82

Install putty serial terminal .






open putty

Select SERIAL & feed in host as


& BAUD RATE 9600




pUTTY Terminal opens where we can test the GSM AT Commands.



Now the UART is mapped to ttyAMA0 as in older machines of PI and old python codes will work without any change.

Video support :






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.

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

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

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)




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

WiFiServer server(80);

void setup() {
pinMode(FAN, OUTPUT);

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

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

Serial.println(“new client”);
String req = client.readStringUntil(‘\r’);

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

Serial.println(“FAN ON”);
else if(req.indexOf(“/fanoff”) != -1)
Serial.println(“FAN OFF”);

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



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

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 , 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.


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


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 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

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.







IOT is Internet Of Things where devices are connected over internet and made SMART.

These devices can be controlled from any where in the World or collect data from devices to process.

In this 1st post of IOT series I will introduce the hardware required to start with and also the IOT platforms used.

Arduino boards are much popular among hobbyists and developers.But these Arduino boards (UNO,MEGA) lack Ethernet or WIFI capability which is essential for IOT.

For wired connection there is ETHERNET Shield which can be plugged on directly to UNO or Mega.



For internet access I’m using a Huawei make USB Dongle with a Data SIM inserted.This dongle

can be used in standalone mode , as it has got WIFI capability.But plugging this to a Router

like TP-LINK enhances its capability of WIFI Range, more Clients, Static IP setting,etc..





The Ethernet shield can be plugged on to Arduino and an Ethernet cable (straight type)

can be used to connect with the Router.

The Router will then allot an IP Address (local IP) to the ethernet shield which is now a client.

DHCP server of Router allots the IP on first come first basis.As this IP is DYNAMIC ,

the address may not be the same if powered off and connected again.’’

To make the IP address STATIC , the ROUTER has ADDRESS RESERVATION settings

under DHCP.

MAC address of the device is used to make the local IP STATIC.


Instead of wired Ethernet connection you can go for WIFI Devices. ESP8266 WIFI modules are

cheap and popular now.

ESP8266 WIFI modules , a wide range available.ESP8266-01 module is basic model .As it is not breadboard friendly , you can make use of a base board to plug on , as shown in picture below.

ESP8266-12E module has more GPIO pins and memory.

These modules can communicate with ARDUINO using AT COMMANDS for ESP.




To use ESP modules we need a controller like Arduino.

Easier option is to use NODEMCU Modules.These NODEMCU modules are built on ESP12E chip

and has USB to upload code.LUA is the official Firmware that comes with NODEMCU.

Using BOARDS MANAGER in Arduino IDE you can implement ARDUINO CORE on to NODEMCU

and start using NODEMCU individually.

You can check out my video on how to implement Arduino core on to NODEMCU.

Once Arduino core implemented , you can use Arduino IDE and libraries to develop code on NODEMCU.

Latest arrival is ESP32 which is much more powerful than NODEMCU with more Analog pins

and with BLUETOOTH,BLE and inbuilt sensors.


For IOT and HOME AUTOMATION projects RELAY BOARDS are helpful to connect wide

range  of Loads or devices.

5V Relay boards are available with 1 channel , 2, 4,8 Upto 16 channels .

Each relay is driven by an opto coupler and a NPN transistor.The relay contacts are

provided as Terminal connectors.

Each Relay has a  common POLE,  a NC –Normally Connected contact and a

NO – Normally Open contact.



These 5V relay boards are LOW ENBLED, meaning , a LOW at input will energize the Relay.

A low at input will make the opto coupler conduct which drives the NPN Transistor.

This in turn will switch ON the relay.


Electronic solid state relay boards are also available which are called SSR.



12v Relay modules also are available.Here the relay is driven by a NPN transistor .12V Modules are HIGH ENABLED ,meaning, a HIGH at input drives the relay ON.




Any load ,DC or AC can be connected to the RELAY contacts, irrespective of the supply voltage to relay board.

The power supply to load is connected to POLE pin and the actual load is connected to the NO pin.

As the relay is energized the pole pin changes from NC to NO ,thus activating  the Load.

While using AC load take precaution to insulate properly the wires as well as the Relay boar.Do not touch relay board with AC load.



You can control the devices over Local Area Network or through Cloud or internet.

While using LAN , make sure that the NODEMCU and your mobile , both are connected to the same Router SSID.

For control over internet you need to PORT FORWARD the local ip device port on the router settings.But nowadays a number of IOT PLATFORMS are available as CLOUD. Though you need a paid subscription , most of them offer free service for hobbyists with some limitations.


Sign in to any of these platforms and start controlling the devices from anywhere in the world.


VIDEO support :







In this article we will explore the ways to auto connect Raspberry PI to WIFI and control it from a Windows machine.

In this demo I use RASPBERRY PI 4 2 GB board , but the method applies to all versions with WIFI ,

RPI 3 B , B+ &  RPI Zero W.

There is no need to connect any Ethernet cable to PI .The keyboard , display of Windows machine are used to control RPI. This is called HEADLESS MODE of operation.

This post will get you up and running with a Raspberry Pi, connected to your WIFI network and accessible over SSH, without ever needing to connect anything to it, besides power source.

RPI 4 comes in 3 variables with 1GB , 2GB  or 4GB RAM. This has 2 USB 3.0 & 2 USB 2.0 ports , a Gigabyte Ethernet port & 2 micro HDMI 4k support ports.

The power cable to be used is C type which can handle more current .

To start with download the latest Raspbian OS image from the official website:

Use CLASS 10 Micro SD card of more than 16GB memory.

A card reader can be used to plug in the SD card on to the Windows Laptop.

Image102                   Image104


To burn the OS image use ETCHER software .

Download it from here :


Image 101


You now have the latest Raspbian image ( BUSTER at the time of this blog) which is ready to boot, but not yet ready to fully work headless!

Remove the card reader with SD card and plug it again .The Windows system can display only the BOOT partition . The ROOT partition is not visible.

Image 1


Prepare to Connect WIFI

To make the Pi connect to your Wifi access point at first boot, store the wifi connection details on the Pi’s boot drive.

Following to be done on Windows system.

Under boot partition of SD card , you need to create a file named wpa_supplicant.conf.

Before this , click on View & put a tick mark against File Name Extensions.

This enables to view the extension of filenames.


Image 2

Right click on empty space and create a new Text document.

Image 4

Rename the text document to  wpa_supplicant.conf.txt.

Image 5


Image 6

Double click the file to open in Notepad.Remember , the file name is now with .txt extension , so that it is open with Notepad.Later you need to delete this .txt extension .

Visit this official site to copy and paste the WIFI code.

The 2 letter Country Alpha-2 code is important and can be known from this wiki link :

Now enter the 2 letter Country code & then your WIFI SSID name and password.

Image 7

If you want to connect with more than 1 SSID , wherever available , you can use the

PRIORITY setting as shown below.

Image 8

Save the file.

Right click to rename & remove the .txt extension.


Image 9

On First Boot the contents of this file will be copied to the relevant etc file location , WIFI enabled and joined to the SSID credentials given.

Finally this wpa_supplicant.conf file will be deleted automatically.


By default, a clean Raspbian image will have Secure SHell SSH disabled. You need to enable SSH at first boot.

To do this , right click on empty space on BOOT section of SD card and create an empty text document ssh.txt

Rename it to delete the .txt extension.

On first boot SSH will be enabled and the file will be deleted automatically.

Image 105


Now remove the SD card and plug it on to Raspberry PI.Power up the PI using proper adapter , a power source of 5v 2.4amp required.

Allow some time to boot up and to auto connect with WIFI.

Following image is the scenario setup now.



A Router connected to Internet Service Provider acts as an Access point .My Windows Laptop is connected to this Router over WIFI.

Now my Raspberry PI also joined the same network.

The Gateway IP of my Router is

The Router will assign IP address to its clients as and when connected by DHCP server.

To verify , whether RPI has joined the network , use PUTTY Software


PuTTY is an SSH and telnet client

Open PUTTY and select SSH .

Enter HOSTNAME as  raspberrypi.

Click OPEN

Image 10

Now you can login using standard Raspberry PI credentials

username : pi

password : raspberry

Image 11

You get the Raspberry PI home prompt.

To know the IP ADDRESS allotted to PI type in

hostname -I

Image 12


To know the Gateway IP of Router

route –n



You can type in this Gateway IP on to your Browser to access the Router settings.



Under DHCP –> DHCP Clients list you can see the list of CLIENTS

You can see the raspberrypi as a client with MAC address and an IP allotted.

This IP is allotted by the DHCP Server, which allots accordingly on first come first basis.

It means , if you shut down RPI and connect again the IP may not be the same.The IP allotted is DYNAMIC.

Image 109

To make it STATIC , copy the MAC address of PI (as seen in above screen shot)

Click on ADDRESS RESERVATION under DHCP of Router settings.

Click ADD NEW…

Image 110

Paste the MAC address and the IP address of RPI you wanted to make it permanent.

This IP should fall in Gateway IP , where the last octet only is changed.

Image 111

Now the address is made STATIC and will be same on every boot.

Next  to view RPI on windows we need to install Remote Desktop protocol client XRDP on RPI


sudo apt-get install xrdp

to start installation of xrdp.

Image 13

On Windows machine , RDP server is installed by default on WIN7,8 & 10.

RDP is proprietary of Microsoft.Just ensure that under advanced system setting,

Remote Assistance is allowed.


Open the Remote Desktop connection on Windows.

Image 14

Type in computer name as rapberrypi & Connect.

Image 28



Image 29

Login window will appear.Here under Session select Xorg ( previously it was called sesmanager)

Image 38

username as pi & password raspberry

Image 30

Now you can see the Raspbian welcome screen on Windows machine.

Image 31

Image 32


Image 33

video tutorial :




Image 1Image 2

89s52  is widely used  IC in 8051 FAMILY.

It is programmed using ICSP with an external programmer USBASP (AVRDUDE).

89S52 has no BOOTLOADER , so it cannot be programmed through SERIAL Port.

W78E052DDG is 8051 compatible 8-bit controller from Nuvoton with 8K programmable flash memory in 40 Pin DIP package

This chip has separate dedicated 2K boot-loader memory, which makes this chip robust and very stable .It supports ISP program downloading from PC using RX-TX lines only.

Other specifications match exactly 89S52.

It contains an 8K-byte Flash EPROM , a 256-byte RAM; four 8-bit bi-directional (P0, P1, P2, P3) and bit-addressable I/O ports , an additional 4-bit I/O port P4; three 16-bit timer/counters ,  a hardware watchdog timer , and a serial port

The instruction set is fully compatible with the standard 8052. Note that the actual part number of the chip in the 40-pin DIP package is W78E052DDG


Because the Nuvoton W78E052D microcontroller comes with a UART boot-loader, it can directly be programmed from the serial (COM) port. You can use “Nuvoton ISP-ICP Utility software” to program the target MCU with the help of a  USB TO RS232 Cable

This cable has CH340 serial IC inside.

Driver for CH340 to be installed in PC , for COM port allotment.

Image 1

The same development of 89S52 can be used for Nuvotone  IC.

Image 2


Note that in this procedure, the MCU’s Reset (RST) pin is controlled by the programmer; hence, a power cycling should become necessary in most situations.

The microcontroller needs an oscillator for its clock generation, so an external 11.0592-MHz crystal with two 22-pF capacitors as shown in the hardware setup diagram is required.

Furthermore, the chip has no internal power-on-reset, so it is achieved externally through the Reset pin using a 10-uF capacitor or 0.1 uf and a 10K resistor.

Image 19

Details of programming from the official Nuvotone site :

For the 8051 MCU products with ISP function, there are two program memories: one is APROM and the other is LDROM. APROM contains the user’s application code for normal operation while LDROM contains the ISP code (cooperating with the ISP Programmer) for updating of APROM.

To use the ISP Programmer to update APROM, the ISP code should always reside in LDROM. If the ISP code disappears from LDROM because of accidentally being erased by a universal programmer, the ISP function will become always failed.

To recover the ISP function, please use a universal programmer to program the Nuvoton standard ISP code into LDROM, and have its CONFIG setting properly configured .

Why is the ISP code easily/accidentally erased by a universal programmer? Because the LDROM is also erased along with the APROM if the user uses a universal programmer to program APROM.

So, it is  strongly recommended  to use the ISP Programmer to program APROM in the beginning of getting the MCU sample with ISP code inside. Don’t use any universal programmer to program APROM unless the ISP function won’t be used.

The difference between ISP (In-System Programming) and ICP (In-Circuit Programming) is that ISP is implemented by software control of MCU itself while ICP is implemented by hardware control. So, before updating the MCU chip, ISP needs a software code (the ISP-code) pre-programmed in MCU’s LDROM to function as software control while ICP doesn’t need any software code pre-programmed.

During ISP operation, the 8051 MCU’s P3.1 behaves as ‘DTA’ (serial data). When ISP is not requested, P3.1 can function as its normal general purpose I/O pin as long as P3.1 conforms to the following requirements: * The state of P3.1 must be logic-1 before the MCU is just released from reset condition. * During the ISP operation, P3.1 cannot be pulled low by the other components connected to it.

Nuvotone Utility IDE is used to dump HEX file on to the Nuvotone Chip.

Download the utility here :


Image 3

Open the Utility

Select ISP BY COM PORT & SELECT THE COM PORT from the drop down menu.

Part no as W78E052D , items to be updated APROM.

Click on LOAD FILE button and browse to the location of the HEX file to load on the APROM Buffer.


Image 3


The creation of HEX file is similar to that of 89S52 using KEIL U-VISION software.

Open KEIL & create NEW Project.

Select Device for target as W79E052D ( selection of 89S52 also works).

Image 1


Image 2

Right click Target & under options for Target click on OUTPUT tab & put a tick mark against


Image 3


Right click SOURCE GROUP & click Add New item to Group.

Select C File & provide a name for the file.

Image 4


Now write your C code & click on BUILD or press F7 key.


Image 5


Image 6

Your HEX file is created under Objects folder.

Image 7


Image 8

Click on LOAD FILE in the NUVOTONE Utility & browse to the HEX file location to select it.

Image 9


Ensure that APROM is selected in the utility.

Image 10


Now click on UPDATE CHIP.

While you see the blue update bar at the bottom you must press the RESET button on the development board.

Image 11


If RESET button is not pressed , you get FAIL report.

Also note that the NUVOTONE Utility must be started in ADMIN mode.


Image 12



Image 14

Once you get the PASS report , you need to press the OK button.

This will execute the file loaded.

Image 15

There is also a P.M selection for multiple IC programming.

Tick mark this P.M & click on UPDATE CHIP.

You can program multiple chips in this mode ,

After RESET you can change the IC & program repeatedly.


Image 13






In the previous post we have seen the installation of PLATFORM IO on VS CODE.

While connecting the ESP32 to PC the PLATFORM IO detects AND ASSIGNS the COM port automatically.

To see the COM port click on DEVICES icon.

Refresh button can be pressed if new connection is made.


Image 36

If more than one COM port is listed , then you can select the COM port manually.

In this demo ,I ‘ve connected  another USB-TTL device with CP2102. To another USB port ESP32

is connected.

Image 37

Click the Refresh button under DEVICES  to view all the COM Ports.Here COM5 is allotted to ESP32 &

COM21 to USB-TTL device.

TO SELECT  COM port 5 Manually, open the platform.ino file.

Add this line at the end.


Save & upload code to see COM port 5 selected & used.


Image 40


Now let us see the solution for the error we encountered in previous post.

Under Arduino.h we received a Squiggle red line indicating error & Intellisense regarding Arduino core was not effective. Arduino.h file was not recognized.

Image 6



If you move the cursor over the Squiggles you see a balloon.Clicking on this shows some solution for the problem.But this was not successful.

Image 8

Finally I got the solution from Plaform IO forum.

Just DELETE the folder .vscode under Explorer.


Image 26

Right click .vscode folder & just DELETE it.





Now close the VS code & restart again .

The Squiggles are gone & new .vscode folder is automatically created.


Image 30

Now Intellisense regarding Arduino.h is working Fine

Image 35



Image 10