You are on page 1of 49

CHAPTER-Ⅰ

INTRODUCTION

1.1 ESP8266 BOARD

Fig 1.1 Esp8266 Board Diagram

1.2 ESP8266 NodeMCU

What is an ESP8266 NodeMCU? The ESP8266 is a low-cost Wi-Fi


chip developed by Espressif Systems.

It can be used as a standalone device, or as a UART to Wi-Fi adaptor to


allow other microcontrollers to connect to a Wi-Fi network. For example, you
can connect an ESP8266 to an Arduino to add Wi-Fi capabilities to your
Arduino board. The most practical application is using it as a standalone device.

1
With the ESP8266, you can control inputs and outputs as you would do
with an Arduino, but with Wi-Fi capabilities. This means you can bring your
projects online, which is great for home automation and internet of things
applications. Why is the ESP8266 so popular? Mainly for the following reasons:

Low-cost: you can get ESP8266 boards starting at $3 (or less) depending on the
model.

Low-power: the ESP8266 consumes very little power when compared with
other microcontrollers and can even go into deep sleep mode to consume less
power;

Wi-Fi: the ESP8266 can generate its own Wi-Fi network (access point) or
connect to other Wi-Fi networks (station) to get access to the internet. This
means the ESP8266 can access online services to make HTTP requests or save
data to the cloud, for example. It can also act as a web server so that you can
access it using a web browser and be able to control and monitor your boards
remotely.

Compatible with the Arduino “programming language”: those that are


already familiar with programming the Arduino board, were happy to know that
they can program the ESP8266 in the Arduino style.

Compatible with MicroPython: you can program the ESP8266 with


MicroPython firmware, which is a re-implementation of Python 3 targeted for
microcontrollers and embedded systems.

1.2 ESP8266 Applications

 The ESP8266 modules are commonly found in the following IoT devices:
 Smart security devices, including surveillance cameras and smart locks
 Smart energy devices, including HVACs and thermostats
 Smart industrial devices, including Programmable Logic Controllers
(PLCs)
 Smart medical devices, including wearable health monitors

2
1.3 ESP8266 Functions

 ESP8266 has many applications when it comes to the IoT. Here are just
some of the functions the chip is used for:
 Networking: The module’s Wi-Fi antenna enables embedded devices to
connect to routers and transmit data
 Data Processing: Includes processing basic inputs from analog and digital
sensors for far more complex calculations with an RTOS or Non-OS
SDK
 P2P Connectivity: Create direct communication between ESPs and other
devices using IoT P2P connectivity
 Web Server: Access pages written in HTML or development languages.

1.4 ESP8266 Specifications

Table 1.1 ESP8266 Specifications

1.5 Chip versus Modules versus Development Boards


As discussed above, the ESP8266 is just the name of the chip. There are
essentially three formats you can buy this in:

3
ESP8266 Chip: This is the basic chip manufactured by Espressif, which
comes unshielded and needs to be soldered onto a module. This is unsuitable for
most users, apart from perhaps volume device manufacturers that can factor this
into the production process under the unit cost of a module.

ESP8266 Modules: These are the surface-mountable modules that contain


the chip, which are ready to be mounted onto an MCU, produced by Espressif,
Ai-Thinker and certain other manufacturers. They are usually shielded and pre-
approved by the FCC for use. This means they’re a good option for device
manufacturers looking to scale production.

ESP8266 Development Boards: These are the complete IoT


MCU development boards that have the modules preinstalled. They’re used for
developers and manufacturers to create prototypes during the design stage,
before they start production. Development boards are produced by several
different manufacturers and the specifications differ between models. Some
core specifications to be aware of when assessing ESP8266 IoT development
board options include:

 GPIO pins
 ADC pins
 Wi-Fi antennas
 LEDs
 Shielding*
 Flash Memory

*Many international markets require shielded Wi-Fi devices, as Wi-Fi


produces considerable Radio Frequency Interference (RFI), and shielding
minimizes this interference. This should, therefore, be a key consideration for
all developers and embedded-device manufacturers.

4
1.6 ESP8266 Modules

Espressif Systems

The Espr essif Systems esp8266 is available in the following modules:

Table 1.2 Espr essif Systems esp8266

Ai-Thinker

Current Ai-Thinker esp8266 modules are the following:

5
Table 1.3 Ai-Thinker esp8266 modules

Older and discontinued models include: ESP-01, ESP-02, ESP-03, ESP-04,


ESP-05, ESP-06, ESP-7, ESP-08, ESP-09, ESP-10, ESP-11, ESP-12, ESP-12E,
and ESP-13 and ESP-14.

1.7 SDKs

There is now a wide range of software development kits (SDKs) available,


enabling developers to program the chip directly without using a separate
MCU.

Espressif provides two official SDKs for use with ESP8266, which are:

1. A FreeRTOS based SDK


2. A Non-OS SDK
3. Aside from the Espressif options, there are plenty of commercial and
open-source SDKs on the market, including:
4. ESP Arduino Core – C++ based firmware
5. ESP8266 BASIC – Open-source BASIC-like environment for IoT
6. ESP-Open-RTOS – FreeRTOS open-source framework for ESP8266
7. ESP-Open-SDK – Open integrated SDK for ESP8266
8. Espruino – Javascript SDK and firmware
9. Micropython – Python for embedded devices
10.Moddable SDK – Javascript SDK
11.Mongoose OS – C or Javascript open-source OS
12.NodeMCU – Open-source Lua based firmware, similar to Node.js
13.Sming – Asynchronous C/C++ framework
14.uLisp – Lisp-based framework
15.ZBasic – Visual Basic 6 adapted for ESP8266
16.Zerynth – Python framework for IoT

