IOT Merged
IOT Merged
PRACTICAL 1
Hardware Components:
• Arduino Uno: Specifically chosen for its widespread availability, ease of use,
and compatibility with a wide range of sensors and actuators. Its versatility
allows for future expansion and integration with additional components.
Software Development:
Arduino IDE: Provides a user-friendly interface for writing, compiling, and
uploading code to the Arduino board. It supports the C++ programming
language, making it accessible to developers of varying skill levels.
Programming Logic: The firmware developed for the Arduino board
includes algorithms for sensor data acquisition, data processing,
decisionmaking regarding irrigation schedules, and control of the water
pump.
Algorithm: The irrigation algorithm considers factors such as soil moisture
thresholds, plant types, weather forecasts, and historical data to determine
the optimal watering schedule and duration. It may incorporate techniques
like threshold-based control, PID control, or machine learning for adaptive
irrigation management.
Installation
PRACTICAL 2
Write the steps to add libraries in Arduino and setup Arduino IDE for
programming.
1. Write the steps to add libraries in Arduino and setup Arduino IDE for programming.
b) Then the Library Manager will open and you will find a list of libraries that are
already installed or ready for installation. In this example we will install the
Bridge library. Scroll the list to find it, click on it, then select the version of the
library you want to install. Sometimes only one version of the library is
available. If the version selection menu does not appear, don't worry: it is
normal.
a) Finally click on install and wait for the IDE to install the new library.
Downloading may take time depending on your connection speed. Once it has
finished, an Installed tag should appear next to the Bridge library. You can
close the library manager.
You can now find the new library available in the Sketch > Include Library menu. If you
want to add your own library to Library Manager, follow these instructions.
Libraries are often distributed as a ZIP file or folder. The name of the folder is the name of
the library. Inside the folder will be a .cpp file, a .h file and often a keywords.txt file,
examples folder, and other files required by the library. Starting with version 1.0.5, you can
install 3rd party libraries in the IDE. Do not unzip the downloaded library, leave it as is.
c) In the Arduino IDE, navigate to Sketch > Include Library > Add .ZIP Library. At
the top of the drop down list, select the option to "Add .ZIP Library''.
a) You will be prompted to select the library you would like to add. Navigate to
the .zip file's location and open it.
b) Return to the Sketch > Include Library menu. menu. You should now see the
library at the bottom of the drop-down menu. It is ready to be used in your sketch.
The zip file will have been expanded in the libraries folder in your Arduino sketches
directory.
When you want to add a library manually, you need to download it as a ZIP file, expand
it and put in the proper directory. The ZIP file contains all you need, including usage
examples if the author has provided them. The library manager is designed to install this
ZIP file automatically as explained in the former chapter, but there are cases where you
may want to perform the installation process manually and put the library in the libraries
folder of your sketchbook by yourself.
You can find or change the location of your sketchbook folder at File> Preferences >
Sketchbook location.
a) Go to the directory where you have downloaded the ZIP file of the library
b) Extract the ZIP file with all its folder structure in a temporary folder, then select the
main folder, that should have the library name
PRACTICAL 3
Code:
void setup() {
pinMode(13, OUTPUT);
void loop() {
digitalWrite(13, HIGH);
delay(500);
digitalWrite(13, LOW);
delay(500);
PRACTICAL 4
Code:
const int lm35_pin A1; void
setup() {
Serial.begin(9600);
} void loop() {
int temp_adc_val;
int temp_val;
temp_adc_val = temp_vale_adc*4.88;
temp_val = temp_adc_val/10;
PRACTICAL 5
Write a program that shows how to fade an LED on pin 9 using the Analog.
Write() function.
Code:
int brightness = 0; int
fadeamount = 5;
void setup() {
pinMode(9,OUTPUT);
} void loop() {
analogWrite(9,brightness); brightness
= brightness + fadeamount;
} delay(30);
PRACTICAL 6
Hardware Setup
Connect an LED to your NodeMCU board. Connect the cathode (short leg) of the LED to a
current-limiting resistor (e.g., 220 ohms), and connect the other end of the resistor to GPIO
pin D1.
Connect the anode (long leg) of the LED to the 3.3V pin on the NodeMCU board.
Blynk Setup
Install the Blynk app on mobile device (iOS or Android) and create a new Blynk project.
In the Blynk app, add a "Slider" widget to control the LED brightness. Assign this widget to
V1 (Virtual pin 1).
#include <BlynkSimpleEsp8266.h>
#define LED_PIN D1 // You can change this pin as per your connection
void setup() {
Serial.begin(9600);
// Connect to WiFi
pinMode(LED_PIN, OUTPUT);
void loop() {
Steps To Follow:
PRACTICAL 7
Code:
#include <ESP8266WiFi.h>
#include <BlynkSimpleEsp8266.h>
void setup() {
Serial.begin(9600);
pinMode(ledPin, OUTPUT);
// Connect to WiFi
void loop() {
Blynk.run();
BLYNK_WRITE(V1) {
if (pinValue == 1) { // Turn
on the LED
digitalWrite(ledPin, HIGH);
Serial.println("LED ON");
} else {
Serial.println("LED OFF");
To control LED with Blynk app, download and install the Blynk app from Google or Apple
app store.
Then, if you are new to Blynk app, create a new account by using your Email and password.
I) In your browser search Blynk code generator then open Blynk example browser
II) Open Arduino IDE and select Tools option as shown below:
PRACTICAL 8
Code:
#include "Servo.h"
Servo myservo;
#define servoPin 9
void loop() {
myservo.write(90);
delay(1000);
myservo.write(180);
delay(1000);
myservo.write(0);
delay(1000);
} delay(1000);
PRACTICAL 9
Code:
int time;
Serial.println(distance/2);
PRACTICAL 10
Code:
#include <Servo.h>
Servo myservo; int
time; int distance,
dist; int trigPin =
12; int echoPin =
13;
void loop() {
digitalWrite(trigPin, LOW);
time = pulseIn(echoPin, HIGH);
distance = time * 0.0343; dist =
distance/2; Serial.println(dist);
if(dist<=100){
myservo.write(90);
delay(1000); }