[go: up one dir, main page]

0% found this document useful (0 votes)
85 views33 pages

Iot Lab Record

The document describes a project to make an RGB LED glow with different colors. The goal is to connect an RGB LED to an Arduino and write a program to light up the red, green and blue colors separately for 0.1 seconds each with 0.2 second delays in between. The program uses digital pins 9, 10 and 12 to control the red, green and blue channels of the RGB LED respectively, setting each pin high for 0.1 seconds then low for 0.2 seconds to light up each color in sequence.
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
85 views33 pages

Iot Lab Record

The document describes a project to make an RGB LED glow with different colors. The goal is to connect an RGB LED to an Arduino and write a program to light up the red, green and blue colors separately for 0.1 seconds each with 0.2 second delays in between. The program uses digital pins 9, 10 and 12 to control the red, green and blue channels of the RGB LED respectively, setting each pin high for 0.1 seconds then low for 0.2 seconds to light up each color in sequence.
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
You are on page 1/ 33

AIM: To Make an LED to BLINK with some delays.

DESCRIPTION:

Connecting the LED to the circuits and making the LED to GLOW ON and OFF with some
time delay.

PROGRAM:
int LED_BUILTIN = 13; // pin D13 is by default assigned as the output pin for LED’s
// the setup function runs once when you press reset or power the board
void setup() {
// initialize digital pin LED_BUILTIN as an output.
pinMode(LED_BUILTIN, OUTPUT);
}

// the loop function runs over and over again forever


void loop() {
digitalWrite(LED_BUILTIN, HIGH);
// turn the LED on (HIGH is the voltage level)
delay(1000); // wait for a second
digitalWrite(LED_BUILTIN, LOW);
// turn the LED off by making the voltage LOW
delay(1000); // wait for a second
}
CIRCUIT DIAGRAM:

IMPLEMENTATION/PROCEDURE:
1. H/W REQUIREMENTS:
a. Arduino Nano,
b. Resistor 220 ohm,
c. LED (any colour),
d. Jumper wires.
2. S/W REQUIREMENTS:
a. Arduino IDE,
b. Arduino Drivers,
c. Windows OS,
STEP 1: Open the arduino IDE and write the above program to blink an LED.
STEP 2: After writing the program we can save it with a file name of your choice (find File–>Save
on menu bar of IDE)

STEP 3: Now we have to configure PC to our Arduino board


A) Selecting the board – we have to select the Arduino board type in your IDE. I am using
an Arduino nano board. To choose the board, and Tools on menu bar. Choose the
option “Board” – and select your correct arduino board. I have chosen arduino nano.

B) Select the right port -- The port number is assigned while installing the hardware driver
of board. You can find the port number by accessing device manager on Windows. See
the section Port (COM & LPT) and look for an open port named “Arduino Uno
(COMxx)“. If you are using a different board, you will find a name accordingly. What matters
is the xx in COMxx part. In my case, its COM5. So my port number is 5.

To select the right port, go to Tools–> Serial Port and select the port number.
Now everything is ready. Your arduino board is ready to communicate with your PC and vice
versa. Instructions will be send to arduino board from your PC.

STEP 4: Now we have to load the program from the Pc to the Arduino Nano Board. There are two
steps involved in loading the program from your PC to Arduino board via the arduino
IDE. First step is compiling and second step is called burning.
A) Compiling – This is the process of converting the code you have just written in Arduino
IDE to another form which is only understood by the micro controller in your
arduino board. In our example, we use Arduino uno board. It is made using Avr
micro controller (Atmega328). In the arduino IDE, compiling is called as “verify“.
So hit the verify button in your IDE (see the button with tick mark just below menu
bar). Refer the screenshot given below as well. When you hit the verify button, the
program you have written in arduino IDE will be compiled for any errors and then
converted to another form that Avr Atmega328 understands. You may refer our
article on the Arduino Software and Hardware to know in detail about the language
used in arduino.
B) Burning – Embedded designers use the word “burning” to refer to uploading a program
to any micro controller. So in this step, we are going to upload the verified program
in Arduino IDE to the Arduino board. To do this, press the “upload” button (see
the button with right arrow mark). A click on the “upload” button will begin the
process of burning the compiled program to Avr micro controller on your Arduino
board. Depending on the size of your program, this will take a little time. If you look on
your Arduino board, you can see the 2 LED’s near Tx and Rx blinking. This is an
indication of successful communication between your PC and Arduino board. If the
program has been uploaded successfully, you will see a message like “Done Uploading“.
If the uploading process was not successful, you will see an error message
accordingly. Refer the screenshot given below.

