0% found this document useful (0 votes)
78 views

Solution LAB4 IOT

This document describes 3 experiments using an Arduino board to read sensor input and control outputs. The first experiment uses a potentiometer and analog pin to adjust an LED's brightness and displays the voltage on the serial monitor. The second reads the temperature from an analog pin and displays it. The third reads temperature and uses the value to control the color of an RGB LED by writing different pins high or low. The code examples show how to set up analog input and output pins and print values to the serial monitor.

Uploaded by

kirit
Copyright
© © All Rights Reserved
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
78 views

Solution LAB4 IOT

This document describes 3 experiments using an Arduino board to read sensor input and control outputs. The first experiment uses a potentiometer and analog pin to adjust an LED's brightness and displays the voltage on the serial monitor. The second reads the temperature from an analog pin and displays it. The third reads temperature and uses the value to control the color of an RGB LED by writing different pins high or low. The code examples show how to set up analog input and output pins and print values to the serial monitor.

Uploaded by

kirit
Copyright
© © All Rights Reserved
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 3

2CE705/2IT705 Internet of Things

PRACTICAL –4_Solution

Aim: - Arduino architecture and basic programming.

 Serial.begin()
 Serial.end()
 Serialread()
 Serialwrite()
 Serial.print()
 Serial.println()
 Serial.available()

Experiment

1. Increase and decrease the brightness of LED using potentiometer and


display the voltage level on serial monitor

Code:

const int analogInPin = A0; // pin connected to the photoresistor


const int analogOutPin = 9; //pin connected to the LED

int sensorValue = 0; // Value read by the photoresistor


int outputValue = 0; // Value sent to the LED

void setup() {

Serial.begin(9600);
pinMode(analogOutPin, OUTPUT);
pinMode(analogInPin, INPUT);
}

void loop() {
sensorValue = analogRead(analogInPin);
outputValue = map(sensorValue, 0, 1023, 0, 255);
analogWrite(analogOutPin, outputValue);
Serial.print("sensor = " );
Serial.print(sensorValue);
Serial.print("\t output = ");
Serial.println(outputValue);
}

CE/IT Department
2CE705/2IT705 Internet of Things

2. Read the current temperature of room and display it on serial monitor

Code:

float tmp;
#define PIN A0
void setup()
{
Serial.begin(9600);
pinMode(PIN,INPUT);
}
void loop()
{
tmp = analogRead(PIN);
tmp = tmp * 5000/1024;
tmp = tmp/10;
tmp = tmp - 50;
Serial.print("Temperature=");
Serial.println(tmp);
}

3. Read the current temperature of room and ON the RGB Led with specific
colour according to current temperature value

Code:

float tmp;
#define PIN A0
#define R 1
#define G 3
#define B 5

void setup()
{
Serial.begin(9600);
pinMode(PIN,INPUT);
pinMode(R,OUTPUT);
pinMode(G,OUTPUT);
pinMode(B,OUTPUT);
}
void loop()
{
tmp = analogRead(PIN);
tmp = tmp * 5000/1024;
tmp = tmp/10;
tmp = tmp - 50;
Serial.print("Temperature=");
Serial.println(tmp);
if(tmp>50)//if temperature above of 25 degrees

CE/IT Department
2CE705/2IT705 Internet of Things

{
digitalWrite(R,HIGH);
digitalWrite(G,LOW);
digitalWrite(B,LOW);
Serial.println("RED");

}
else if(tmp>=0&&tmp<=50)//if temperature is under 23 degrees
{
digitalWrite(R,LOW);
digitalWrite(G,HIGH);
digitalWrite(B,LOW);
Serial.println("GREEN");

}
else
{
digitalWrite(R,LOW);
digitalWrite(G,LOW);
digitalWrite(B,HIGH);
Serial.println("BLUE");

}
}

CE/IT Department

You might also like