0% found this document useful (0 votes)
112 views4 pages

Practical - 3 - Solution: Pinmode Digitalread Digitalread Delay Analogread Analogwrite Map

This document discusses Arduino programming and experiments with LEDs. It presents code to control an LED by turning it on and off, blinking it, and changing the color of an RGB LED. Additional code is provided to gradually increase and decrease the brightness of an LED, and to control the brightness of an LED using the value read from a potentiometer. The goal is to demonstrate basic Arduino functions like pinMode, digitalRead, digitalWrite, analogRead, analogWrite and map.

Uploaded by

kirit
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
112 views4 pages

Practical - 3 - Solution: Pinmode Digitalread Digitalread Delay Analogread Analogwrite Map

This document discusses Arduino programming and experiments with LEDs. It presents code to control an LED by turning it on and off, blinking it, and changing the color of an RGB LED. Additional code is provided to gradually increase and decrease the brightness of an LED, and to control the brightness of an LED using the value read from a potentiometer. The goal is to demonstrate basic Arduino functions like pinMode, digitalRead, digitalWrite, analogRead, analogWrite and map.

Uploaded by

kirit
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 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