Note: While I was uploading the “classic LED blink” program to my Arduino board, I got an error
message on first attempt. It was like “Port COM5 is already in use by another device”. I got it fixed
by plugging the board to another USB port in my laptop.
OUTPUT:

EXPECTED: LED Blink with Delay 1000ns.


ACTUAL: LED BLINKS with Delay 1000ns.
CONCLUSION:
The Experiment to make LED to BLINK with some Delay say 1000ns is
compiled and executed successfully.

AIM: To make a series of LED to GLOW and BLINK

DESCRIPTION:
To connect a series of LED of different colours and allow them to BLINK with some delays
using Resistors.

PROGRAM:

int redPin = 12; // Red LED connected to digital pin 12


int greenPin = 10; // Green LED connected to digital pin 10
int bluePin = 9; // Blue LED connected to digital pin 9

void setup() // run once, when the sketch starts


{
pinMode(redPin, OUTPUT); // sets the digital pin as output
pinMode(greenPin, OUTPUT); // sets the digital pin as output
pinMode(bluePin, OUTPUT); // sets the digital pin as output
}
void loop() // run over and over again
{
digitalWrite(redPin, HIGH); // sets the Red LED on
digitalWrite(greenPin, HIGH); // sets the Green LED on
digitalWrite(bluePin, HIGH); // sets the BLUE LED on

delay(500); // waits for half a second

digitalWrite(redPin, HIGH); // sets the Red LED on


digitalWrite(greenPin, HIGH); // sets the Green LED on
digitalWrite(bluePin, LOW); // sets the BLUE LED off

delay(500); // waits for half a second

digitalWrite(redPin, HIGH); // sets the Red LED on


digitalWrite(greenPin, LOW); // sets the Green LED off
digitalWrite(bluePin, LOW); // sets the BLUE LED off
delay(500); // waits for half a second

digitalWrite(redPin, LOW); // sets the Red LED off


digitalWrite(greenPin, HIGH); // sets the Green LED on
digitalWrite(bluePin, LOW); // sets the BLUE LED off

delay(500); // waits for half a second

digitalWrite(redPin, LOW); // sets the Red LED off


digitalWrite(greenPin, LOW); // sets the Green LED off
digitalWrite(bluePin, HIGH); // sets the BLUE LED on

delay(500); // waits for half a second

digitalWrite(redPin, LOW); // sets the Red LED off


digitalWrite(greenPin, LOW); // sets the Green LED off
digitalWrite(bluePin, LOW); // sets the BLUE LED off
delay(500); // waits for half a second

CIRCUIT DIAGRAM:
IMPLEMENTATION/PROCEDURE:

1. H/W REQUIREMENTS:
a. Arduino Nano,
b. Resistors 220 ohm,
c. LED’s (all colours),
d. Jumper wires.

2. S/W REQUIREMENTS:
a. Arduino IDE,
b. Arduino Drivers,
c. Windows OS,
Basically you've connected the LED and resistor in series (one after the other) to a 5V
'battery'. The positive pin of the LED is connected to the positive terminal of the battery, then the
negative pin is connected to a resistor which goes to the negative terminal of the battery. The battery
is supplying the current that flows through the LED, making it light up.

The positive and negative battery terminals are often called the power supply, as they supply
power to our circuit. The positive terminal is called power (as that where current flows from) and the
negative terminal is called ground, as it is where current flows to.

The digitalWrite procedure connects the pin indicated by the first input (ledPin) to either the
+5V power supply or to ground depending on the second input (HIGH or LOW)

Three resistors are required - one for each LED. Use RED, GREEN and BLUE LEDs.

STEP 1: Connect the GND pin to the blue line in the breadboard. This will give you a common
ground for your circuit.

STEP 2: Connect one leg of your resistors to the ground and the other leg to one of the LED. Repeat
for each LED as shown in the diagram.

STEP 3: Connect Pin 12 to the other leg of the RED LED.

STEP 4: Connect Pin 10 to GREEN LED

STEP 5: Connect Pin 9 to BLUE LED

STEP 6: Compile and verify your code.

OUTPUT:

EXPECTED: All the 3 LED’s BLINK with the interval delay.

ACTUAL:
CONCLUSION:
The LED’s connected serially using resistors and allowed them to BLINK with some
delay intervals. The program is compiled and executed successfully.
AIM: To Make an RGB LED to glow with different colours.

DESCRIPTION:
RGB LED – these are three LEDs of different colors (Red – red, Green –green, Blue – blue),
enclosed in one package. The difference between RGB LEDs with a common anode and a common
cathode.
RGB LEDs are of two types: with a common anode (“plus”) and a common cathode
(“minus”).. The long leg of the LED is always the common power pin. Separately, the red LED
output (R) is located, green (G) and blue (B) are located on the other side of the common output. The
LED, in turn, lights up in red, green and blue. Each color burns for 0.1 seconds, and then goes out for
0.2 seconds, and the next one turns on.

PROGRAM:

const int pinR = 12;


const int pinG = 10;
const int pinB = 9;
void setup()
{
// put your setup code here, to run once:
pinMode(pinR, OUTPUT);
pinMode(pinG, OUTPUT);
pinMode(pinB, OUTPUT);
}

void loop()
{
// put your main code here, to run repeatedly:
digitalWrite(pinR, LOW);
delay(100);
digitalWrite(pinR, HIGH);
delay(200);

digitalWrite(pinG, LOW);
delay(100);
digitalWrite(pinG, HIGH);
delay(200);

digitalWrite(pinB, LOW);
delay(100);
digitalWrite(pinB, HIGH);
delay(200);
}

CIRCUIT DIAGRAM:
IMPLEMENTATION/PROCEDURE:

An RGB LED is a light emitting diode which can display any color we want. It consists of 3
discrete LEDs, a RED, a GREEN, and a BLUE LED housed in a single package. So by combining
these 3 colors we can create any color. As you can see, the RGB LED has 4 pins. So far the LEDs we
were using only had 2 pins. The pins are used in order to control the color of the LED. The longest
pin is either the anode or the cathode depending on the type of the RGB LED. The LED I have
bought is a common cathode LED so the longest leg will be connected to GND. If it was a common
anode LED, the longest pin would connect to 5V. The other three pins are Red, Green, and Blue.

1. H/W REQUIREMENTS:
a. Arduino Nano,
b. Breadboard
c. RGB LED
d. Resistor 330 ohm
e. Connecting Wires

2. S/W REQUIREMENTS:
a. Arduino IDE,
b. Arduino Drivers,
c. Windows OS,

1. Connect the RGB LED to a Breadboard.


2. To limit the current use 3 resistors one for each color pin.
3. Connect the RED pin to port 12
4. Connect the GREEN pin to port 10
5. Connect the BLUE pin to port 9
6. In the Arduino use the above code and verify it.
OUTPUT:

CONCLUSION:

Glowing RGB LED in RED, GREEN, BLUE colours is compiled and executed successfully.
AIM: Connect a LED with TOGGLE button using Arduino.

DESCRIPTION:

Digital input is taken through push button and that is detected by Arduino Nano. This input is
processes by Arduino Nano and it send digital command to attached LED. When we press the button
LED glows.

PROGRAM:

const int BUTTON = 4; // Naming switch button pin


const int LED = 3; // Namin LED pin
int BUTTONstate = 0; // A variable to store Button Status / Input
void setup()
{
pinMode(LED, OUTPUT);
pinMode (BUTTON, INPUT);
}
void loop()
{
BUTTONstate = digitalRead(BUTTON); // Reading button status / input
if (BUTTONstate == HIGH) // Condition to check button input
{
digitalWrite(LED, HIGH);
}
else
{
digitalWrite(LED, LOW);
}
}
CIRCUIT DIAGRAM:
IMPLEMENTATION/ PROCEDURE:

1. H/W REQUIREMENTS:

a. Arduino Nano,
b. Mini USB Cable
c. Breadboard
d. LED
e. Resistor 220 ohm and 10k
f. Push button
g. Male to Male Jumper Wire

2. S/W REQUIREMENTS:
a. Arduino IDE,
b. Arduino Drivers,
c. Windows OS,

Place a pushbutton in the breadboard. They should be properly fixed. The legs should tightly
fixed or else it will not work. Put a 10k resistor to one leg on any column. On the other end connect
the hole through a jumper wire to 5v.

Now the one leg of Push Button is connected to 5v supply and the other one is connected with
LED via the resistor, as shown in circuit diagram. Initially, Push Button does not allow the current to
flow through it, but when it is pressed it completes the circuit and LED will start to glow. The current
will pass till the button is pressed, as soon as we release it, the LED will be turned off as push-button
breaks the circuit and stop the supply.
OUTPUT:

CONCLUSION:

Connecting LED with button using Arduino is compiled and executed successfully.
AIM: To Detect Light with LDR and represent that using Serial Monitor or LED.

DESCRIPTION:

The Arduino Nano for LED light is turned on or off by the light-sensitive resistor to the
surrounding ambient light. A photoresistor or photocell is a light-controlled variable resistor. The
resistance of a photoresistor decreases with increasing incident light intensity. A photoresistor can be
applied in light-sensitive detector circuits, and light- and dark-activated switching circuits. It's also
called light-dependent resistor (LDR).

PROGRAM:

int photocellPin = 2; // photocell to anallog pin 2 


int photocellVal = 0; // photocell variable 
int minLight = 200; 
int ledPin = 12; 
int ledState = 0; 
void setup()

  pinMode(ledPin, OUTPUT); 
  Serial.begin(9600); 

void loop()

  photocellVal = analogRead(photocellPin); 
  Serial.println(photocellVal); 
  if (photocellVal < minLight && ledState == 0) 
  { 
  digitalWrite(ledPin, HIGH); // turn on LED 
  ledState = 1; 
  } 
  if (photocellVal > minLight && ledState == 1) 
  { 
  digitalWrite(ledPin, LOW); // turn off LED 
  ledState = 0; 
  } 
  delay(100); 
}

CIRCUIT DIAGRAM:

IMPLEMENTATION/ PROCEDURE:
The resistance value becomes smaller when there is much light. So in the dark the led remains
off because the resistance has become very big.
1. HARDWARE REQUIREMENTS:
a. Arduino Nano 
b. USB Cable 
c. Red LED 
d. 220Ω Resstor 
e. 10kΩ ResistoR
f. Photo resistance 
g. Breadboard 
h. Several jumper wires.
2. SOFTWARE REQUIREMENTS:
d. Arduino IDE,
e. Arduino Drivers,
f. Windows OS,

Step 1: Connect the photocell pin to port 2


Step 2: Connect the led pin to port 12
Step 3: Connect the resistors to the LED and Photocell
Now when the analog reads input if the photocell senses minimum light pulse then it make
the LED to glow high. If the Analog reads the input in high light pulse then it make the LED to glow
light.
OUTPUT:

CONCLUSION:

To Detect Light with LDR and represent that using LED is compiled and
executed successfully.
AIM:
To Detect Temperature & Humidity using DHT11 sensors and send to PC via serial.

DESCRIPTION:

To read DHT11 (Temperature & Humidity sensors) values, and send data to PC via serial. For
this the library adafruit/DHT-sensor-library is used to read DHT11.

PROGRAM:

// Example testing sketch for various DHT humidity/temperature sensors


// Written by ladyada, public domain
#include "DHT.h"
#define DHTPIN 2 // what pin we're connected to
// Uncomment whatever type you're using!
#define DHTTYPE DHT11 // DHT 11
//#define DHTTYPE DHT22 // DHT 22 (AM2302)
//#define DHTTYPE DHT21 // DHT 21 (AM2301)
// Connect pin 1 (on the left) of the sensor to +5V
// NOTE: If using a board with 3.3V logic like an Arduino Due connect pin 1
// to 3.3V instead of 5V!// Connect pin 2 of the sensor to whatever your DHTPIN is
// Connect pin 4 (on the right) of the sensor to GROUND
// Connect a 10K resistor from pin 2 (data) to pin 1 (power) of the sensor
// Initialize DHT sensor for normal 16mhz Arduino
//DHT dht(DHTPIN, DHTTYPE);
// NOTE: For working with a faster chip, like an Arduino Due or Teensy, you
// might need to increase the threshold for cycle counts considered a 1 or 0.
// You can do this by passing a 3rd parameter for this threshold. It's a bit
// of fiddling to find the right value, but in general the faster the CPU the
// higher the value. The default for a 16mhz AVR is a value of 6. For an
// Arduino Due that runs at 84mhz a value of 30 works.
// Example to initialize DHT sensor for Arduino Due:

DHT dht(DHTPIN, DHTTYPE, 6);


void setup() {
Serial.begin(9600);
Serial.println("DHTxx test!");
dht.begin();
}
void loop() {
// Wait a few seconds between measurements.
delay(2000);
// Reading temperature or humidity takes about 250 milliseconds!
// Sensor readings may also be up to 2 seconds 'old' (its a very slow sensor)
float h = dht.readHumidity();
// Read temperature as Celsius
float t = dht.readTemperature();
// Read temperature as Fahrenheit
float f = dht.readTemperature(true);
// Check if any reads failed and exit early (to try again).
if (isnan(h) || isnan(t) || isnan(f)) {
Serial.println("Failed to read from DHT sensor!");
return;
}

// Compute heat index


// Must send in temp in Fahrenheit!
float hi = dht.computeHeatIndex(f, h);
Serial.print("Humidity: ");
Serial.print(h);
Serial.print(" %\t");Serial.print("Temperature: ");
Serial.print(t);
Serial.print(" *C ");
Serial.print(f);
Serial.print(" *F\t");
Serial.print("Heat index: ");
Serial.print(hi);
Serial.println(" *F");
}

CIRCUIT DIAGRAM:
IMPLEMENTATION/ PROCEDURE:

1. H/W REQUIREMENTS:
d. Arduino Nano,
e. Mini USB Cable
f. Breadboard
g. LED
h. Resistor 220 ohm and 10k
i. DTH11 Sensor
j. Male to Male Jumper Wire
2. S/W REQUIREMENTS:
k. Arduino IDE,
l. Arduino Drivers,
m. Windows OS,

The library adafruit/DHT-sensor-library is included in Arduino IDE library sources, so it's


easy to add it to your project. Once the library added, you can fifind a example in File -> Examples
-> DHT sensor library -> DHTtester.

To make the setup for DUMPING follow the procedure

There are four legs in DTH11 sensor, 1 leg you connect to 5V, another leg not connected to
any pins of Arduino Nano, another leg to Ground, another leg to D2 of Arduino Nano and Resistors
as given in the Diagram given below.

Now Place a DTH11 sensor in the breadboard. They should be properly fixed. The legs
should tightly fixed or else it will not work. Put a 10k resistor to one leg on any column. On the other
end connect the hole through a jumper wire to 5v. other end of the resistor is connected to the D2
digital input pin of Arduino Nano.
Now the one leg of DTH11 sensor is connected to 5v supply and the D2 pin via the resistor, as
shown in circuit diagram. One leg is connected to D2 directly, One leg is connected to Ground. One
Leg of DTH11 sensor is not connected to anywhere. By executing the program and uploading you
can view the Sensor Data in the window like DHTtester.ino which shows the Humidity and
Temperature (C & F), Heat Index everything is taken as output.

OUTPUT:

CONCLUSION:
Thus reading DHT11 (Temperature & Humidity sensors) values, and send data to PC via
serial with DTH11 Sensor and Arduino Nano is compiled and executed successfully.

You might also like