6
1.8 NodeMCU Pinout and Functions Explained

Fig 1.2 Esp8266 CONNECTION DIAGRAM

 Power Pins There are four power pins. VIN pin and three 3.3V pins.
 VIN can be used to directly supply the NodeMCU/ESP8266 and its
peripherals. Power delivered on VIN is regulated through the onboard
regulator on the NodeMCU module – you can also supply 5V regulated to
the VIN pin
 3.3V pins are the output of the onboard voltage regulator and can be used
to supply power to external components.
 GND are the ground pins of NodeMCU/ESP8266
 I2C Pins are used to connect I2C sensors and peripherals. Both I2C
Master and I2C Slave are supported. I2C interface functionality can be
realized programmatically, and the clock frequency is 100 kHz at a
maximum. It should be noted that I2C clock frequency should be higher
than the slowest clock frequency of the slave device.

7
 GPIO Pins NodeMCU/ESP8266 has 17 GPIO pins which can be assigned
to functions such as I2C, I2S, UART, PWM, IR Remote Control, LED
Light and Button programmatically. Each digital enabled GPIO can be
configured to internal pull-up or pull-down, or set to high impedance.
When configured as an input, it can also be set to edge-trigger or level-
trigger to generate CPU interrupts.
 ADC Channel The NodeMCU is embedded with a 10-bit precision SAR
ADC. The two functions can be implemented using ADC. Testing power
supply voltage of VDD3P3 pin and testing input voltage of TOUT pin.
However, they cannot be implemented at the same time.
 UART Pins NodeMCU/ESP8266 has 2 UART interfaces (UART0 and
UART1) which provide asynchronous communication (RS232 and
RS485), and can communicate at up to 4.5 Mbps. UART0 (TXD0,
RXD0, RST0 & CTS0 pins) can be used for communication. However,
UART1 (TXD1 pin) features only data transmit signal so, it is usually
used for printing log.
 SPI Pins NodeMCU/ESP8266 features two SPIs (SPI and HSPI) in slave
and master modes. These SPIs also support the following general-purpose
SPI features:
 4 timing modes of the SPI format transfer
 Up to 80 MHz and the divided clocks of 80 MHz
 Up to 64-Byte FIFO
 SDIO Pins NodeMCU/ESP8266 features Secure Digital Input/Output
Interface (SDIO) which is used to directly interface SD cards. 4-bit 25
MHz SDIO v1.1 and 4-bit 50 MHz SDIO v2.0 are supported.
 PWM Pins The board has 4 channels of Pulse Width Modulation (PWM).
The PWM output can be implemented programmatically and used for
driving digital motors and LEDs. PWM frequency range is adjustable
from 1000 μs to 10000 μs (100 Hz and 1 kHz).
 Control Pins are used to control the NodeMCU/ESP8266. These pins
include Chip Enable pin (EN), Reset pin (RST) and WAKE pin.
 EN: The ESP8266 chip is enabled when EN pin is pulled HIGH. When
pulled LOW the chip works at minimum power.
 RST: RST pin is used to reset the ESP8266 chip.
 WAKE: Wake pin is used to wake the chip from deep-sleep.
 Control Pins are used to control the NodeMCU/ESP8266. These pins
include Chip Enable pin (EN), Reset pin (RST) and WAKE pin.

8
 EN: The ESP8266 chip is enabled when EN pin is pulled HIGH. When
pulled LOW the chip works at minimum power.
 RST: RST pin is used to reset the ESP8266 chip.
 WAKE: Wake pin is used to wake the chip from deep-sleep.

1.9 ESP8266 Technical Data

For more details about the specs of the ESP8266, check the following list:

Fig 1.3 Esp8266 WIFI CHIP

Processor: L106 32-bit RISC microprocessor core based on the Tensilica


Diamond Standard 106Micro running at 80 or 160 MHz

Memory:

32 KiB instruction RAM


32 KiB instruction cache RAM
80 KiB user-data RAM
16 KiB ETS system-data RAM
External QSPI flash: up to 16 MiB is supported (512 KiB to 4 MiB
typically included)
IEEE 802.11 b/g/n Wi-Fi

9
Integrated TR switch, balun, LNA, power amplifier, and matching
network
WEP or WPA/WPA2 authentication, or open networks
17 GPIO pins
Serial Peripheral Interface Bus (SPI)
I²C (software implementation)
I²S interfaces with DMA (sharing pins with GPIO)
UART on dedicated pins, plus a transmit-only UART can be enabled on
GPIO2
10-bit ADC (successive approximation ADC)

10
CHAPTER-Ⅱ

LITERATURE SURVEY
2.1 INTRODUCTION

Arduino Integrated Development Environment (IDE) v1

Learn how the Arduino IDE v1 works, such as compiling & uploading sketches,
file management, installing dependencies and much more.

The Arduino Integrated Development Environment - or Arduino


Software (IDE) - contains a text editor for writing code, a message area, a text
console, a toolbar with buttons for common functions and a series of menus. It
connects to the Arduino hardware to upload programs and communicate with
them.

