Iot 1
Iot 1
SMART ROOF TOP GARDEN USING SOIL MOISTURE SENSOR AND NODEMCU
Aim:
To measure and monitor moisture values using soil moisture sensor Interfaced with NodeMCU.
Apparatus:
S.No Components Quantity
1 NodeMCU 1
2 Breadboard 1
3 USB Cable 1
4 Jumper Wires As per required
5 Soil Moisture Sensor 1
Theory:
The soil Moisture sensor FC-28 consists of two probes that are used to measure the volumetric
content of water. The sensor works between the input voltage range of 3.3V to 5V. The output voltage
given by it is 0 – 4.2V. The output signal appears both in analog form and in digital form. The soil
Moisture sensor FC-28 has four pins
VCC: For power
A0: Analog output
D0: Digital output
GND: Ground
The Module also contains a potentiometer that will set the threshold value and then this threshold
value will be compared by the LM393 comparator. The output LED will light up and down according to
this threshold value.
Circuit Diagram:
Procedure:
1. Connect the Soil Moisture sensor to NodeMCU: VCC to 3.3V, GND to GND, and data pin to A0
2. Set up NodeMCU on Arduino IDE: Open Arduino IDE, install necessary platform files for NodeMCU,
and select "NodeMCU 1.0 (ESP-12E Module)" under "Tools" -> "Board."
3. Write Arduino Code: Create a new sketch, paste the code,initialize the sensor, and read the
moisture values.
4. Upload the Code: Click the "Upload" button in Arduino IDE to load the code onto NodeMCU.
5 . Monitor Soil Moisture: Open the Serial Monitor in Arduino IDE (Tools -> Serial Monitor), and observe
real-time Soil Moisture readings from the sensor.
Code:
#define soil_moisture_pin A0
void setup() {
Serial.begin(9600);
}
void loop() {
Serial.println(analogRead(soil_moisture_pin));
delay(500);
}
Output:
After uploading the code we will obtain soil moisture readings in the serial monitor.
EXPERIMENT-2
CAPACITIVE TOUCH SENSOR USING ARDUINO
Aim:
To design and implement a capacitive touch sensor interface using NodeMCU.
Apparatus:
S.No Components Quantity
1 NodeMCU 1
2 Breadboard 1
3 USB Cable 1
4 Jumper Wires As per required
5 Capacitive Touch Sensor 1
Theory:
A capacitive touch sensor, also known as a touch button or touch switch, is commonly used to
control devices, such as a touchable lamp. It has the same purpose as a button, but is used in place
of a button on many modern devices due to its sleek appearance.
THE TOUCH SENSOR PINOUT
The touch sensor has three pins:
GND pin: This should be connected to the ground voltage (OV).
VCC pin: This should be connected to the VCC voltage (5V or 3.3V).
SIGNAL pin: This is an output pin. It will be LOW when not touched and HIGH when touched. This pin
should be connected to an ESP8266 input pin.
When the sensor is not being interacted with, the SIGNAL pin of the sensor is at a LOW level.
However, when the sensor is touched, the SIGNAL pin of the sensor is at a HIGH level.
Circuit Diagram:
Procedure:
1. Connect the Capacitive touch sensor to NodeMCU: VCC to 3.3V, GND to GND, and SIG pin to D7
2. Set up NodeMCU on Arduino IDE: Open Arduino IDE, install necessary platform files for NodeMCU,
and select "NodeMCU 1.0 (ESP-12E Module)" under "Tools" -> "Board."
3. Write Arduino Code: Create a new sketch, paste the code,initialize the sensor.
4. Upload the Code: Click the "Upload" button in Arduino IDE to load the code onto NodeMCU.
5 . Monitor Capacitive touch sensor: Open the Serial Monitor in Arduino IDE (Tools -> Serial Monitor),
and check Whether the sensor is touched or not.
Code:
#define SENSOR_PIN D7 // The ESP8266 NodeMCU input pin that connects to the sensor's SIGNAL
pin
int prev_state = LOW; // The previous state from the input pin
int touch_state; // The current reading from the input pin
void setup() {
// Initialize the Serial to communicate with the Serial Monitor.
Serial.begin(9600);
// initialize the ESP8266 NodeMCU's pin as an input
pinMode(SENSOR_PIN, INPUT);
}
void loop() {
// read the state of the the input pin:
touch_state = digitalRead(SENSOR_PIN);
if(prev_state == LOW && touch_state == HIGH)
Serial.println("The sensor is touched");
else if(prev_state == HIGH && touch_state == LOW)
Serial.println("The sensor is released");
// save the the last state
prev_state = touch_state;
}
Output:
After uploading the code if the sensor is touched it displays “The sensor is touched”
otherwise “The sensor is released” in the serial monitor.
EXPERIMENT-3
PI R M OT I O N S EN S O R M O D UL E I N T E RF A C E W I T H A RD UI N O
Aim:
To design and implement PIR Motion sensor module interface with Arduino.
Apparatus:
S.No Components Quantity
1 NodeMCU 1
2 Breadboard,LED 1,1
3 USB Cable 1
4 Jumper Wires As per required
5 PIR Motion Sensor 1
Theory:
PIR (Passive Infrared) sensor detects the Infrared waves emitted by objects.The IR sensor itself is
housed in a hermetically sealed metal can to improve noise/temperature/humidity immunity. There is
a window made of IR-transmissive material that protects the sensing element. Behind the window are
the two balanced sensors. This whole arrangement is covered with a Fresnel Lens because of which
IR rays in a large area are converged in the IR sensor inside.PIR sensors mostly used in PIR-based
motion detectors. Also, it used in security alarms and automatic lighting applications.
The PIR Motion sensor has three pins:
Pin1 corresponds to the drain terminal of the device, which connected to the positive supply 5V DC.
Pin2 corresponds to the source terminal of the device, which connects to the ground terminal via a
100K or 47K resistor. The Pin2 is the output pin of the sensor. The pin 2 of the sensor carries the
detected IR signal to an amplifier from the
Pin3 of the sensor connected to the ground
Circuit Diagram:
Procedure:
1.Connect the PIR Motion sensor to NodeMCU: VCC to 3.3V, GND to GND,data pin to D7 and LED to
D6.
2. Set up NodeMCU on Arduino IDE: Open Arduino IDE, install necessary platform files for NodeMCU,
and select "NodeMCU 1.0 (ESP-12E Module)" under "Tools" -> "Board."
3. Write Arduino Code: Create a new sketch, paste the code,initialize the sensor.
4. Upload the Code: Click the "Upload" button in Arduino IDE to load the code onto NodeMCU.
5 .Monitor PIR Motion: Open the Serial Monitor in Arduino IDE (Tools -> Serial Monitor), and check
Whether the motion detected by the PIR Motion sensor.
Code:
int Status = 12; // Digital pin D6
int sensor = 13; // Digital pin D7
void setup() {
Serial.begin(9600);
pinMode(sensor, INPUT); // declare sensor as Input
pinMode (Status, OUTPUT); // declare LED as output
void loop() {
long state=digitalRead(sensor);
if(state == HIGH) {
digitalWrite (Status, HIGH); Serial.println("Motion detected!");
delay(1000);
}
else {
digitalWrite (Status, LOW); Serial.println("Motion absent!");
delay(1000);
}
}
Output: After uploading the code,if the motion is detected the LED will glow .
EXPERIMENT-4
GA S S EN S O R A N D B U ZZ E R I N T E RF A C I N G W I T H A R D UI N O
Aim:
To design and implement gas sensor and buzzer interfacing with Arduino.
Apparatus:
S.No Components Quantity
1 NodeMCU 1
2 Breadboard 1
3 USB Cable 1
4 Jumper Wires As per required
5 Gas Sensor 1
6 Buzzer 1
Theory:
The Gas Sensor (MQ2) module is useful for gas leakage detection (home and industry). It is suitable
for detecting H2, LPG, CH4, CO, Alcohol, Smoke or Propane. Due to its high sensitivity and fast
response time, measurement can be taken as soon as possible. The sensitivity of the sensor can be
adjusted by potentiometer. The sensor is actually enclosed in two layers of fine stainless steel mesh
called Anti-explosion network. It ensures that heater element inside the sensor will not cause an
explosion, as we are sensing flammable gases.
It also provides protection for the sensor and filters out suspended particles so that only gaseous
elements are able to pass inside the chamber. The mesh is bound to rest of the body via a copper
plated clamping ring.
Circuit Diagram:
Procedure:
1.Connect the Gas sensor to NodeMCU: VCC to 3.3V, GND to GND,data pin to A0 and Buzzer to D2.
2. Set up NodeMCU on Arduino IDE: Open Arduino IDE, install necessary platform files for NodeMCU,
and select "NodeMCU 1.0 (ESP-12E Module)" under "Tools" -> "Board."
3. Write Arduino Code: Create a new sketch, paste the code,initialize the sensor.
4. Upload the Code: Click the "Upload" button in Arduino IDE to load the code onto NodeMCU.
5 .Monitor Gas Sensor: Open the Serial Monitor in Arduino IDE (Tools -> Serial Monitor), and check
Whether the gas leakage is detected by the gas sensor.
Code:
int buzzer = D2;
int smokeA0 = A0;
// Your threshold value. You might need to change it.
int sensorThres = 600;
void setup() {
pinMode(buzzer, OUTPUT);
pinMode(smokeA0, INPUT);
Serial.begin(9600);
}
void loop() {
int analogSensor = analogRead(smokeA0);
Serial.print("Pin A0: ");
Serial.println(analogSensor);
// Checks if it has reached the threshold value
if (analogSensor > sensorThres)
{
tone(buzzer, 1000, 200);
}
else
{
noTone(buzzer);
}
delay(100);
}
Output:
After uploading the code if the value detected by the gas sensor exceeds the threshold value
then buzzer makes sound.
EXPERIMENT-5
S O UN D D ET EC T I O N S EN S O R US I N G A RD UI N O
Aim:
To design and implement sound detection sensor interfacing with Arduino.
Apparatus:
S.No Components Quantity
1 NodeMCU 1
2 Breadboard 1
3 USB Cable 1
4 Jumper Wires As per required
5 Sound Sensor 1
6 LED 1
7 Resistor 1(10Kohm)
Theory:
The microphone sound sensor, as the name says, detects sound. It gives a measurement of how loud
a sound is. The sound sensor is a small board that combines a microphone (50Hz-10kHz) and some
processing circuitry to convert sound waves into electrical signals. This electrical signal is fed to on-
board LM393 High Precision Comparator to digitize it and is made available at OUT pin.
The sound sensor can be used to detect sound in the environment around it. There are two types of
sound sensor module:
Digital sound sensor module: outputs the digital signal value (ON/OFF)
Analog sound sensor module: outputs both analog and digital signal value.
The sensitivity of digital output can be addjusted by potentiometer. using a built-in
THE DIGITAL SOUND SENSOR PINOUT
The sound sensor includes three pins:
VCC pin:needs to be connected to vcc (3.3V to 5V)
GND pin:needs to be connected to GND (OV)
OUT pin: is an output pin: HIGH if quiet and LOW if sound is detected. This pin needs to be connected
to ESP8266's input pin.
Circuit Diagram:
Procedure:
1.Connect the Sound sensor to NodeMCU: VCC to 3.3V, GND to GND,A0 to A0,D0 to D8,LED positive
to D7 and negative to resistor.
2. Set up NodeMCU on Arduino IDE: Open Arduino IDE, install necessary platform files for NodeMCU,
and select "NodeMCU 1.0 (ESP-12E Module)" under "Tools" -> "Board."
3. Write Arduino Code: Create a new sketch, paste the code,initialize the sensor.
4. Upload the Code: Click the "Upload" button in Arduino IDE to load the code onto NodeMCU.
5 .Monitor Sound Sensor: Open the Serial Monitor in Arduino IDE (Tools -> Serial Monitor), and check
Whether the sound is detected by the sound sensor.
Code:
int soundSensor=5;
int LED 16;
boolean LEDStatus=false;
void setup(){
pinMode (soundSensor, INPUT);
pinMode (LED, OUTPUT);
Serial.begin(9600);
}
void loop() {
int state= digitalRead(soundSensor);
if (state==1) {
if(LEDStatus==false){
LEDStatus =true;
digitalWrite(LED, HIGH);
Serial.println("sound detected ");
}
else{
LEDStatus=false;
digitalWrite(LED, LOW);
}
Output:
After uploading the code,if the sound is detected LED will blinks.
EXPERIMENT-6
O L ED D I S P L A Y US I N G A R D UI N O
Aim:
To interface OLED display to Arduino.
Apparatus:
S.No Components Quantity
1 NodeMCU 1
2 Breadboard 1
3 USB Cable 1
4 Jumper Wires As per required
5 OLED Display 1
Theory:
An OLED (organic light-emitting diode) is used frequently in displaying texts, bitmap images, shapes,
and different types of clocks. They offer good view angles and pixel density in a cost-effective
mannerSSD1306 0.96 inch OLED Display
OLED stands for organic light-emitting diode. Its name shows that it is a flat light emitting technology
that is developed when two organic thin films are connected in series between two electric
conductors. When an electric current is supplied to these conductors then the organic compound is
made which emits the bright light. Typically, one conductor is the transparent conductor between
these two conductors therefore there is no need for any backlight to emits the light. Therefore, this
OLED display has improved image quality, full viewing angle, high brightness, better contrast, wide
color range, low power consumption, more efficient and reliable as compared to a simple LCD
display. It is mainly used in digital display devices such as computer monitors, mobile phones,
handheld games, and televisions screens, etc.
Circuit Diagram:
Procedure:
1.Connect the OLED Display to NodeMCU: VCC to 3.3V, GND to GND,SCL to D1 and SDA to D2.
2. Set up NodeMCU on Arduino IDE: Open Arduino IDE, install necessary platform files for NodeMCU,
and select "NodeMCU 1.0 (ESP-12E Module)" under "Tools" -> "Board."
3. Write Arduino Code: Create a new sketch, paste the code,initialize the sensor.
4. Upload the Code: Click the "Upload" button in Arduino IDE to load the code onto NodeMCU.
5 .Monitor OLED Display:Observe OLED Display in the information specified in the code.
Code:
#include <SPI.h>
#include <Wire.h>
#include <Adafruit_GFX.h>
#include <Adafruit_SSD1306.h>
#define SCREEN_WIDTH 128 // OLED display width, in pixels
#define SCREEN_HEIGHT 64 // OLED display height, in pixels
// Declaration for SSD1306 display connected using I2C
#define OLED_RESET -1 // Reset pin
#define SCREEN_ADDRESS 0x3C
Adafruit_SSD1306 display(SCREEN_WIDTH, SCREEN_HEIGHT, &Wire, OLED_RESET);
void setup(){
Serial.begin(9600);
// initialize the OLED object
if(!display.begin(SSD1306_SWITCHCAPVCC, SCREEN_ADDRESS)) {
Serial.println(F("SSD1306 allocation failed"));
for(;;); // Don't proceed, loop forever
}