Professional Documents
Culture Documents
INTRODUCTION
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.
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.
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.
GPIO pins
ADC pins
Wi-Fi antennas
LEDs
Shielding*
Flash Memory
4
1.6 ESP8266 Modules
Espressif Systems
Ai-Thinker
5
Table 1.3 Ai-Thinker esp8266 modules
1.7 SDKs
Espressif provides two official SDKs for use with ESP8266, which are:
6
1.8 NodeMCU Pinout and Functions Explained
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.
For more details about the specs of the ESP8266, check the following list:
Memory:
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
Learn how the Arduino IDE v1 works, such as compiling & uploading sketches,
file management, installing dependencies and much more.
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
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.
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.
For details on creating packages for third-party hardware, see the Arduino
Platform specification.
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
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.)
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.
19
Arduino Uno An ATmega328P running at 16 MHz with auto-
reset, 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.
21
CHAPTER-Ⅲ
METHOLODGY
22
Android Studio has many exciting features that can help you to develop
your Android application like :
You can experience all the awesome features by using Android Studio in-hand.
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
Overview
Installation
24
Once you launched Android Studio, its time to mention JDK7 path or later
version in android studio installer.
25
Below the image initiating JDK to android SDK
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).
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.
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
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.
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.
31
device. Launch Android AVD Manager Clicking AVD_Manager icon as shown
below
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.
33
CHAPTER-Ⅳ
EXPERIMENTAL WORK
Arudino
software
34
#include <ESP8266WiFi.h>
/* define port */
WiFiClient client;
WiFiServer server(80);
/* WIFI settings */
void setup()
Serial.begin(115200);
pinMode(leftMotorForward, OUTPUT);
pinMode(rightMotorForward, OUTPUT);
pinMode(leftMotorBackward, OUTPUT);
pinMode(rightMotorBackward, OUTPUT);
WiFi.begin(ssid, password);
Serial.print(".");
// Connect to WPA/WPA2 network. Change this line if using open or WEP network:
delay(3000);
Serial.println("");
35
Serial.println("WiFi connected");
server.begin();
void loop()
client = server.available();
if (!client) return;
void MotorForward(void)
digitalWrite(leftMotorForward, HIGH);
digitalWrite(rightMotorForward, HIGH);
digitalWrite(leftMotorBackward, LOW);
digitalWrite(rightMotorBackward, LOW);
void MotorBackward(void)
digitalWrite(leftMotorBackward, HIGH);
36
digitalWrite(rightMotorBackward, HIGH);
digitalWrite(leftMotorForward, LOW);
digitalWrite(rightMotorForward, LOW);
void TurnLeft(void)
digitalWrite(leftMotorForward, LOW);
digitalWrite(rightMotorForward, HIGH);
digitalWrite(rightMotorBackward, LOW);
digitalWrite(leftMotorBackward, HIGH);
void TurnRight(void)
digitalWrite(leftMotorForward, HIGH);
digitalWrite(rightMotorForward, LOW);
digitalWrite(rightMotorBackward, HIGH);
digitalWrite(leftMotorBackward, LOW);
void MotorStop(void)
digitalWrite(leftMotorForward, LOW);
digitalWrite(leftMotorBackward, LOW);
digitalWrite(rightMotorForward, LOW);
digitalWrite(rightMotorBackward, LOW);
request.remove(0, 5);
request.remove(request.length() - 9, 9);
return request;}
37
Fig 4.2 Arudino Port Setting
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);
poweron.setOnClickListener(new View.OnClickListener() {
public void onClick(View v) {
webView.loadUrl("http://"+ip.getText().toString()+"/forward");
}
});
//poweroff
poweroff.setOnClickListener(new View.OnClickListener() {
public void onClick(View v) {
webView.loadUrl("http://"+ip.getText().toString()+"/stop");
}
});
//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
});
}
<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
41
Weld the pipe
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.
43
CHAPTER-Ⅴ
44
Click Button Gate Open
45
5.2 Esp8266 Board and DC Motor
46
Gate Close Button Click.
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.
CHAPTER-Ⅶ
48
REFERENCE
7.1 Interrupts
Interrupts can be used on the ESP8266, but they must be used with care and
have several limitations:
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