2.2 Writing Sketches

Programs written using Arduino Software (IDE) are called sketches.


These sketches are written in the text editor and are saved with the file
extension .ino. The editor has features for cutting/pasting and for
searching/replacing text. The message area gives feedback while saving and
exporting and also displays errors. The console displays text output by the
Arduino Software (IDE), including complete error messages and other
information. The bottom righthand corner of the window displays the
configured board and serial port. The toolbar buttons allow you to verify and
upload programs, create, open, and save sketches, and open the serial monitor.

NB: Versions of the Arduino Software (IDE) prior to 1.0 saved


sketches with the extension .pde. It is possible to open these files with version
1.0, you will be prompted to save the sketch with the .ino extension on save.

• Verify Checks your code for errors compiling it.

11
• Upload Compiles your code and uploads it to the configured board.
See uploading below for details.
• Note: If you are using an external programmer with your board, you can
hold down the "shift" key on your computer when using this icon. The
text will change to "Upload using Programmer"

• New Creates a new sketch.

• Open Presents a menu of all the sketches in your sketchbook. Clicking
one will open it within the current window overwriting its content.
• Note: due to a bug in Java, this menu doesn't scroll; if you need to open a
sketch late in the list, use the File | Sketchbook menu instead.

• Save Saves your sketch.

• Serial Monitor Opens the serial monitor.
• Additional commands are found within the five
menus: File, Edit, Sketch, Tools, Help. The menus are context sensitive,
which means only those items relevant to the work currently being
carried out are available.
• File
• New Creates a new instance of the editor, with the bare minimum
structure of a sketch already in place.
• Open Allows to load a sketch file browsing through the computer drives
and folders.
• Open Recent Provides a short list of the most recent sketches, ready to be
opened.
• Sketchbook Shows the current sketches within the sketchbook folder
structure; clicking on any name opens the corresponding sketch in a new
editor instance.
• Examples Any example provided by the Arduino Software (IDE) or
library shows up in this menu item. All the examples are structured in a
tree that allows easy access by topic or library.
• Close Closes the instance of the Arduino Software from which it is
clicked.
• Save Saves the sketch with the current name. If the file hasn't been named
before, a name will be provided in a "Save as.." window.

12
• Save as... Allows to save the current sketch with a different name.
• Page Setup It shows the Page Setup window for printing.
• Print Sends the current sketch to the printer according to the settings
defined in Page Setup.
• Preferences Opens the Preferences window where some settings of the
IDE may be customized, as the language of the IDE interface.
• Quit Closes all IDE windows. The same sketches open when Quit was
chosen will be automatically reopened the next time you start the IDE.
• Edit
• Undo/Redo Goes back of one or more steps you did while editing; when
you go back, you may go forward with Redo.
• Cut Removes the selected text from the editor and places it into the
clipboard.
• Copy Duplicates the selected text in the editor and places it into the
clipboard.
• Copy for Forum Copies the code of your sketch to the clipboard in a form
suitable for posting to the forum, complete with syntax coloring.
• Copy as HTML Copies the code of your sketch to the clipboard as
HTML, suitable for embedding in web pages.
• Paste Puts the contents of the clipboard at the cursor position, in the
editor.
• Select All Selects and highlights the whole content of the editor.
• Comment/Uncomment Puts or removes the // comment marker at the
beginning of each selected line.
• Increase/Decrease Indent Adds or subtracts a space at the beginning of
each selected line, moving the text one space on the right or eliminating a
space at the beginning.
• Find Opens the Find and Replace window where you can specify text to
search inside the current sketch according to several options.
• Find Next Highlights the next occurrence - if any - of the string specified
as the search item in the Find window, relative to the cursor position.
• Find Previous Highlights the previous occurrence - if any - of the string
specified as the search item in the Find window relative to the cursor
position.
• Sketch
• Verify/Compile Checks your sketch for errors compiling it; it will report
memory usage for code and variables in the console area.

13
• Upload Compiles and loads the binary file onto the configured board
through the configured Port.
• Upload Using Programmer This will overwrite the bootloader on the
board; you will need to use Tools > Burn Bootloader to restore it and be
able to Upload to USB serial port again. However, it allows you to use
the full capacity of the Flash memory for your sketch. Please note that
this command will NOT burn the fuses. To do so a Tools -> Burn
Bootloader command must be executed.
• Export Compiled Binary Saves a .hex file that may be kept as archive or
sent to the board using other tools.
• Show Sketch Folder Opens the current sketch folder.
• Include Library Adds a library to your sketch by inserting #include
statements at the start of your code. For more details, see libraries below.
Additionally, from this menu item you can access the Library Manager
and import new libraries from .zip files.
• Add File... Adds a supplemental file to the sketch (it will be copied from
its current location). The file is saved to the
• data
• subfolder of the sketch, which is intended for assets such as
documentation. The contents of the
• data
• folder are not compiled, so they do not become part of the sketch
program.
• Tools
• Auto Format This formats your code nicely: i.e. indents it so that opening
and closing curly braces line up, and that the statements inside curly
braces are indented more.
• Archive Sketch Archives a copy of the current sketch in .zip format. The
archive is placed in the same directory as the sketch.
• Fix Encoding & Reload Fixes possible discrepancies between the editor
char map encoding and other operating systems char maps.
• Serial Monitor Opens the serial monitor window and initiates the
exchange of data with any connected board on the currently selected Port.
This usually resets the board, if the board supports Reset over serial port
opening.
• Board Select the board that you're using. See below for descriptions of
the various boards.

14
• Port This menu contains all the serial devices (real or virtual) on your
machine. It should automatically refresh every time you open the top-
level tools menu.
• Programmer For selecting a hardware programmer when programming a
board or chip and not using the onboard USB-serial connection. Normally
you won't need this, but if you're burning a bootloader to a new
microcontroller, you will use this.
• Burn Bootloader The items in this menu allow you to burn
a bootloader onto the microcontroller on an Arduino board. This is not
required for normal use of an Arduino board but is useful if you purchase
a new ATmega microcontroller (which normally come without a
bootloader). Ensure that you've selected the correct board from
the Boards menu before burning the bootloader on the target board. This
command also set the right fuses.
• Help
• Here you find easy access to a number of documents that come with the
Arduino Software (IDE). You have access to Getting Started, Reference,
this guide to the IDE and other documents locally, without an internet
connection. The documents are a local copy of the online ones and may
link back to our online website.
• Find in Reference This is the only interactive function of the Help menu:
it directly selects the relevant page in the local copy of the Reference for
the function or command under the cursor.

2.3 Sketchbook

The Arduino Software (IDE) uses the concept of a sketchbook: a


standard place to store your programs (or sketches). The sketches in your
sketchbook can be opened from the File > Sketchbook menu or from
the Open button on the toolbar. The first time you run the Arduino software, it
will automatically create a directory for your sketchbook. You can view or
change the location of the sketchbook location from with the Preferences dialog.

Beginning with version 1.0, files are saved with a .ino file
extension. Previous versions use the .pde extension. You may still open .pde
named files in version 1.0 and later, the software will automatically rename the
extension to .ino.

15
2.4 Tabs, Multiple Files, and Compilation

Allows you to manage sketches with more than one file (each of
which appears in its own tab). These can be normal Arduino code files (no
visible extension), C files (.c extension), C++ files (.cpp), or header files (.h).

Before compiling the sketch, all the normal Arduino code files of
the sketch (.ino, .pde) are concatenated into a single file following the order the
tabs are shown in. The other file types are left as is.

2.5 Uploading

Before uploading your sketch, you need to select the correct items
from the Tools > Board and Tools > Port menus. The boards are described
below. On the Mac, the serial port is probably something
like /dev/tty.usbmodem241 (for an UNO or Mega2560 or Leonardo)
or /dev/tty.usbserial-1B1 (for a Duemilanove or earlier USB board),
or /dev/tty.USA19QW1b1P1.1 (for a serial board connected with a Keyspan
USB-to-Serial adapter). On Windows, it's probably COM1 or COM2 (for a
serial board) or COM4, COM5, COM7, or higher (for a USB board) - to find
out, you look for USB serial device in the ports section of the Windows Device
Manager. On Linux, it should be /dev/ttyACMx , /dev/ttyUSBx or similar. Once
you've selected the correct serial port and board, press the upload button in the
toolbar or select the Upload item from the Sketch menu. Current Arduino
boards will reset automatically and begin the upload. With older boards (pre-
Diecimila) that lack auto-reset, you'll need to press the reset button on the board
just before starting the upload. On most boards, you'll see the RX and TX LEDs
blink as the sketch is uploaded. The Arduino Software (IDE) will display a
message when the upload is complete, or show an error.

When you upload a sketch, you're using the Arduino bootloader, a


small program that has been loaded on to the microcontroller on your board. It
allows you to upload code without using any additional hardware. The
bootloader is active for a few seconds when the board resets; then it starts
whichever sketch was most recently uploaded to the microcontroller. The
bootloader will blink the on-board (pin 13) LED when it starts (i.e. when the
board resets).

2.6 Libraries
16
Libraries provide extra functionality for use in sketches, e.g.
working with hardware or manipulating data. To use a library in a sketch, select
it from the Sketch > Import Library menu. This will insert one or
more #include statements at the top of the sketch and compile the library with
your sketch. Because libraries are uploaded to the board with your sketch, they
increase the amount of space it takes up. If a sketch no longer needs a library,
simply delete its #include statements from the top of your code.

There is a list of libraries in the reference. Some libraries are included with the
Arduino software. Others can be downloaded from a variety of sources or
through the Library Manager. Starting with version 1.0.5 of the IDE, you do can
import a library from a zip file and use it in an open sketch. See
these instructions for installing a third-party library.

To write your own library, see this tutorial.

2.7 Third-Party Hardware

Support for third-party hardware can be added to


the hardware directory of your sketchbook directory. Platforms installed there
may include board definitions (which appear in the board menu), core libraries,
bootloaders, and programmer definitions. To install, create
the hardware directory, then unzip the third-party platform into its own sub-
directory. (Don't use "arduino" as the sub-directory name or you'll override the
built-in Arduino platform.) To uninstall, simply delete its directory.

For details on creating packages for third-party hardware, see the Arduino
Platform specification.

2.8 Serial Monitor

This displays serial sent from the Arduino board over USB or
serial connector. To send data to the board, enter text and click on the "send"
button or press enter. Choose the baud rate from the drop-down menu that
matches the rate passed to Serial.begin in your sketch. Note that on Windows,
Mac or Linux the board will reset (it will rerun your sketch) when you connect

