0% found this document useful (0 votes)
14 views15 pages

4321iot experiments in tinkercad with code and diagram

The document outlines six experiments involving Arduino and related components, each with specific aims and procedures. Experiments include interfacing LEDs, measuring temperature with sensors, using ultrasonic sensors for distance detection, building a security system with a PIR sensor, and creating a home automation system with ESP8266 and Blynk app. Each experiment provides a program code to achieve the desired functionality.

Uploaded by

babugamer79
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
14 views15 pages

4321iot experiments in tinkercad with code and diagram

The document outlines six experiments involving Arduino and related components, each with specific aims and procedures. Experiments include interfacing LEDs, measuring temperature with sensors, using ultrasonic sensors for distance detection, building a security system with a PIR sensor, and creating a home automation system with ESP8266 and Blynk app. Each experiment provides a program code to achieve the desired functionality.

Uploaded by

babugamer79
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
You are on page 1/ 15

Experiment 1

Aim: To interface LED with Arduino and write a program to turn ON LED for 1 sec after every 2
seconds.
Requirements:
1. Standard 5mm LED
2. One Resistor
3. Arduino Uno microcontroller board (ATmega328p)
4. Jumper wires
Procedure:
Step 1: Open www.wokwi.com in browser and select “Arduino Uno” microcontroller.
Step 2: In the Simulation part, select the above list by clicking “+” symbol, which are specified in above
requirements.
Step 3: By using jumper wires, Connect Anode (A-pin) of LED to digital pin 3 of Arduino microcontroller
through the resistor and Cathode (C-pin) of LED to ground.
Step 4: Write program in “sketch.ino”.

Program:
voidsetup() {

// put your setup code here, to run once:

pinMode(3, OUTPUT);
}

voidloop() {

// put your main code here, to run repeatedly:

digitalWrite(3,HIGH); //we can also write digitalWrite(3,1);

delay(1000);

digitalWrite(3,LOW);//we can also write digitalWrite(3,0);

delay(1000);

}
Output: LED will turn on for 1 sec after every 2 seconds by interfacing LED with Arduino.
Experiment 2
Aim: Use PWN library to operate LED brightness (Pulse Width Modulation)
Requirements:
1. Standard 5mm LED
2. One Resistor
3. Arduino Uno microcontroller board (ATmega328p)
4. Jumper wires
Procedure:
Step 1: Open www.wokwi.com in browser and select “Arduino Uno” microcontroller.
Step 2: In the Simulation part, select the above list by clicking “+” symbol, which are specified in above
requirements.
Step 3: By using jumper wires, Connect Anode (A-pin) of LED to digital pin 3 of Arduino microcontroller
through the resistor and Cathode (C-pin) of LED to ground.
Step 4: Write program in “sketch.ino”.

Program:

int brightness=0;

void setup()
{
pinMode(3, OUTPUT);
}

