Professional Documents
Culture Documents
IOT Lab 3
IOT Lab 3
Title: Interfacing LDR sensor and Relay with Arduino Uno Board.
Connection Diagram:
Fig. 2 Interfacing LDR Sensor and Relay with Arduino Uno Board
Page No 1
IOT Lab 3 Enrollment No: IU2141050017
Program:
void setup()
{
pinMode(LED_BUILTIN, OUTPUT);
}
void loop()
{
int x;
Serial.begin(9600);
x = analogRead(A5);
Serial.println(x);
}
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