MOHIT(2317707) IOT file-1
MOHIT(2317707) IOT file-1
PracticalFile
Subject:IOTandBlockchainTechnologyLaboratory Subject
Code: PGCA1968
SubmittedBy: SubmittedTo:
Akhil Ms. Harpreet Kaur
2317651 (AssistantProfessor)
CHANDIGARHBUSINESSSCHOOLOF
ADMINISTRATION
INDEX
Aim:FamiliarizationwithArduino/RaspberryPiandperformnecessarysoftwareinstallation..
The Raspberry pi is a single computer board with credit card size that can be used for many tasks that your
computer does, like games, word processing, spreadsheets and also to play HD video. It was established by the
Raspberry pi foundation from the UK. It has been ready for public consumption since 2012 with the idea of
making a low-cost educational microcomputer for students and children. The main purpose of designing the
raspberry pi board is, to encourage learning, experimentation and innovation for school level students. The
raspberrypi board is a portable and low cost. Maximum of theraspberrypi computers is used in mobilephones.
RaspberryPiTechnology
The raspberry pi comes in two models, they are model A and model B. The main difference between model A
and model B is USB port. Model a board will consume less power and that does not include an Ethernet port.
But, the model B board includes an Ethernet port and designed in china. The raspberry pi comes with a set of
open source technologies, i.e. communication and multimedia web technologies. In the year 2014, the
foundation of the raspberrypi board launched the computer module that packages a model B raspberrypi board
into module for use as a part of embedded systems, to encourage their use.
RaspberryPiHardwareSpecifications
The raspberry pi board comprises a program memory (RAM), processor and graphics chip, CPU, GPU,Ethernet
port, GPIO pins, Xbee socket, UART, power source connector. And various interfaces for other external
devices. It also requires mass storage, for that we use an SD flash memory card. So that raspberry pi board will
boot from this SD card similarly as a PC boots up into windows from its hard disk.
Essential hardware specifications of raspberry pi board mainly include SD card containing Linux OS, US
keyboard, monitor, power supply and video cable. Optional hardware specifications include USB mouse,
powered USB hub, case, internet connection, the Model A or B: USB WiFi adaptor is used and internet
connection to Model B is LAN cable.
Memory
The raspberry pi model aboard is designed with 256MB of SDRAM and model B is designed with
51MB.Raspberry pi is a small size PC compare with other PCs. The normal PCs RAM memory is available in
gigabytes. But in raspberry pi board, the RAM memory is available more than 256MB or 512MB
CPU(CentralProcessingUnit)
The Central processing unit is the brain of the raspberry pi board and that is responsible for carrying out the
instructions of the computer through logical and mathematical operations. The raspberry pi uses ARM11 series
processor, which has joined the ranks of the Samsung galaxy phone.
GPU(GraphicsProcessingUnit)
The GPU is a specialized chip in the raspberry pi board and that is designed to speed up the operation of image
calculations. This board designed with a Broadcom video core IV and it supports OpenGL
1
EthernetPort
GPIOPins
The general purpose input & output pins are used in the raspberry pi to associate with the other electronic
boards. These pins can accept input & output commands based on programming raspberry pi. The raspberry pi
affords digital GPIO pins. These pins are used to connect other electronic components. For example, you can
connect it to the temperature sensor to transmit digital data.
XBeeSocket
Thepowersourcecableisasmallswitch,whichisplacedonsideoftheshield.Themainpurposeofthepower source
connector is to enable an external power source.
UART
Display
The connection options of the raspberry pi board are two types such as HDMI and Composite.Many LCD and
HD TV monitors can be attached using an HDMI male cable andwith a low-cost adaptor. The versions
ofHDMIare 1.3 and 1.4 are supported and 1.4 version cable is recommended. TheO/Ps of the RaspberryPi audio
and video through HMDI, but does not support HDMI I/p. Older TVs can be connected using composite video.
When using a composite video connection, audio is available from the 3.5mm jack socket and can be sent to
your TV. To send audio to your TV, you need a cable which adjusts from 3.5mm to double RCA connectors.
The Raspberry Pi board is a Broadcom (BCM2835) SOC (system on chip) board. It comes equipped with an
ARM1176JZF-S core CPU, 256 MB of SDRAM and 700 MHz,. The raspberrypi USB 2.0 ports use only
external data connectivity options. The board draws its power from a micro USB adapter, with min range of 2.
Watts (500 MA). The graphics, specialized chip is designed to speed up the operation of image calculations.
This is in built with Broadcom video core IV cable that is useful if you want to run a game and video through
your raspberry pi.
2
ModelARaspberryPi Board
3
Practical:2
Aim: To interface LED/Buzzer with Arduino/Raspberry Pi and write a program to turn ON LED for 1
sec after every 2 seconds
Python is the Pi’s recommended programming language, but Linux is its recommended operating system.
Nearly every flavor of OS that works on Raspberry Pi—Raspbian, Pidora and more—isa riff on the Linux
kernel.
GettingStartedWithRaspberryPi
Raspberry Pi owes its low price tag to advances in integrated chips. Instead of having a CPU, a GPU,a USB
controller,and memoryeachontheirown individualchips,RaspberryPiusesa system-on-a-chipwithallthose
components on a single chip.
Without a lot of chips to take up space, the Pi itself can consist of a printed circuit boardwhich boots up froman
SD memory card. So it’s not just cheap, it’s simple, too.
Still, the $35 price tag is a bit misleading. You can’t just buy a Raspberry Pi and expect it to work right out of
the box. Here are the accessories you’ll need to get up and running:
● A power supply. Raspberry Pi doesn’t come with one, so you’ll need a micro USB compatible cable in
order to plug it into the wall.
● A case. There’s no official one yet, so I put mine in this pink onefrom Adafruit. Unfortunately, despite
what you may have heard, it does not fit in an Altoids tin.
● An HDMI cable or RCA video lead. You can’t use your Pi without a visual display. You can either plug
it into a computer monitor with HDMI input using an HDMI cable, or youcan plug it into an analogue
TV with a standard RCA composite video lead.
● A USB mouse and keyboard. Or else how will you interact with the Pi? Any wired or wireless mouse
and keyboard should do; I’m using wireless Logitech products for both.
● AnSDmemorycard.You’llneedonetobootupthePi.TheRaspberryPifoundationrecommendsat
4
least4gigstostart,butas manyas32ifyou want.
● A primary computer. I didn’t get that you can’t just get the Pi running without already owning another
computer, Mac or PC. Hopefully you already have one of these, or this project just got a lot more
expensive.
● AnSDmemorycardreader.TheRaspberryPi doesn’t need this, but your primarycomputerdoes so you can
transfer installations from it to the Pi. A lot of computers come with a built-in card reader, but if yours
doesn’t, you might want to invest in one.
● Put your Raspberry Pi in its case. Unless it’s very customized, it should continue to have holes in it for
all of the Pi’s inputs.
● Put the Pi aside and go to your primary computer. Insert your SD card and format it according to
theFoundation’sdirections.This will install arecoveryprogram on it so you can save your card even if you
break it with your tinkering.
● Download NOOBSon your primary computer. Short for New Out Of Box Software, it’s the Raspberry
Pi Foundation’s fittingly named distro for first-time Pi users. A distro is a package installation of Linux
and its associated software.
● LoadyourNOOBSdownloadonto thenewlyformattedSD card.
● Time to get started with the Raspberry Pi. Slide the SD card into the underside of the Raspberry Pi, and
make sure it’s oriented correctly; it’d be bad to break your Pi before you turn it on!
● Connectittothepower supply,monitor,keyboard,and mouse.
● The Raspberry Pi will boot up and take you the NOOBS screen. If it doesn’t, check your power supply
and HDMI cables and make sure they’re secure.
● Select an OS to install. If you select the default Raspbian, recommended for beginners, Adafruit has a
great tutorialon the process. This install will take a while (20 minutes for me) so this is a good time to go
do something else.
● Once the file copies, you’ll get a notice that says, “Image applied successfully.” Press return, and the Pi
will reboot. Now it will boot into the operating system’s graphical user interface, which looks a lot like
Windows 98.
5
A word of caution, however, from somebody who already made this mistake: don’t delete the NOOBS copyyou
downloaded on your primary computer. My husband and I wiped the Pi twice (and installed operating systems
three times) in one night, so I know it saves time to have everything ready onyour computer in case you want to
start fresh for any reason.
Pi ProjectTutorialsforBeginners
With 512 MB on the Model B, Raspberry Pi isn’t the strongest computer in the world, but it’s still powerful
enough for any project a beginner can think up.
PrintServer
This is the tutorial we used, so I can vouch for its ease of use. It makes use of CUPS (Common UNIX Printing
System)and basicallyall you haveto do is install it on yourSD card and then teach RaspberryPi theaddress of
your printer.
XMBCMediaCenter
This seems to be one of the most popular uses of a Raspberry Pi. Since it is capable of running XMBC, a
program that organizes all of your movies, TV, music, and more into one easy-to-use cloud-based corral, a Pi
makes a perfect hub for streaming your media over your network.
Sure, you could sit around playing Minecrafton your Pi, but you could also fulfill your secret dream of
becoming a video game developer. Programmer Andy Balaam made a tutorial on the topic so thorough,
ittakes threehours to watchall of it.
AdesktopcomputerbuiltwithaRaspberryPi Create
an Information Kiosk
Brendan Nee was sick of arriving late for buses, so he programmed his Pi to display real-time arrivalpredictions
for transit around his house. His step-by-step instructions are great for San Franciscans, but if you live
somewhere else you’ll need to configure for another transit system.
6
BuildaPiPC
You’ve already got the monitor, keyboard, and mouse for your Pi. Why not go the rest of the way and turn it
into aself-containedcomputer? MikeDavis’s tutorial shows you howto attach thePi to theback of themonitor to
create a compact desktop PC.
TimeLapseDolly
AffordableBitcoinMiningRig
Insteadofbuyinga$4,000plusBitcoinminer,youcansetupyourRaspberryPitodoitforjust
$83.However, giventheamountofenergyrequiredtomineBitcoins,wehighlydoubt you’llgetrich offofa Raspberry
Pi’s diminutive mining power.
SolarPoweredPi
WebServer
Design your first website, and get it online, too, by turning your Raspberry Pi into your own home Web server.
Solongas you don’texpect yoursiteto getloads oftraffic, you canhavethePihostitinsteadofa priceyonline host.
7
Practical:3
AIM:InterfacingRainSensingAutomaticWiper System.
PracticalObjectives:
1. Sensetheavailable networks usingArduino.
COMPONENTSREQUIRED:
1. WiFiModuleorESP8266 Module.
2. Connectingcable orUSBcable.
ALGORITHM:
STEP1: Starttheprocess.
STEP2:Start->ArduinoIDE-1.8.8
STEP3:ThenenterthecodinginArduinoSoftware.STEP4:Compilethecodingin ArduinoSoftware. STEP 5:
Connect the USB cable to WiFi module.
STEP6:Selecttools->selectboard->ModulenodeMch.0.9CEESP modules->select port.
STEP7:UploadthecodinginESPModulenodeMch.0.9CEandopenserialmonitortoviewtheavailable networks.
STEP 8: Stopthe process.
BLOCKMODULE:
8
CODING:
#include<ESP8266WiFi.h>voidsetup(){Serial.begin(115200);WiFi.mode(WIFI_STA);
WiFi.disconnect(); delay(100); Serial.println("Setup done");
}
voidloop(){Serial.println("scanstart");intn=WiFi.scanNetworks();Serial.println("scandone");if(n==0)
{
Serial.println("nonetworksfound");
}else { Serial.print(n);
Serial.println("networks found"); for(inti =0;i<n;
++i){Serial.print(i+1);Serial.print(": ");
Serial.print(WiFi.SSID(i));Serial.print("(");Serial.print(WiFi.RSSI(i));Serial.print(")");
Serial.println((WiFi.encryptionType(i) == ENC_TYPE_NONE) ? " " : "*");delay(10);
}}
Serial.println("");delay(5000);
}
OUTPUT:
RESULT:
Thusthe output forsensingtheavailablenetworks usingArduino has successfullyexecuted.
9
Practical:4
Aim:ToInterfaceDHT11UsingArduinoUnoboardanduploadsensordatatoCloud.
.
Apparatus:
Hardware Procedure:
● LCDpins connectedto ArduinoUno pin 2,3,4, 5,6,and 7.
● DHT11pin connectedto the10 pinof Arduino board.
● Wifimodule pins RX &TXare connected to 8 and 9 pin of Arduino (RX=8, TX=9).
● USBconnector is connected toArduino Uno to monitor.
● PlaceWifiModulein IOTdevelopmentBoard.
● Connectthe12V powersupplyto development board.
● Powerjackisconnected totheArduino Uno.
● Checktheoutputfromthedevelopmentboard.
SoftwareProcedure:
1. ClickonArduinoIDE
2. Clickon file
3. Clickon New
4. WriteaProgramasper circuitPin connections
5. Clickon Save
6. CreateanAccountinThingsSpeak,thencreate achannel.
10
7. Goto APIkeysin thatChannel and thencopy“WriteAPIkey”.
8. Goto Arduino codeandpaste WriteAPIkey.
9. Giveyour mobilehotspot nameand passwordin Arduino code.
10. Clickon save&ClickonVerify.
11. Click on Upload the codeinto Arduino Uno byusingUSBcable.
12. AfterthatopenthingsSpeakaccountand clickonprivateview
13. DHT11SensordatawillbeuploadedanditwillbeshownasgraphinPrivateviewonThingsSpeak account.
Program:
#include<dht.h>
#include<LiquidCrystal.h>#include<SoftwareSerial.h>LiquidCrystallcd(2,3,4,5,6,7); SoftwareSerialwifi(8,
9); // TX, RX
String apiKey = "TRNIC1L9BXBXT322"; ///WriteAPIKeydhtDHT;
#define DHT11_PIN 10const int buzzer = 13;
voidsetup(){lcd.begin(16,2);
pinMode(buzzer,OUTPUT);digitalWrite(buzzer,0);project_Name();Serial.begin(9600);
Serial.println("AT");delay(1000);Serial.println("AT+CMGF=1");delay(1000);
Serial.println("AT+CNMI=2,2,0,0,0"); delay(1000);
lcd.setCursor(0,0); lcd.print("WiFi module ");lcd.setCursor(0,1); lcd.print("Initilizing ");
wifi.begin(115200); wifi.println("AT+RST"); delay(4000);
wifi.println("AT+CWMODE=3");delay(4000);wifi.print("AT+CWJAP=");wifi.write('"');
wifi.print("STTMANI"); wifi.write('"');
wifi.write(',');
wifi.write('"');wifi.print("hailucky123,./");wifi.write('"');wifi.println();delay(1000);lcd.setCursor(0,0);
lcd.print("WiFi module. "); lcd.setCursor(0,1); lcd.print("Initilized ");
delay(1000);lcd.clear();
}
void loop()
{
intchk =DHT.read11(DHT11_PIN);
//SendWiFi_Data();
//delay(1000); lcd.setCursor(0,0); lcd.print("Temperature: "); lcd.setCursor(0,1);
lcd.print("Humidity: ");lcd.setCursor(12,0);lcd.print(DHT.temperature);lcd.setCursor(9,1);
lcd.print(DHT.humidity); delay(500);
/*TempuratureDataProcess*/if(DHT.temperature>45)
{
buzzer_sound();
}
/*HumidityData Process*/ if(DHT.humidity<30)
11
{
buzzer_sound();
}
lcd.setCursor(15,1);lcd.write(0x20);SendWiFi_Data();delay(1000);}
void SendWiFi_Data(){
Stringcmd="AT+CIPSTART=\"TCP\",\"";cmd+="184.106.153.149";//api.thingspeak.comcmd+= "\",80";
wifi.println(cmd);
delay(1500);
StringgetStr="GET/update?api_key=";getStr
+=apiKey;
getStr+="&field1=";
getStr+=String(DHT.temperature);
getStr+="&field2=";
getStr+=String(DHT.humidity); getStr+=
"\r\n\r\n";
//senddata length
cmd= "AT+CIPSEND=";
cmd+=String(getStr.length());wifi.println(cmd); delay(1500);wifi.println(getStr);delay(1000);
}
voidbuzzer_sound()
{
digitalWrite(buzzer,HIGH);delay(600);digitalWrite(buzzer,LOW);delay(400);digitalWrite(buzzer, HIGH);
delay(600); digitalWrite(buzzer, LOW); delay(400);
}
voidproject_Name(){lcd.setCursor(0,0);lcd.print("
ESP8266 ");
lcd.setCursor(0,1);lcd.print("Interfacing");delay(3000);lcd.clear();
}
RESULT:
DHT11 sense the surrounding temperature and measure humidity in surrounding air that temperature and
humidityshown by LCD display and Sensor data will be successfully uploaded on Things Speak account.
12
Practical:5
AIM:TointerfacemotorusingrelaywithArduino/RaspberryPiandwriteaprogramtoturn ON motor
when push button is pressed.
PracticalObjectives:
BLOCKMODULE:
13
CODING:
constinttrigPin=9;constinttechoPin=10;longduration;intdistance;void setup()
{
pinMode(trigPin,OUTPUT);//SetsthetrigPinasanOutputpinMode(echoPin,INPUT);//SetstheechoPin as an
Input Serial.begin(9600); // Starts the serial communication
}
void loop()
{
digitalWrite(trigPin,LOW);//ClearsthetrigPindelayMicroseconds(2);digitalWrite(trigPin,HIGH);//Sets the
trigPin on HIGH state for 10 micro secondsdelayMicroseconds(10); digitalWrite(trigPin, LOW); duration
=pulseIn(echoPin, HIGH);
distance=duration*0.034/2;//distance=(Timex SpeedofSoundinAir(340m/s))/2
Serial.println(distance);delay(1000);
}
OUTPUT:
RESULT:
Thustheoutputformeasuringthedistanceusingultrasonicsensorand LEDblinkusingArduinohas successfully
executed.
14
Practical:6
AIM:TointerfaceBluetoothwithArduino/RaspberryPiandwriteaprogramtosend sensordatato
Smartphone using Bluetooth.
PracticalObjectives:
1. Detectthevibrationof anobjectusingArduino.
COMPONENTS REQUIRED:
1. Vibrationsensor
2. Jumper wires
3. USBcable
ALGORITHM:
STEP1:Start theprocess.STEP 2:
StartArduino.1.8.8.
STEP3: Then enterthecodinginArduino software.
STEP4: InArduinoboard,connectvcctopowersupply5Vand connectdotoanalogpinA0 andconnect gnd to
ground gnd using jumper wires.
STEP5:Connectthearduinoboard withtheUSBcabletothe system.
STEP6:Selecttools Selectboard ArduinoNanogndSelectprocessor ATmega823pandthenselect the port.
STEP7: Upload the codingto theArduino board.
STEP8:Thentheoutputwillbedisplayedintheserialmonitor. STEP
9: Stopthe process.
BLOCKDIAGRAM:
15
CODING:
IntledPin=13; Intvib=A0;voidsetup()
{
pinMode(ledPin,OUTPUT);
pinMode(vib, INPUT);//setEPinputformeasurementSerial.begin(9600); //initserial9600
}
void loop()
{
longmeasurement=pulseIn(vib,HIGH);delayMicroseconds(50);Serial.print("VIB:v001:hertz:"
);
Serial.println(measurement);
}
OUTPUT:
RESULT:
Thustheoutputfordetectingthevibrationsofan objectwithvibrationsensorusingArduino hasbeen successfully
16
Practical:7
PracticalObjectives:
1. CONNECTWITHTHEAVAILABLEWI-FIUSINGARDUINO
COMPONENTS REQUIRED:
1. ESP8266moduleorWi-Fi module
2. Connectingcables orUSBcables
ALGORITHM:
STEP1:Starttheprocess.STEP2:StartArduinoIDE1.8.8. STEP3:
Include the file directory ESP 8266 in Arduino.
STEP4:ThenenterthecodingtoWi-FimoduleorESP8266module.STEP5:Thenenterthecodingin Arduino
software.
STEP6:ConnecttheUSBcabletotheWi-FimoduleandtheArduinoconnectedsystemwithavailable network.
STEP7:SelecttoolsSelectboardNodeMCU0.9CESP-12moduleandthenSelectPort.STEP8:Uploadthe coding to
ESP 8266 module and open serial monitor to Viewthe available network connects IP address.
STEP9: Stopthe process.
BLOCKDIAGRAM:
17
CODING:
#include<ESP8266WiFi.h>//IncludetheWi-Fi library
constchar*ssid="Error";//TheSSID(name)oftheWi-Finetwork youwanttoconnecttoconstchar* password =
"networkerror"; // The password of the Wi-
Finetworkvoidsetup(){
Serial.begin(115200);//StarttheSerialcommunicationtosendmessagestothecomputerdelay(10);
Serial.println('\n');
WiFi.begin(ssid,password);//ConnecttothenetworkSerial.print("Connectingto");Serial.print(ssid);
Serial.print(“...")
int i
=0;
while(WiFi.status()!=WL_CONNECTED){//WaitfortheWi-Fitoconnectdelay(1000);Serial.print(++i);
Serial.print(' ');
}
voidloop(){Serial.println('\n');Serial.println("Connectionestablished!")
Serial.print("IPaddress:\t");
Serial.println(WiFi.localIP());//Sendthe IPaddressoftheESP8266tothecomputer
}
}
RESULT:
Thustheoutput forconnectingwiththeavailable Wi-Fi usingArduino has beensuccessfully
18
Practical:8
AIM:TowriteaprogramtosenseafingerwhenitisplacedontheboardArduino
PracticalObjectives:
BLOCKDIAGRAM:
19
CODING:
intLed=13 ;//defineLEDInterface
intbuttonpin=7;//defineMetalTouchSensor Interfaceintval;//define numericvariablesval void setup
()
{
Serial.begin(9600);
pinMode(Led,OUTPUT);//defineLEDasoutputinterfacepinMode(buttonpin,INPUT);//define metal
touch sensor output interface
}
void loop ()
{
val=digitalRead(buttonpin);
//Serial.println(val);
if(val==1)// Whenthe metaltouchsensor detectsasignal,LED flashes
{
digitalWrite(Led,HIGH);Serial.println(val);delay(1000);
}
else
{
digitalWrite(Led,LOW);Serial.println(val);delay(1000);
}
}
OUTPUT:
RESULT:
Thustheoutputforsensinga finger whenitis placedinboardArduino
20
Practical:9
AIM:WriteaprogramonArduino/RaspberryPitouploadandretrievetemperatureandhumidity data to
and from thing speak cloud.
PracticalObjectives:
1.TemperaturenotificationusingArduino.
COMPONENTSREQUIRED:
1. Temperatureandhumiditysensor.
2. Jumper wires
3. ConnectivitycableorUSBcable.
ALGORITHM:
STEP1:Start theprocess.STEP 2:
Start Arduino1.8.8
STEP3: IncludetheDHTlibraryto theArduinosoftware.STEP4:ThenenterthecodinginArduino software.
STEP5: Completethecodingin Arduino.
STEP6: InArduinoboardconnectVCCtothepowersupply5Vand connectSIGtodigitalsignalDTand connect SND
to ground GND using jumper wires.
STEP7:ConnectthearduinoboardwithUSBcabletothesystem.STEP8:SelecttoolsSelected.STEP9: Upload the
coding to arduino board. Then the output will bedisplayed in the serial monitor.
STEP 10: Stopthe process.
BLOCKDIAGRAM:
21
CODING:
#include<dht.h>
#definedht_apin A0 // AnalogPin sensoris connected to dht DHT;void setup()
{
pinMode(A0,INPUT); Serial.begin(9600); delay(500);
Serial.println("DHT11Humidity&temperatureSensor\n\n");delay(1000);
}
void loop()
{
DHT.read11(dht_apin);Serial.print("THS:th01:None:");Serial.print(DHT.humidity);Serial.print("%,");
//Serial.print("temperature= ");Serial.print(DHT.temperature);Serial.println("degC");
delay(2000);//Wait 5 seconds before accessing sensor again.
}
OUTPUT:
RESULT:
Thusthe outputto gettemperaturenotificationusingArduinohas successfullyexecuted.
22
Practical:10
PracticalObjectives:
1. LDR to varythe light intensityofLEDusingArduino.
ALGORITHM:
STEP1:Starttheprogram.
STEP2:Start→Arduino1.88[IDE].
STEP3:EnterthecodinginArduino software.STEP4:Compile thecodingin theArduino software.
STEP5:FromLDRlightsensormodule,connectVCCtopowersupply5VandconnecttodigitalpinD3and connect
GND to ground gnd using jumper wires to arduino board.
STEP6:ForLED,connectDtodigitalpinD2andconnectGNDtogroundGNDusingjumperwiresto arduino board.
STEP7:Showthevarianceoflightsintensityin LEDweuseLDRlightsensormodule.STEP8:Stopthe process.
BLOCKDIAGRAM
CODING:
constintldr_pin=3;constintled_pin=2;voidsetup(){pinMode(ldr_pin,INPUT);pinMode(led_pin, OUTPUT);
Serial.begin(9600);
}
void loop(){
if(digitalRead(ldr_pin)==1){digitalWrite(led_pin, HIGH);
}
else{
digitalWrite(led_pin, LOW);
}
Serial.println(digitalRead(ldr_pin));delay(100);
}
23
OUTPUT:
RESULT:
ThustheoutputforLDRtovarythelightintensityofLEDusingArduinohas successfully executed.
24