17
with the serial monitor. Please note that the Serial Monitor does not process
control characters; if your sketch needs a complete management of the serial
communication with control characters, you can use an external terminal
program and connect it to the COM port assigned to your Arduino board.

You can also talk to the board from Processing, Flash, MaxMSP, etc (see
the interfacing page for details).

2.9 Preferences

Some preferences can be set in the preferences dialog (found under


the Arduino menu on the Mac, or File on Windows and Linux). The rest can be
found in the preferences file, whose location is shown in the preference dialog.

FIG 2.1 ARUDINO LANGUAGE SELECTION

18
Since version 1.0.1 , the Arduino Software (IDE) has been
translated into 30+ different languages. By default, the IDE loads in the
language selected by your operating system. (Note: on Windows and possibly
Linux, this is determined by the locale setting which controls currency and date
formats, not by the language the operating system is displayed in.)

If you would like to change the language manually, start the


Arduino Software (IDE) and open the Preferences window. Next to the Editor
Language there is a dropdown menu of currently supported languages. Select
your preferred language from the menu, and restart the software to use the
selected language. If your operating system language is not supported, the
Arduino Software (IDE) will default to English.

You can return the software to its default setting of selecting its
language based on your operating system by selecting System Default from
the Editor Language drop-down. This setting will take effect when you restart
the Arduino Software (IDE). Similarly, after changing your operating system's
settings, you must restart the Arduino Software (IDE) to update it to the new
default language.

2.10 Boards

The board selection has two effects: it sets the parameters (e.g.
CPU speed and baud rate) used when compiling and uploading sketches; and
sets and the file and fuse settings used by the burn bootloader command. Some
of the board definitions differ only in the latter, so even if you've been
uploading successfully with a particular selection you'll want to check it before
burning the bootloader. You can find different boards here.

Arduino Software (IDE) includes the built in support for the


boards in the following list, all based on the AVR Core. The Boards
Manager included in the standard installation allows to add support for the
growing number of new boards based on different cores like Arduino Due,
Arduino Zero, Edison, Galileo and so on.

Arduino Yún An ATmega32u4 running at 16 MHz with auto-


reset, 12 Analog In, 20 Digital I/O and 7 PWM.

19
Arduino Uno An ATmega328P running at 16 MHz with auto-
reset, 6 Analog In, 14 Digital I/O and 6 PWM.

Arduino Diecimila or Duemilanove w/ ATmega168 An


ATmega168 running at 16 MHz with auto-reset.

Arduino Nano w/ ATmega328P An ATmega328P running at 16


MHz with auto-reset. Has eight analog inputs.

Arduino Mega 2560 An ATmega2560 running at 16 MHz with


auto-reset, 16 Analog In, 54 Digital I/O and 15 PWM.

Arduino Mega An ATmega1280 running at 16 MHz with auto-


reset, 16 Analog In, 54 Digital I/O and 15 PWM.

Arduino Mega ADK An ATmega2560 running at 16 MHz with


auto-reset, 16 Analog In, 54 Digital I/O and 15 PWM.

Arduino Leonardo An ATmega32u4 running at 16 MHz with auto-


reset, 12 Analog In, 20 Digital I/O and 7 PWM.

Arduino Micro An ATmega32u4 running at 16 MHz with auto-


reset, 12 Analog In, 20 Digital I/O and 7 PWM.

Arduino Esplora An ATmega32u4 running at 16 MHz with auto-


reset.

Arduino Mini w/ ATmega328P An ATmega328P running at 16 MHz with auto-


reset, 8 Analog In, 14 Digital I/O and 6 PWM.

Arduino Ethernet Equivalent to Arduino UNO with an Ethernet


shield: An ATmega328P running at 16 MHz with auto-reset, 6 Analog In, 14
Digital I/O and 6 PWM.

Arduino Fio An ATmega328P running at 8 MHz with auto-reset.


Equivalent to Arduino Pro or Pro Mini (3.3V, 8 MHz) w/ ATmega328P, 6
Analog In, 14 Digital I/O and 6 PWM.

Arduino BT w/ ATmega328P ATmega328P running at 16 MHz.


The bootloader burned (4 KB) includes codes to initialize the on-board
Bluetooth® module, 6 Analog In, 14 Digital I/O and 6 PWM..

20
LilyPad Arduino USB An ATmega32u4 running at 8 MHz with
auto-reset, 4 Analog In, 9 Digital I/O and 4 PWM.

LilyPad Arduino An ATmega168 or ATmega132 running at 8


MHz with auto-reset, 6 Analog In, 14 Digital I/O and 6 PWM.

Arduino Pro or Pro Mini (5V, 16 MHz) w/ ATmega328P An


ATmega328P running at 16 MHz with auto-reset. Equivalent to Arduino
Duemilanove or Nano w/ ATmega328P; 6 Analog In, 14 Digital I/O and 6
PWM.

Arduino NG or older w/ ATmega168 An ATmega168 running at


16 MHzwithout auto-reset. Compilation and upload is equivalent to Arduino
Diecimila or Duemilanove w/ ATmega168, but the bootloader burned has a
slower timeout (and blinks the pin 13 LED three times on reset); 6 Analog In,
14 Digital I/O and 6 PWM.

Arduino Robot Control An ATmega328P running at 16 MHz with