Void loop ()
{
for ( brightness=0; brightness<=500;
brightness+=5)
{
analogWrite(3, brightness);
}
for( brightness=500; brightness<=0;
brightness-=5)
{
analogWrite(3, brightness);
}
delay(50);

Output:
Experiment 3
Aim: Calculate the ambient temperature using TMP36 on Arduino /DHT 11
Requirements:
1. Arduino Uno microcontroller board (ATmega328p)
2. LM 35
3. USB cable
4. Bread board
5. jumper wires

Procedure:
Step 1: Insert the temperature sensor into your breadboard and connect its pin1 to the supply.
Step 2: Connect its centre pin to the analog pin A0 and the remaining pin3 to GND on the breadboard.
Step 3: Upload the code as given below.
Step 4: Vary the temperature and read the voltage changes.
Step 5: Open the Arduino IDE’s serial monitor to see the results.

Program:

int LM35Pin=A0;
void setup()
{
Serial.begin(9600);}
void loop ()
{int val; int data;
val = analogRead(LM35Pin);
data= (val*5)/10;
Serial.print(“Temp:”);
Serial.print(data);
Serial.println(“C”);
delay(500);
}

Output:
Experiment 4:

Aim: To use an ultrasonic sensor to detect the distance of an object up to 10 metres.

Requirements:
1. Arduino UNO
2. Red LED
3. Green LED
4. HC-SR04 Ultrasonic Sensor
5. Buzzer
6. USB Cable
7. Breadboard

Procedure:
Step1: Insert the Ultrasonic sensor into your breadboard and connect its Echo pin

to the digital pin 2 and the Trigger pin to digital pin 3 of the Arduino.

Step 2: Insert the RED and Green LED into the breadboard.

Step 3: Attach the positive leg (the longer leg) of red LED to signal pin of the Buzzer
via the 220- ohm resistor, and the negative leg to GND.

Step 4: The green LED is connected to digital pin 8 of the Arduino.

Step 5: Upload the code.


Step 6: Observe the LEDs and take some object in front of ultrasonic sensor.
Step 7: Observe the changes in the LED and buzzer sound.
Program:

#define echo 2
#define trig 3
#define outA 8 // Red LED #define outB 9 // Green LED
#define outC 10 // Buzzer
float duration; // time taken by the pulse to return
back float distance; // one way distance travelled
by the pulse
const int intruderDistance = 10; // the minimum
distance up to which the sensor is able to sense any
object
void setup() { pinMode(trig, OUTPUT); pinMode(echo,
INPUT);
pinMode(outA, OUTPUT); digitalWrite(outA, LOW);
pinMode(outB, OUTPUT); digitalWrite(outB, LOW);
pinMode(outC, OUTPUT); digitalWrite(outC, LOW);
Serial.begin(9600);

}
void loop()
{ time_Measurem
ent();
distance = (float)duration * (0.0343) / 2;
// calculate the one way distance travelled
by the pulse Serial.println(distance);
alarm_condition();
}
void time_Measurement()
{ // function to measure the time taken
by the pulse to return back digitalWrite(trig,
LOW);
delayMicroseconds(2); digitalWrite(trig, HIGH);
delayMicroseconds(10); digitalWrite(trig, LOW);
duration = pulseIn(echo, HIGH);
}
void alarm_condition()
{ //function to execute the output commands based on
the sensor input
if(distance<=intruderDistance)
{
digitalWrite(outA,HIGH); digitalWrite(outB,LOW);
analogWrite(outC,200);} else
{

digitalWrite(outA,LOW); digitalWrite (outB, HIGH);


analogWrite (outC,0);
}
}

Output:
Experiment 5:

Aim: Build a security system for home using PIR sensor

Requirements:
1. Arduino UNO
2. Red LED
3. Green LED
4. PIR sensor
5. Buzzer
6. USB Cable
7. Breadboard

Procedure:
Step1: Insert the PIR sensor into your breadboard and connect its digital pin and the

VCC pin to 5V of the Arduino.

Step 2: Insert the RED and Green LED into the breadboard.

Step 3: Attach the positive leg (the longer leg) of red LED to signal pin of the Buzzer
via the 220- ohm resistor, and the negative leg to GND.

Step 4: The green LED is connected to digital pin 8 of the Arduino.

Step 5: Upload the code.


Step 6: Observe the LEDs and take some motion in front of PIR sensor
Step 7: Observe the changes in the LED and buzzer sound.
Program:

Output:
Experiment 6:

Aim: Build a home automation system to operate home appliances ESP 8266 (Wi-Fi Module)

Requirements:
1. ESP8266 – Node MCU
2. Channel relay module
3. Bread board
4. Wires, switches
5 5v power supply
6. Arduino IDE
7. Blynk App

Procedure:
Step1: Download the Blynk app from the App Store or Google Play Store and create an
account.

Step2: Create a new project by clicking the “🔧” icon in the top-right corner of the screen.

Step3: Choose the hardware device you will be using (e.g. Arduino, Raspberry Pi, etc.) and
the connection type (e.g. Wi-Fi, Bluetooth, etc.).

Step4: Check your email for the auth token that was automatically generated and sent to
you by Blynk.

Step5: Copy the auth token (in the email, look for the hyperlink as “here”) and save it for
later usage.

Step6: After creating the project, you will be directed to the main screen where you can
start designing your app’s user interface.

Step7: Click the “+” icon in the top-right corner of the screen to add a new widget.

Choose the type of widget you want to add to your app (e.g. button, slider, gauge, etc.).
Step8: Customize the widget’s properties, such as the label, color, and pin assignment. For
Detailed Configuration settings,

Program:
// wifi controlled home automation using Blynk App & ESP8266
#define BLYNK_TEMPLATE_ID "YourTemplateId" //blynk template ID
#define BLYNK_TEMPLATE_NAME "YourTemplateName " //blynk template name
#define BLYNK_AUTH_TOKEN "4ANo-vG6TpPOvyXdbZgxBBLCVz976NmB" // enter your
blynk auth token

#define BLYNK_PRINT Serial


#include <gpio.h>
#include <ESP8266WiFi.h>
#include <BlynkSimpleEsp8266.h>

char auth[] = BLYNK_AUTH_TOKEN;

char ssid[] = "YouWifiName"; // Your Wifi Name


char pass[] = "YourWifiPasword"; // Your Wifi Password

//in the below code, we have set all values reverse


//For value==1, digitalWrite is "LOW" as the realy module is active "LOW" to
turn device ON.
//For value==0, digitalWrite is "HIGH" as Optocoupler based relay is turned
OFF when HIGH Input is given
BLYNK_WRITE(V1)
{
int value = param.asInt();
Serial.println(value);
if(value == 1)
{
digitalWrite(D0, LOW);
Serial.println("LED ON"); //Setting Digital PIN as LOW to turn ON Device
if relay module is "active low"
}
if(value == 0)
{
digitalWrite(D0, HIGH);
Serial.println("LED OFF");//Setting Digital PIN as HIGH to turn OFF
Device if relay module is "active low"
}
}

BLYNK_WRITE(V2)
{
int value = param.asInt();
Serial.println(value);
if(value == 1)
{
digitalWrite(D1, LOW);
Serial.println("LED ON");
}
if(value == 0)
{
digitalWrite(D1, HIGH);
Serial.println("LED OFF");
}
}

BLYNK_WRITE(V3)
{
int value = param.asInt();
Serial.println(value);
if(value == 1)
{
digitalWrite(D2, LOW);
Serial.println("LED ON");
}
if(value == 0)
{
digitalWrite(D2, HIGH);
Serial.println("LED OFF");
}
}

BLYNK_WRITE(V4)
{
int value = param.asInt();
Serial.println(value);
if(value == 1)
{
digitalWrite(D3, LOW);
Serial.println("LED ON");
}
if(value == 0)
{
digitalWrite(D3, HIGH);
Serial.println("LED OFF");
}
}

void setup()
{
Serial.begin(115200);
Blynk.begin(auth, ssid, pass);
pinMode(D0,OUTPUT); //GPIO 16 (equivalent to PIN 16 of Arduino)
pinMode(D1,OUTPUT); //GPIO 05 (equivalent to PIN 05 of Arduino)
pinMode(D2,OUTPUT);//GPIO 04 (equivalent to PIN 16 of Arduino)
pinMode(D3,OUTPUT);//GPIO 00 (equivalent to PIN 00 of Arduino)
}

void loop()
{
Blynk.run();
}
OUTPUT:

You might also like