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

2CE705/2IT705 Internet of Things

PRACTICAL –3_Solution

Aim: - Arduino architecture and basic programming.

pinMode()
digitalRead()
digitalRead()
delay()
analogRead()
analogWrite()
map()

Experiment

1. Working with LED


a. LED ON

Code:
#define LED 12
void setup()
{
pinMode(LED,OUTPUT);
}

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

void loop()
{
digitalWrite(LED,HIGH);

b. LED ON/OFF using PUSH button

Code

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

void loop()
{
analogWrite(A0,255);
}

c. LED Blinking

Code

#define LED 12
void setup()
{
pinMode(LED,OUTPUT);
}

void loop()
{
digitalWrite(LED,HIGH);
delay(1000);
digitalWrite(LED,LOW);
delay(1000);

d. RGB LED

Code
#define RED 1
#define GREEN 2
#define BLUE 3

void setup()
{

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

pinMode(RED,OUTPUT);
pinMode(GREEN,OUTPUT);
pinMode(BLUE,OUTPUT);

}
void loop()
{
digitalWrite(RED,HIGH);
digitalWrite(GREEN,LOW);
digitalWrite(BLUE,LOW);
delay(1000);
digitalWrite(RED,LOW);
digitalWrite(GREEN,HIGH);
digitalWrite(BLUE,LOW);
delay(1000);
digitalWrite(RED,LOW);
digitalWrite(GREEN,LOW);
digitalWrite(BLUE,HIGH);
delay(1000);
}

2. Increase / Decrease LED Brightness


Code

#define pin 3
int i=0;
int step = 5;
void setup()
{
pinMode(pin,OUTPUT);
}
void loop()
{
i=0;
while ( i <= 255 ){
analogWrite(pin, i );
delay(50);
i = i + step;
}
while ( i > 0 ){
analogWrite(pin, i );
delay(50);
i = i - step;
}

3. Increase / Decrease LED Brightness using potentiometer


Code

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

const int analogInPin = A0; // Number of the pin connected to the


photoresistor
const int analogOutPin = 3; // Number of the pin connected to the LED

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


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

void setup() {
pinMode(analogOutPin, OUTPUT);
pinMode(analogInPin, INPUT);
}

void loop() {
sensorValue = analogRead(analogInPin);
outputValue = map(sensorValue, 0, 1023, 0, 255);
analogWrite(analogOutPin, outputValue);
}

CE/IT Department

You might also like