Download as pdf or txt
Download as pdf or txt
You are on page 1of 3

IOT Lab 3 Enrollment No: IU2141050017

Title: Interfacing LDR sensor and Relay with Arduino Uno Board.

Connection Diagram:

Fig. 1 Interfacing LDR Sensor with Arduino Uno Board

Fig. 2 Interfacing LDR Sensor and Relay with Arduino Uno Board

Page No 1
IOT Lab 3 Enrollment No: IU2141050017

Program:

Program of LDR with Arduino Uno Board

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

void loop()
{
int x;
Serial.begin(9600);
x = analogRead(A5);
Serial.println(x);
}

Program of LDR and Relay with Arduino Uno Board

void setup()

{
pinMode(A5, INPUT);
pinMode(13, OUTPUT);
Serial.begin(9600);
}

void loop()

{
int x = analogRead(A5);
if(x<300) {
digitalWrite(13, HIGH);
}
else {
digitalWrite(13, LOW);
}

Function Description:

• Serial.begin: sets the band rate for serial data communication. The band rate signifies the data
rate in bits per second. The default band rate in Arduino is 9600 bps (bits per second)
• Serial.println: Prints data to the serial port as human-readable ASCII text. This command can
take many forms. Numbers are printed using an ASCII character for each digit. Floats are
similarly printed as ASCII digita, defaulting to two decimal places. Bytes are sent as a single
character. Character and strings are sent as it is.
Page No 2
IOT Lab 3 Enrollment No: IU2141050017

• analogRead: The analogRead() function reads the value from the specified analog pin present on
the particular Arduino Board.

Faculty Signature

Page No 3

You might also like