auto-reset.

Arduino Robot Motor An ATmega328P running at 16 MHz with


auto-reset.

Arduino Gemma An ATtiny85 running at 8 MHz with auto-reset,


1 Analog In, 3 Digital I/O and 2 PWM.

For instructions on installing support for other boards, see third-


party hardware above.

21
CHAPTER-Ⅲ

METHOLODGY

3.1 What is Android Studio?

In recent times, Android became the world's most popular operating


system for various reasons. As an Android programmer, I want to share what
the Android Studio is? Android Studio is an IDE for Google Android
Development launched on 16th May 2013, during Google's I/O 2013 event.
Android Studio contains all the Android tools to design, test, debug, and profile
your application. The Android Studio uses Gradle to manage your project, a
Build Automation Tool.
For developing your first app, you need to download Android Studio for your
preferred platform (Windows®, Mac OS X, or Linux) from the Android
developers site. Android Studio can develop and test your application on either
a real device or an emulator.

22
Android Studio has many exciting features that can help you to develop
your Android application like :

 Powerful code editor with smart editing and code re-factoring.


 Emulator to show your code output in various resolutions, including Nexus 4,
Nexus 7, Nexus 10, and many other android phones.
 Gradle based build support.
 Maven Support.
 Template-based wizards.
 Dracula Theme Environment to enjoy your coding experience.

You can experience all the awesome features by using Android Studio in-hand.

3.2 install of android studio

Step 1 - System Requirements

You will be delighted, to know that you can start your Android application
development on either of the following operating systems −
 Microsoft® Windows® 10/8/7/Vista/2003 (32 or 64-bit)
 Mac® OS X® 10.8.5 or higher, up to 10.9 (Mavericks)
 GNOME or KDE desktop
Second point is that all the required tools to develop Android applications are
open source and can be downloaded from the Web. Following is the list of
software's you will need before you start your Android application
programming.
 Java JDK5 or later version
 Java Runtime Environment (JRE) 6
 Android Studio

Step 2 - Setup Android Studio

Overview

Android Studio is the official IDE for android application development.It


works based on IntelliJ IDEA, You can download the latest version of android
studio from Android Studio 2.2 Download, If you are new to installing Android
Studio on windows,you will find a file, which is named as android-studio-
23
bundle-143.3101438-windows.exe.So just download and run on windows
machine according to android studio wizard guideline.
If you are installing Android Studio on Mac or Linux, You can
download the latest version from Android Studio Mac Download,or Android
Studio Linux Download, check the instructions provided along with the
downloaded file for Mac OS and Linux. This tutorial will consider that you are
going to setup your environment on Windows machine having Windows 8.1
operating system.

Installation

So let's launch Android Studio.exe,Make sure before launch Android


Studio, Our Machine should required installed Java JDK. To install Java
JDK,take a references of Android environment setup

Fig 3.1 Android Studio Installation

24
Once you launched Android Studio, its time to mention JDK7 path or later
version in android studio installer.

Fig 3.2 Android Studio Setup

25
Below the image initiating JDK to android SDK

Fig 3.3 Android Studio Jdk selection

26
Need to check the components, which are required to create applications, below
the image has selected Android Studio, Android SDK, Android Virtual
Machine and performance(Intel chip).

Fig 3.4 Android Studio choose Components

27
Need to specify the location of local machine path for Android studio and
Android SDK, below the image has taken default location of windows 8.1 x64
bit architecture.

Fig 3.5 Android Studio Configuration Setting

28
3.3 CREATE ANDROID APPLICATIN

After done all above steps perfectly, you must get finish button and it
gonna be open android studio project with Welcome to android studio message
as shown below

Fig 3.6 Android Studio Create New Project

29
You can start your application development by calling start a new android
studio project. in a new installation frame should ask Application name,
package information and location of the project.

Fig 3.7 Android Studio Create New Application

The next level of installation should contain selecting the activity to mobile, it
specifies the default layout for Applications

30
Fig 3.8 Android Studio Choose Activity

At the final stage it going to be open development tool to write the application
code.

Fig 3.9 Android Studio Code Section

Step 3 - Create Android Virtual Device

To test your Android applications, you will need a virtual Android


device. So before we start writing our code, let us create an Android virtual

31
device. Launch Android AVD Manager Clicking AVD_Manager icon as shown
below

Fig 3.10 Launch Application

After Click on a virtual device icon, it going to be shown by default virtual


devices which are present on your SDK, or else need to create a virtual device
by clicking Create new Virtual device button

Fig 3.11 Android Studio Target Device

32
If your AVD is created successfully it means your environment is ready
for Android application development. If you like, you can close this window
using top-right cross button. Better you re-start your machine and once you are
done with this last step, you are ready to proceed for your first Android example
but before that we will see few more important concepts related to Android
Application Development.

3.4 Running Application

Fig 3.12 IOT Application

33
CHAPTER-Ⅳ

EXPERIMENTAL WORK

4.1 ARUDINO SOFTWARE


4.1.1 Open arudino software from windows

Arudino
software

Fig 4.1Arudino Application

4.1.2 Write the program

34
#include <ESP8266WiFi.h>

/* define port */

WiFiClient client;

WiFiServer server(80);

/* WIFI settings */

const char* ssid = "Azephyrad";

const char* password = "@guinevere@@@";

/* data received from application */

String data = "";

/* define L298N or L293D motor control pins */

int leftMotorForward = 2; /* GPIO2(D4) -> IN3 */

int rightMotorForward = 15; /* GPIO15(D8) -> IN1 */

int leftMotorBackward = 0; /* GPIO0(D3) -> IN4 */

int rightMotorBackward = 13; /* GPIO13(D7) -> IN2 */

void setup()

Serial.begin(115200);

/* initialize motor control pins as output */

pinMode(leftMotorForward, OUTPUT);

pinMode(rightMotorForward, OUTPUT);

pinMode(leftMotorBackward, OUTPUT);

pinMode(rightMotorBackward, OUTPUT);

//connect to your local wi-fi network

WiFi.begin(ssid, password);

// Attempt to connect to WiFi network:

while (WiFi.status() != WL_CONNECTED)

Serial.print(".");

// Connect to WPA/WPA2 network. Change this line if using open or WEP network:

// Wait 3 seconds for connection:

delay(3000);

Serial.println("");

35
Serial.println("WiFi connected");

Serial.println("IP address: ");

Serial.println(WiFi.localIP()); //You can get IP address assigned to ESP

/* start server communication */

server.begin();

void loop()

/* If the server available, run the "checkClient" function */

client = server.available();

if (!client) return;

data = checkClient ();

/************************ Run function according to incoming data from application *************************/

/* If the incoming data is "forward", run the "MotorForward" function */

if (data == "forward") MotorForward();

/* If the incoming data is "backward", run the "MotorBackward" function */

else if (data == "backward") MotorBackward();

/* If the incoming data is "left", run the "TurnLeft" function */

else if (data == "left") TurnLeft();

/* If the incoming data is "right", run the "TurnRight" function */

else if (data == "right") TurnRight();

/* If the incoming data is "stop", run the "MotorStop" function */

else if (data == "stop") MotorStop();

/********************************************* FORWARD *****************************************************/

void MotorForward(void)

digitalWrite(leftMotorForward, HIGH);

digitalWrite(rightMotorForward, HIGH);

digitalWrite(leftMotorBackward, LOW);

digitalWrite(rightMotorBackward, LOW);

/********************************************* BACKWARD *****************************************************/

void MotorBackward(void)

digitalWrite(leftMotorBackward, HIGH);

36
digitalWrite(rightMotorBackward, HIGH);

digitalWrite(leftMotorForward, LOW);

digitalWrite(rightMotorForward, LOW);

/********************************************* TURN LEFT *****************************************************/

void TurnLeft(void)

digitalWrite(leftMotorForward, LOW);

digitalWrite(rightMotorForward, HIGH);

digitalWrite(rightMotorBackward, LOW);

digitalWrite(leftMotorBackward, HIGH);

/********************************************* TURN RIGHT *****************************************************/

void TurnRight(void)

digitalWrite(leftMotorForward, HIGH);

digitalWrite(rightMotorForward, LOW);

digitalWrite(rightMotorBackward, HIGH);

digitalWrite(leftMotorBackward, LOW);

/********************************************* STOP *****************************************************/

void MotorStop(void)

digitalWrite(leftMotorForward, LOW);

digitalWrite(leftMotorBackward, LOW);

digitalWrite(rightMotorForward, LOW);

digitalWrite(rightMotorBackward, LOW);

/********************************** RECEIVE DATA FROM the APP ******************************************/

String checkClient (void)

while (!client.available()) delay(1);

String request = client.readStringUntil('\r');

request.remove(0, 5);

request.remove(request.length() - 9, 9);

return request;}

4.1.3 connect the port and setting the port

37
Fig 4.2 Arudino Port Setting

4.1.4 upload the program


 Upload the program from arudino software
4.2. ANDROID STUDIO
 Open android studio software from windows application
 Create the software
 Then write the program from main activity.java

Package
com.example.iotproject;

38
import androidx.appcompat.app.AppCompatActivity;

import android.annotation.SuppressLint;
import android.os.Bundle;
import android.view.View;
import android.webkit.WebView;
import android.webkit.WebViewClient;
import android.widget.Button;
import android.widget.EditText;

import androidx.appcompat.app.AppCompatActivity;
public class MainActivity extends AppCompatActivity {

EditText ip;
Button poweron;
Button poweroff,POWERMANUAL;

@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);

// Find the WebView by its unique ID


WebView webView = findViewById(R.id.web);
ip = (EditText)findViewById(R.id.ipaddress);
poweron = (Button)findViewById(R.id.poweron);
poweroff =(Button)findViewById(R.id.poweroff);
POWERMANUAL=(Button)findViewById(R.id.powermanual);

poweron.setOnClickListener(new View.OnClickListener() {
public void onClick(View v) {

webView.loadUrl("http://"+ip.getText().toString()+"/forward");

// this will enable the javascript.

}
});

//poweroff
poweroff.setOnClickListener(new View.OnClickListener() {
public void onClick(View v) {

webView.loadUrl("http://"+ip.getText().toString()+"/stop");

// this will enable the javascript.

}
});

//powermanual

POWERMANUAL.setOnClickListener(new View.OnClickListener() {
public void onClick(View v) {
webView.loadUrl("http://"+ip.getText().toString()+"/stop");

}
});

POWERMANUAL.setOnLongClickListener(new View.OnLongClickListener() {
public boolean onLongClick(View v) {
webView.loadUrl("http://"+ip.getText().toString()+"/forward");
return false;
}

39
});
}

