4321iot experiments in tinkercad with code and diagram
4321iot experiments in tinkercad with code and diagram
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() {
pinMode(3, OUTPUT);
}
voidloop() {
delay(1000);
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:
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.
#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
{
Output:
Experiment 5:
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
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.
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
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: