You are on page 1of 4

Internet of Things 3171108

LAB 3
AIM:-Digital on/off using IR sensor and LDR Sensor Understand and implement
Interfacing and programming.

CODE:-
#define led 5
#define ir 16
void setup()
{
pinMode(ir,INPUT);// input from IR Sensor, if object is present
pinMode(led,OUTPUT); // connecting LED will glow or else it wont
Serial.begin(9600); // baud rate for India
}
//In case there is no obstacle in range, the output of IR sensor is +5v or logic 1.
//The fact that black color absorbs any kind of radiation can be used to detect a
//black line on white background.
void loop()
{
int data = digitalRead(ir);// reading IR sensor data
if(data == 1 ){
digitalWrite(led,HIGH);
}
if(data == 0){
digitalWrite(led,LOW);
}
Serial.print("Sensor Data - ");
Serial.println(data);
// delay(1000);
}

PARTH PATEL 180420111043


Internet of Things 3171108

OUTPUT:-

PARTH PATEL 180420111043


Internet of Things 3171108

CODE:-
#define led 5
void setup()
{
pinMode(A0,INPUT);
Serial.begin(9600); // baud rate for India
pinMode(led,OUTPUT);
}
void loop()
{
int data = analogRead(A0);
Serial.println(data);
if(data<50){
digitalWrite(led,HIGH);
}
else{
digitalWrite(led ,LOW);
}
//delay(500);
}
OUTPUT:-

PARTH PATEL 180420111043


Internet of Things 3171108

PARTH PATEL 180420111043

You might also like