Write the program activity man.xml

<?xml version="1.0" encoding="utf-8"?>


<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="match_parent"
tools:context="com.example.iotproject.MainActivity"
android:orientation="vertical">

<EditText
android:id="@+id/ipaddress"
android:text="192.168.143.113"
android:layout_width="150dp"
android:layout_height="50dp">

</EditText>

<Button
android:id="@+id/poweron"
android:layout_width="150dp"
android:layout_height="50dp"
android:text="POWER ON"

>

</Button>

<Button
android:id="@+id/poweroff"
android:layout_width="150dp"
android:layout_height="50dp"
android:text="POWER OFF"

>

</Button>

<Button
android:id="@+id/powermanual"
android:layout_width="150dp"
android:layout_height="50dp"
android:text="POWER MANUAL"

>

</Button>
<!-- unique ID of WebView -->
<WebView
android:id="@+id/web"
android:visibility="invisible"
android:layout_width="match_parent"
android:layout_height="180dp"
tools:layout_editor_absoluteX="8dp"
tools:layout_editor_absoluteY="8dp" />
</LinearLayout>

40
BUILD THE PROGRM
To view details about the build process, select View > Tool Windows > Build or
click Build in the tool window bar. The Build tool window

4.3 Material Preparation


 Select the Square type mild steel pipe

Fig 4.3 Material Selection


 Cut the pipe from requirements

Fig 4.4 Mild Steel cutting

41
 Weld the pipe

Automatic door open with wifi


control

Fig 4.5 Weld The Pipe

 Add the Rack and Pinion gear Mechanism

Fig 4.6 Rack and Pinion Mechanism

42
INSTALL THE IOT ANDROID SOFTWARE

 Install the after build android application from android studio windows
application
 Then open the iot software.
 Run the iot software.

Fig 4.7 Iot Application Connect

43
CHAPTER-Ⅴ

RESULTS AND DISCUSSIONS

5.1 IOT ANDROID APPLICATION

 Open IOT Application

Fig 5.1 Iot Application

 Connect Wifi IP Address

Fig 5.2 Connect wifi

44
 Click Button Gate Open

Fig 5.3 Gate open apps

 Click The Button Gate close

Fig 5.4 Gate close apps

45
5.2 Esp8266 Board and DC Motor

Gate Open Button Click.

Dc motor run forward with wifi control gate opened.

Fig 5.5 Gate Open

46
Gate Close Button Click.

Dc motor run Reverse with wifi control gate opened.

Fig 5.6 Gate close

47
CHAPTER-Ⅵ

CONCLUSION

 It can be inferred that both the ESP32 and the ESP8266 are amazing
toolkits. Sometimes one is preferred over the other when it comes to
certain elements in question.
 The ESP8266 has a lower current consumption than that of its competitor
however one has more digital pins than the other. Hence you should
choose the variant you are in need of.
 Hope this article will give you some useful information.

 The NodeMCU has an ESP12, which itself is a module containing the


ESP8266.
You can think of it as a computer with a mainboard, including a CPU.
 Because our ESP8266 Deauther project requires an ESP8266 to run
(hence the name), you'd need to get development boards that use the
ESP8266 (either directly or in a module like the ESP12) to recreate the
project. Of course, you could technically just buy the SoC or a module,
but it would be impossible to make any use of it without additional
equipment. Like using a CPU without a mainboard. But a development
board will have all the needed hardware onboard.
 So that's the difference between an SoC, RF module, and development
board. Of course, the same concept applies to other chips, like the ESP32.
We just took the ESP8266 as an example here.

CHAPTER-Ⅶ

48
REFERENCE

7.1 Interrupts
Interrupts can be used on the ESP8266, but they must be used with care and
have several limitations:

 Interrupt callback functions must be in IRAM, because the flash may be in


the middle of other operations when they occur. Do this by adding
the IRAM_ATTR attribute on the function definition. If this attribute is not
present, the sketch will crash when it attempts to attachInterrupt with an
error message.
IRAM_ATTR void gpio_change_handler(void *data) {...

 Interrupts must not call delay() or yield(), or call any routines which
internally use delay() or yield() either.
 Long-running (>1ms) tasks in interrupts will cause instabilty or crashes.
WiFi and other portions of the core can become unstable if interrupts are
blocked by a long-running interrupt. If you have much to do, you can set a
volatile global flag that your main loop() can check each pass or use a
scheduled function (which will be called outside of the interrupt context
when it is safe) to do long-running work.
 Heap API operations can be dangerous and should be avoided in interrupts.
Calls to malloc should be minimized because they may require a long
running time if memory is fragmented. Calls to realloc and free must
NEVER be called. Using any routines or objects which
call free or realloc themselves is also forbidden for the same reason. This
means that String, std::string, std::vector and other classes which use
contiguous memory that may be resized must be used with extreme care
(ensuring strings aren’t changed, vector elements aren’t added, etc.). The
underlying problem, an allocation address could be actively in use at the
instant of an interrupt. Upon return, the address actively in use may be
invalid after an ISR uses realloc or free against the same allocation.
 The C++ new and delete operators must NEVER be used in an ISR. Their
call path is not in IRAM. Using any routines or objects that use
the new or delete operator is also forbidden.

49

You might also like