Location via proxy:   [ UP ]  
[Report a bug]   [Manage cookies]                
0% found this document useful (0 votes)
29 views

Arduino Lab Book BBACA

Detail information of Internet of things

Uploaded by

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

Arduino Lab Book BBACA

Detail information of Internet of things

Uploaded by

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

T.Y.B.B.A.(C.A.

)Sem-V(CBCS 2019 Pattern)


Subject: Internet of Things (IoT) Subject Code: CA-507
Add on Practical Assignments using Arduino Uno:

Designed by Prof. Deepak Shivram Kumbhar

Modern College, Ganeshkhind,Pune-16 Cell: 9890136461

Assignment No. 1: Demonstration of LED Blink.

Aim: To demonstrate LED blink application using Arduino Uno


Objectives:
1. To study Arduino IDE software and understand the basics of LED
working.
2. To develop & write simple LED blink program using Arduino Uno
platform and demonstrate it.
3. To implement your ideas and programming coding skill using LED
Arrays
Software and hardware required:
1. Arduino IDE
2. FCT make Arduino Circuit Board

Diagram:

a. Single LED b. LED Array


Procedure:
1. Connect the Arduino Uno board to the PC through USB cable.
2. Start Arduino IDE from PC and open new Sketch and the program/code
for that and save as LEDblink.
3. Verify/Compile the program and Upload the code into Arduino Uno.
4. Make necessary connections according diagram.
5. Observe the output running on the board.
6. Repeat the procedure for other programs to implement your ideas and
programming coding skill.

Program /Code:
a. Single LED blink
/* Assignment 1. Demonstration of LED Blink
*/
# define LED 6
// 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, OUTPUT);
}

// the loop function runs over and over again forever


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

b. LED Array

int ledPin0 = 2;
int ledPin1 = 3;
int ledPin2 = 4;
int ledPin3 = 5;
int ledPin4 = 6;
int ledPin5 = 7;
int ledPin6 = 8;
int ledPin7 = 9;

void setup() {
pinMode(ledPin0, OUTPUT);
pinMode(ledPin1, OUTPUT);
pinMode(ledPin2, OUTPUT);
pinMode(ledPin3, OUTPUT);
pinMode(ledPin4, OUTPUT);
pinMode(ledPin5, OUTPUT);
pinMode(ledPin6, OUTPUT);
pinMode(ledPin7, OUTPUT);
}

void loop() {
digitalWrite(ledPin0, HIGH);
delay(50);
digitalWrite(ledPin0, LOW);
delay(50);
digitalWrite(ledPin1, HIGH);
delay(50);
digitalWrite(ledPin1, LOW);
delay(50);
digitalWrite(ledPin2, HIGH);
delay(50);
digitalWrite(ledPin2, LOW);
delay(50);
digitalWrite(ledPin3, HIGH);
delay(50);
digitalWrite(ledPin3, LOW);
delay(50);
digitalWrite(ledPin4, HIGH);
delay(50);
digitalWrite(ledPin4, LOW);
delay(50);
digitalWrite(ledPin5, HIGH);
delay(50);
digitalWrite(ledPin5, LOW);
delay(50);
digitalWrite(ledPin6, HIGH);
delay(50);
digitalWrite(ledPin6, LOW);
delay(50);
digitalWrite(ledPin7, HIGH);
delay(50);
digitalWrite(ledPin7, LOW);
delay(50);
digitalWrite(ledPin7, HIGH);
delay(50);
digitalWrite(ledPin7, LOW);
delay(50);
digitalWrite(ledPin6, HIGH);
delay(50);
digitalWrite(ledPin6, LOW);
delay(50);
digitalWrite(ledPin5, HIGH);
delay(50);
digitalWrite(ledPin5, LOW);
delay(50);
digitalWrite(ledPin4, HIGH);
delay(50);
digitalWrite(ledPin4, LOW);
delay(50);
digitalWrite(ledPin3, HIGH);
delay(50);
digitalWrite(ledPin3, LOW);
delay(50);
digitalWrite(ledPin2, HIGH);
delay(50);
digitalWrite(ledPin2, LOW);
delay(50);
digitalWrite(ledPin1, HIGH);
delay(50);
digitalWrite(ledPin1, LOW);
delay(50);
digitalWrite(ledPin0, HIGH);
delay(50);
digitalWrite(ledPin0, LOW);
delay(50);

}
Assignment No. 2: Demonstration of interfacing of switch & LED.

Aim: To demonstrate interface a switch and LED to Arduino Uno


Objectives:
1. To learn & understand the basics of a switch and LED interface to
Arduino Uno.
2. To develop & write a switch and LED interface program using Arduino
Uno platform and demonstrate it.
3. To implement and apply your ideas and programming coding skill for a
switch and
LED array.
Software and hardware required:
1. Arduino IDE
2. FCT make Arduino Circuit Board
Diagram:

a. Single LED and Switches b. LED Array and Switches


Procedure:
1. Connect the Arduino Uno board to the PC through USB cable.
2. Start Arduino IDE from PC and open new Sketch and the program/code
for that and save as LEDSwitch.
3. Verify/Compile the program and Upload the code into Arduino Uno.
4. Make necessary connections according diagram.
5. Observe the output running on the board.
6. Repeat the procedure for other programs to implement your ideas and
programming coding skill.
Program:

/* Switch (Push button and LED - Turns on and off a light emitting
diode(LED) connected to digital pin 2, when pressing a pushbutton
attached to pin 3.
*/
// constants won't change. They're used here to set pin numbers:
const int buttonPin = 3; // the number of the pushbutton pin
const int ledPin = 2; // the number of the LED pin

// variables will change:


int buttonState = 0; // variable for reading the pushbutton status

void setup() {
// initialize the LED pin as an output:
pinMode(ledPin, OUTPUT);
// initialize the pushbutton pin as an input:
pinMode(buttonPin, INPUT);
}

void loop() {
// read the state of the pushbutton value:
buttonState = digitalRead(buttonPin);

// check if the pushbutton is pressed. If it is, the buttonState is HIGH:


if (buttonState == HIGH) {
// turn LED on:
digitalWrite(ledPin, HIGH);
} else {
// turn LED off:
digitalWrite(ledPin, LOW);
}
}
Assignment No. 3: Demonstration of LED fade-in and fade-out.

Aim: To demonstrate LED fade-in and fade-out application using Arduino


Uno
Objectives:
1. To understand the basics of LED working.
2. To develop & write simple LED blink program using Arduino Uno
platform and demonstrate it.
3. To implement your ideas and programming coding skill using LED
Arrays
4. To study Arduino IDE software.
Software and hardware required:
1. Arduino IDE
2. FCT make Arduino Circuit Board
Diagram:

a. Single LED fade in and fade out b. LED Array fade in and fade out
Procedure:
1. Connect the Arduino Uno board to the PC through USB cable.
2. Start Arduino IDE from PC and open new Sketch and the program/code
for that and save as LEDfade.
3. Verify/Compile the program and Upload the code into Arduino Uno.
4. Make necessary connections according diagram.
5. Observe the output running on the board.
6. Repeat the procedure for other programs to implement your ideas and
programming coding skill.
Program:

1. Fade-in Fade-out without pot.


/*
Fade-in Fade-out Program. The analogWrite() function uses PWM.
PWM pins are identified with a "~" sign, like ~3, ~5, ~6, ~9, ~10 and ~11
in Arduino Uno.
*/
int led = 9; // the PWM pin the LED is attached to
int brightness = 0; // how bright the LED is
int fadeAmount = 5; // how many points to fade the LED by

// the setup routine runs once when you press reset:


void setup() {
// declare pin 9 to be an output:
pinMode(led, OUTPUT);
}

// the loop routine runs over and over again forever:


void loop() {
// set the brightness of pin 9:
analogWrite(led, brightness);

// change the brightness for next time through the loop:


brightness = brightness + fadeAmount;

// reverse the direction of the fading at the ends of the fade:


if (brightness <= 0 || brightness >= 255) {
fadeAmount = -fadeAmount;
}
// wait for 30 milliseconds to see the dimming effect
delay(30);
}

2. Fade-in Fade-out with pot.


/*
Fade with Pot program. The analogWrite() function uses PWM.
PWM pins are identified with a "~" sign, like ~3, ~5, ~6, ~9, ~10 and ~11
in Arduino Uno.
*/

int LED_PIN = 9; // the PWM pin the LED is attached to

// the setup routine runs once when you press reset:


void setup() {
// initialize serial communication at 9600 bits per second:
Serial.begin(9600);

// declare LED pin to be an output:


pinMode(LED_PIN, OUTPUT);
}

// the loop routine runs over and over again forever:


void loop() {
// reads the input on analog pin A0 (value between 0 and 1023)
int analogValue = analogRead(A0);

// scales it to brightness (value between 0 and 255)


int brightness = map(analogValue, 0, 1023, 0, 255);

// sets the brightness LED that connects to pin 3


analogWrite(LED_PIN, brightness);

// print out the value


Serial.print("Analog: ");
Serial.print(analogValue);
Serial.print(", Brightness: ");
Serial.println(brightness);
delay(100);
}
Assignment No. 4: Demonstration of Traffic Signal.

Aim: To demonstrate Traffic Signal application using Arduino Uno


Objectives:
1. To understand the basics of Traffic Signal Control working.
2. To develop & write Traffic Signal Control program using Arduino
Uno platform and demonstrate it.
3. To implement your ideas and programming coding skill Traffic
Signal Control
Software and hardware required:
1. Arduino IDE
2. FCT make Arduino Circuit Board
Diagram:

Four Way Traffic Signal

Procedure:
1. Connect the Arduino Uno board to the PC through USB cable.
2. Start Arduino IDE from PC and open new Sketch and the
program/code for that and save as trafficlight.
3. Verify/Compile the program and Upload the code into Arduino
Uno.
4. Make necessary connections according diagram.
5. Observe the output running on the board.
6. Repeat the procedure for other programs to implement your ideas
and programming coding skill.
Program:

int signal1[] = {2, 3, 4};


int signal2[] = {7, 6, 5};
int signal3[] = {8, 9, 10};
int signal4[] = {13, 12, 11};
int redDelay = 5000;
int yellowDelay = 2000;

void setup() {
// Declaring all the LED's as output
for (int i = 0; i < 3; i++) {
pinMode(signal1[i], OUTPUT);
pinMode(signal2[i], OUTPUT);
pinMode(signal3[i], OUTPUT);
pinMode(signal4[i], OUTPUT);
}
}
void loop() {
// Making Green LED at signal 1 and red LED's at other signal HIGH
digitalWrite(signal1[2], HIGH);
digitalWrite(signal1[0], LOW);
digitalWrite(signal2[0], HIGH);
digitalWrite(signal3[0], HIGH);
digitalWrite(signal4[0], HIGH);
delay(redDelay);
// Making Green LED at signal 1 LOW and making yellow LED at signal 1 HIGH for 2 seconds
digitalWrite(signal1[1], HIGH);
digitalWrite(signal1[2], LOW);
delay(yellowDelay);
digitalWrite(signal1[1], LOW);
// Making Green LED at signal 2 and red LED's at other signal HIGH
digitalWrite(signal1[0], HIGH);
digitalWrite(signal2[2], HIGH);
digitalWrite(signal2[0], LOW);
digitalWrite(signal3[0], HIGH);
digitalWrite(signal4[0], HIGH);
delay(redDelay);
// Making Green LED at signal 2 LOW and making yellow LED at signal 2 HIGH for 2 seconds
digitalWrite(signal2[1], HIGH);
digitalWrite(signal2[2], LOW);
delay(yellowDelay);
digitalWrite(signal2[1], LOW);
// Making Green LED at signal 3 and red LED's at other signal HIGH
digitalWrite(signal1[0], HIGH);
digitalWrite(signal2[0], HIGH);
digitalWrite(signal3[2], HIGH);
digitalWrite(signal3[0], LOW);
digitalWrite(signal4[0], HIGH);
delay(redDelay);
// Making Green LED at signal 3 LOW and making yellow LED at signal 3 HIGH for 2 seconds
digitalWrite(signal3[1], HIGH);
digitalWrite(signal3[2], LOW);
delay(yellowDelay);
digitalWrite(signal3[1], LOW);
// Making Green LED at signal 4 and red LED's at other signal HIGH
digitalWrite(signal1[0], HIGH);
digitalWrite(signal2[0], HIGH);
digitalWrite(signal3[0], HIGH);
digitalWrite(signal4[2], HIGH);
digitalWrite(signal4[0], LOW);
delay(redDelay);
// Making Green LED at signal 4 LOW and making yellow LED at signal 4 HIGH for 2 seconds
digitalWrite(signal4[1], HIGH);
digitalWrite(signal4[2], LOW);
delay(yellowDelay);
digitalWrite(signal4[1], LOW);
}
Assignment No. 5: Demonstration of interfacing of 7 segment display

Aim: To demonstrate 7-segment application using Arduino Uno


Objectives:
1. To understand the basics of 7-segment working.
2. To develop & write 7-segment program using Arduino Uno
platform and demonstrate it.
3. To implement your ideas and programming coding skill using 7-
segment.
Software and hardware required:
1. Arduino IDE
2. FCT make Arduino Circuit Board
Diagram:

Display decimal numbers on 7-Segment display

Procedure:
1. Connect the Arduino Uno board to the PC through USB cable.
2. Start Arduino IDE from PC and open new Sketch and the
program/code for that and save as Seven_segment.
3. Verify/Compile the program and Upload the code into Arduino
Uno.
4. Make necessary connections according diagram.
5. Observe the output running on the board.
6. Repeat the procedure for other programs to implement your ideas
and programming coding skill.
Program:
#include "SevSeg.h"
SevSeg sevseg;

void setup()
{
//Set to 1 for single digit display
byte numDigits = 1;

//defines common pins while using multi-digit display. Left empty as


we have a single digit display
byte digitPins[] = {};

//Defines arduino pin connections in order: A, B, C, D, E, F, G, DP


byte segmentPins[] = {2, 3, 4, 5, 6, 7, 8, 9};
bool resistorsOnSegments = true;

//Initialize sevseg object. Uncomment second line if you use


common cathode 7 segment
sevseg.begin(COMMON_ANODE, numDigits, digitPins,
segmentPins, resistorsOnSegments);
//sevseg.begin(COMMON_CATHODE, numDigits, digitPins,
segmentPins, resistorsOnSegments);

sevseg.setBrightness(90);
}

void loop()
{
//Display numbers one by one with 2 seconds delay
for(int i = 0; i < 10; i++)
{
sevseg.setNumber(i);
sevseg.refreshDisplay();
delay(2000);
}
}
Assignment No. 6: Demonstration of up and down counter. (Counting 0 to
9 using any display).
Aim: To demonstrate up and down counter application using Arduino Uno
Objectives:
1. To understand the basics of LED working.
2. To develop & write simple LED blink program using Arduino Uno
platform and demonstrate it.
3. To implement your ideas and programming coding skill using LED
Arrays
Software and hardware required:
1. Arduino IDE
2. FCT make Arduino Circuit Board
Diagram:

Up and Down Counter using 7-Segment display

Procedure:
1. Connect the Arduino Uno board to the PC through USB cable.
2. Start Arduino IDE from PC and open new Sketch and the
program/code for that and save as counter.
3. Verify/Compile the program and Upload the code into Arduino
Uno.
4. Make necessary connections according diagram.
5. Observe the output running on the board.
6. Repeat the procedure for other programs to implement your ideas
and programming coding skill.
Program:

#include "SevSeg.h"
SevSeg sevseg;

void setup()
{
//Set to 1 for single digit display
byte numDigits = 1;

//defines common pins while using multi-digit display. Left empty as


we have a single digit display
byte digitPins[] = {};

//Defines arduino pin connections in order: A, B, C, D, E, F, G, DP


byte segmentPins[] = {2, 3, 4, 5, 6, 7, 8, 9};
bool resistorsOnSegments = true;

//Initialize sevseg object. Uncomment second line if you use


common cathode 7 segment
sevseg.begin(COMMON_ANODE, numDigits, digitPins,
segmentPins, resistorsOnSegments);
//sevseg.begin(COMMON_CATHODE, numDigits, digitPins,
segmentPins, resistorsOnSegments);

sevseg.setBrightness(90);
}

void loop()
{
//Display numbers one by one with 2 seconds delay
for(int i = 0; i < 10; i++)
{
sevseg.setNumber(i);
sevseg.refreshDisplay();
delay(2000);
}
}
Assignment No. 7: Demonstration of interfacing of speaker (audio) with
Arduino Uno.
Aim: To demonstrate speaker (audio) application using Arduino Uno
Objectives:
1. To understand the basics of Speaker/Buzzer working.
2. To develop & write speaker program using Arduino Uno platform
and demonstrate it.
3. To implement your ideas and programming coding skill using
Speaker
Software and hardware required:
1. Arduino IDE
2. FCT make Arduino Circuit Board
Diagram:

Speaker with Arduino Uno

Procedure:
1. Connect the Arduino Uno board to the PC through USB cable.
2. Start Arduino IDE from PC and open new Sketch and the
program/code for that and save as speaker.
3. Verify/Compile the program and Upload the code into Arduino
Uno.
4. Make necessary connections according diagram.
5. Observe the output running on the board.
6. Repeat the procedure for other programs to implement your ideas
and programming coding skill.
Program:
/*
Speaker (Jan Gan Mam )
*/
int speakerPin = 7; //buzzer is connected to Pin 7 of the Board.

int length = 149; // the number of notes


char notes[] = "cdeeeeeeeeedef eeedddbdc ccgggggggggaf fffffeddf
eedeedeggaff eeeeeddbdc cdeeeedf efgggfedfe feeeddbdc
ccggggeggggga fffffedfe egc bab aga ccddeedef "; // a space
represents a rest
//char notes[] = "ccddeeeeeeedef eeedddb-dc cggggggggf#ag fffeeedfe
eeeeedgggff eeedddb-dc cdeeeedef efgggfedfe eedddb-dc
ggggggggggf#ag fffeeedfe egc+ bab aga ccddeedef "; // a space
represents a rest
int beats[] = { 1, 1, 1, 1, 1, 1, 1, 1, 2, 1, 1, 1, 1, 1, 1,
2, 1, 1, 2, 1, 1, 1, 1, 1, 1,
2, 2, 1, 2, 1, 1, 1, 1, 1, 1, 1, 2, 1, 1,
2, 1, 1, 2, 1, 1, 1, 1, 1, 1,
2, 1, 1, 2, 1, 1, 1, 1, 2, 1, 1, 1, 1,
2, 1, 1, 1, 1, 1, 1, 1, 1, 2, 1,
1, 1, 1, 1, 2, 2, 2, 1, 1,
1, 1, 1, 1, 2, 1, 1, 1, 1, 1, 1,
2, 2, 1, 1, 1, 1, 1, 1, 1, 1,
1, 1, 1, 1, 2, 1, 1, 2, 1, 1, 1, 1, 1, 1,
2, 1, 1, 2, 1, 1, 1, 1, 1, 1,
1, 1, 4, 1, 1, 1, 4, 1, 1, 1, 4, 1,
1, 1, 1, 1, 1, 1, 1, 1, 4, 1 };

int tempo = 200; //set tempo

void playTone(int tone, int duration) { //created a square wave for


given time duration
for (long i = 0; i < duration * 1000L; i += tone * 2) {
digitalWrite(speakerPin, HIGH);
delayMicroseconds(tone);
digitalWrite(speakerPin, LOW);
delayMicroseconds(tone);
}
}

void playNote(char note, int duration) { //Assigning high time for the
notes
char names[] = { 'c', 'd', 'e', 'f', 'g', 'a', 'b', 'C' };
int tones[] = { 956, 851, 758, 716, 638, 568, 1014, 478 };

// play the tone corresponding to the note name


for (int i = 0; i < 8; i++) {
if (names[i] == note) {
playTone(tones[i], duration);
}
}
}

void setup() {
pinMode(speakerPin, OUTPUT); // pin 7 as an OutPut Pin
}

void loop() { //Main function


for (int i = 0; i < length; i++) { //For the length of the tune array
if (notes[i] == ' ') { //take space as rest
delay(beats[i] * tempo); // rest
} else {
playNote(notes[i], beats[i] * tempo); //play the corresponding note
for the corresponding beat
}

// pause between notes


delay(tempo / 2);
}
}
Assignment No. 8: Demonstration of IR sensor based intruder /alarm
system.
Aim: To demonstrate IR sensor based intruder /alarm system using Arduino
Uno
Objectives:
1. To understand the basics of IR sensor working.
2. To develop & write IR sensor based intruder /alarm system
program using Arduino Uno platform and demonstrate it.
3. To implement your ideas and programming coding skill using IR
sensor.
Software and hardware required:
1. Arduino IDE
2. FCT make Arduino Circuit Board
Diagram:

IR Sensor based intruder detection with LED indicator and


Buzzer alarm

Procedure:
1. Connect the Arduino Uno board to the PC through USB cable.
2. Start Arduino IDE from PC and open new Sketch and the
program/code for that and save as IR_sensor.
3. Verify/Compile the program and Upload the code into Arduino
Uno.
4. Make necessary connections according diagram.
5. Observe the output running on the board.
6. Repeat the procedure for other programs to implement your ideas
and programming coding skill.
Program:
//IR sensor interface

int val = 0 ;
#define IR 6
#define Lamp 5
#define RED 4
#define GREEN 3
#define BUZ 2
void setup()
{
Serial.begin(9600); // sensor baud rate
pinMode(IR,INPUT); // IR sensor output pin connected
pinMode(RED,OUTPUT); // LED
pinMode(GREEN,OUTPUT); // LED
pinMode(BUZ,OUTPUT); // BUZZER
pinMode(Lamp,OUTPUT); // Lamp
}
void loop()
{
val = digitalRead(IR); // IR sensor output pin connected
Serial.println(val); // see the value in serial monitor in Arduino IDE
delay(500);
if(val == 1 )
{
digitalWrite(Lamp,LOW); // Lamp OFF
digitalWrite(RED,HIGH); // LED ON
digitalWrite(GREEN,LOW); // LED OFF
digitalWrite(BUZ,LOW); // BUZZER OFF
}
else
{
digitalWrite(Lamp,HIGH); // Lamp ON
digitalWrite(RED,LOW); // LED OFF
digitalWrite(GREEN,HIGH); // Green LED ON
digitalWrite(BUZ,HIGH); // BUZZER ON
}
}
Assignment No. 9: Demonstration of relay control.

Aim: To demonstrate relay control application using Arduino Uno


Objectives:
1. To understand the basics of Relay working.
2. To develop & write Relay control application program using
Arduino Uno platform and demonstrate it.
3. To implement your ideas and programming coding skill using
Relay.
Software and hardware required:
1. Arduino IDE
2. FCT make Arduino Circuit Board
Diagram:

Relay Control Lamp


Procedure:
1. Connect the Arduino Uno board to the PC through USB cable.
2. Start Arduino IDE from PC and open new Sketch and the program/code
for that and save as Relaycontrol.
3. Verify/Compile the program and Upload the code into Arduino Uno.
4. Make necessary connections according diagram.
5. Observe the output running on the board.
6. Repeat the procedure for other programs to implement your ideas and
programming coding skill.

Program:
1. Relay Progrm
// Arduino Relay Control Code
#define relay 11
#define interval 1000
void setup() {
// put your setup code here, to run once:
pinMode(relay, OUTPUT);
}
void loop()
{
// put your main code here, to run repeatedly:
digitalWrite(relay, HIGH);
delay(interval);
digitalWrite(relay, LOW);
delay(interval);
}

2. Bluetooth and Relay Program


//Code to control an LEDs and Buzzer via bluetooth through a phone app.
/*
HC05 Arduino
Tx---------- > Rx
Rx --------- > Tx

*/
#define Lamp 5
#define RED 4
#define GREEN 3
#define BUZ 2

char switchstate;
/*declaring that there is a variable called switchstate, which will
hold a character value. This is due to programming of the app, which
will send a text value to arduino. If we use 'int' instead of
'char' the code will not work properly.*/
void setup() {//Here the code only runs once.
Serial.begin(9600);
/*To start serial communication at a rate of 9600 bits per second. This
is the default rate anyways.*/
pinMode(Lamp, OUTPUT);
pinMode(GREEN, OUTPUT);
pinMode(RED, OUTPUT);
pinMode(BUZ, OUTPUT);
//Declaring that the LED is an output.
}
void loop() {//This code repeats. This is our main code.
if (Serial.available() > 0) {
delay(50);
//code to be executed only when Serial.available()>0
/*Serial.available>0 is to check if there is any reading from the
HC-05 Bluetooth module.*/
switchstate = Serial.read();
while(Serial.available() > 0) {
Serial.read();
}
/*The character we had declared earlier is now being assigned a value-
the value of whatever Serial.read() is.*/
digitalWrite(Lamp, LOW);
digitalWrite(GREEN, LOW);
digitalWrite(RED, LOW);
digitalWrite(BUZ, LOW);

if (switchstate == 'g') {
digitalWrite(GREEN, HIGH);
} else if (switchstate == 'r') {
digitalWrite(RED, HIGH);
} else if (switchstate == 'l') {
digitalWrite(Lamp, HIGH);
} else if (switchstate == 'b') {
digitalWrite(BUZ, HIGH);
delay(1000);
digitalWrite(BUZ, LOW);
}
}
}
Assignment No. 10: Demonstration of servo motor.

Aim: To demonstrate servo motor control application using Arduino Uno


Platform.
Objectives:
1. To understand the basic of Servo Motor.
2. To develop & write simple Servo Motor control program using
Arduino Uno platform and demonstrate it.
3. To implement your ideas and programming coding skill using
Servo Motor (e.g. Sensor based automatically opening/closing the
dustbin/parking gate.)
Software and hardware required:
1. Arduino IDE
2. FCT make Arduino Circuit Board
Diagram:

Servo motor control with Potentiometer


Procedure:
1. Connect the Arduino Uno board to the PC through USB cable.
2. Start Arduino IDE from PC and open new Sketch and the program/code
for that and save as servomotor.
3. Verify/Compile the program and Upload the code into Arduino Uno.
4. Make necessary connections according diagram.
5. Observe the output running on the board.
6. Repeat the procedure for other programs to implement your ideas and
programming coding skill.
Program:
#include <Servo.h>
Servo myServo; // create servo object to control a servo
void setup() {
// initialize serial communication at 9600 bits per second:
Serial.begin(9600);
myServo.attach(9); // attaches the servo on pin 9 to the servo object
}

void loop() {
// reads the value of the potentiometer (value between 0 and 1023)
int analogValue = analogRead(A0);

// scales it to use it with the servo (value between 0 and 180)


int angle = map(analogValue, 0, 1023, 0, 180);

// sets the servo position according to the scaled value


myServo.write(angle);

// print out the value


Serial.print("Analog: ");
Serial.print(analogValue);
Serial.print(", Angle: ");
Serial.println(angle);
delay(100);
}
Assignment No. 11: Demonstration of stepper motor.

Aim: To demonstrate steeper motor application using Arduino Uno


Objectives:
1. To understand the basics of stepper motor working.
2. To develop & write stepper motor program using Arduino Uno
platform and demonstrate it.
3. To implement your ideas and programming coding skill using
stepper motor.
Software and hardware required:
1. Arduino IDE
2. FCT make Arduino Circuit Board
Diagram:

Stepper motor control with Speed Control Potentiometer & Direction


Switch
Procedure:
1. Connect the Arduino Uno board to the PC through USB cable.
2. Start Arduino IDE from PC and open new Sketch and the program/code
for that and save as steppermotor.
3. Verify/Compile the program and Upload the code into Arduino Uno.
4. Make necessary connections according diagram.
5. Observe the output running on the board.
6. Repeat the procedure for other programs to implement your ideas and
programming coding skill.
Program:
int motorDirection = A1;
void setup() {
// put your setup code here, to run once:
pinMode(motorDirection, INPUT);

pinMode(2, OUTPUT); // Stepper A


pinMode(3, OUTPUT); // Stepper B
pinMode(4, OUTPUT); // Stepper C
pinMode(5, OUTPUT); // Stepper D
// enable =+5V
// enable pins are not defined and not used

}
void loop() {
// put your main code here, to run repeatedly:
int motorSpeed = analogRead(A0)/10;
if( motorSpeed > 100)
motorSpeed = 100;

if(digitalRead(motorDirection)==HIGH)
{
phaseA();
delay(motorSpeed);
phaseB();
delay(motorSpeed);
phaseC();
delay(motorSpeed);
phaseD();
delay(motorSpeed);

}
else
{
phaseD();
delay(motorSpeed);
phaseC();
delay(motorSpeed);
phaseB();
delay(motorSpeed);
phaseA();
delay(motorSpeed);
}
}
void phaseA()
{
// phase_a 0x0a
digitalWrite(2, LOW);
digitalWrite(3, HIGH);
digitalWrite(4, LOW);
digitalWrite(5, HIGH);
}
void phaseB()
{
// phase_b 0x06
digitalWrite(2, LOW);
digitalWrite(3, HIGH);
digitalWrite(4, HIGH);
digitalWrite(5, LOW);
}
void phaseC()
{
// phase_c 0x05
digitalWrite(2, HIGH);
digitalWrite(3, LOW);
digitalWrite(4, HIGH);
digitalWrite(5, LOW);
}
void phaseD()
{
// phase_d 0x09
digitalWrite(2, HIGH);
digitalWrite(3, LOW);
digitalWrite(4, LOW);
digitalWrite(5, HIGH);
}
Assignment No. 12: Demonstration of “Hello” message on LCD Display.

Aim: To demonstrate “Hello” message on LCD Display using Arduino Uno


Objectives:
1. To understand the basics of LCD working.
2. To develop & write LCD Display program using Arduino Uno
platform and demonstrate it.
3. To implement your ideas and programming coding skill using LCD
Software and hardware required:
1. Arduino IDE
2. FCT make Arduino Circuit Board
Diagram:

Message Displayed on LCD display


Procedure:
1. Connect the Arduino Uno board to the PC through USB cable.
2. Start Arduino IDE from PC and open new Sketch and the program/code
for that and save as LCD_mgs.
3. Verify/Compile the program and Upload the code into Arduino Uno.
4. Make necessary connections according diagram.
5. Observe the output running on the board.
6. Repeat the procedure for other programs to implement your ideas and
programming coding skill.
Program:
// Display Hello & College Name
#include<LiquidCrystal.h>
//pins of the LCD. (RS, E, D4, D5, D6, D7)
LiquidCrystal lcd(6, 7, 5, 4, 3, 2);
void setup()
{
Serial.begin(9600);
lcd.begin(16,2);
delay(500);
}
void loop()
{

lcd.setCursor(0,0);
lcd.print("*Hello*");
lcd.setCursor(0,1);
lcd.print("College of BBA(CA)");
delay(1000); //Delay of 1 second for ease of viewing in serial monitor
}
Assignment No. 13: Demonstration of reading analog voltage

Aim: To demonstrate reading analog voltage using Arduino Uno


Objectives:
1. To understand the details electrical parameter: analog voltage.
2. To develop & write reading analog voltage program using Arduino
Uno platform and demonstrate it.
3. To implement your ideas and programming coding skill using
analog input voltage and LCD display.
Software and hardware required:
1. Arduino IDE
2. FCT make Arduino Circuit Board
Diagram:

Reading analog voltage with LCD


Procedure:
1. Connect the Arduino Uno board to the PC through USB cable.
2. Start Arduino IDE from PC and open new Sketch and the program/code
for that and save as analog_volt.
3. Verify/Compile the program and Upload the code into Arduino Uno.
4. Make necessary connections according diagram.
5. Observe the output running on the board.
6. Repeat the procedure for other programs to implement your ideas and
programming coding skill.
Program:
/*
ReadAnalogVoltage
Reads an analog input on pin 0, converts it to voltage, and prints the
result to the Serial Monitor also on LCD.
Graphical representation is available using Serial Plotter (Tools >
Serial Plotter menu).
Attach the center pin of a potentiometer to pin A0, and the outside
pins to +5V and ground.

*/
#include<LiquidCrystal.h>
//pins of the LCD. (RS, E, D4, D5, D6, D7)
LiquidCrystal lcd(6, 7, 5, 4, 3, 2);

// the setup routine runs once when you press reset:


void setup() {
// initialize serial communication at 9600 bits per second:
Serial.begin(9600);
lcd.begin(16,2);
delay(500);
}
// the loop routine runs over and over again forever:
void loop() {
// read the input on analog pin 0:
int sensorValue = analogRead(A0);
// Convert the analog reading (which goes from 0 - 1023) to a
voltage (0 - 5V):
float voltage = sensorValue * (5.0 / 1023.0);
// print out the value you read:
Serial.println(voltage);
lcd.setCursor(0,0);
lcd.print("*Analog Volt**");
lcd.setCursor(0,1);
lcd.print(voltage);
lcd.print("Volt");
delay(1000); //Delay of 1 second
}
Assignment No. 14: Demonstration of Temperature sensor.

Aim: To demonstrate Temperature sensor application using Arduino Uno


Objectives:
1. To understand the basics of Temperature sensor LM35 working.
2. To develop & write Temperature sensor program using Arduino
Uno platform and demonstrate it.
3. To implement your ideas and programming coding skill using
LM35 .LED & LCD Arrays
Software and hardware required:
1. Arduino IDE
2. FCT make Arduino Circuit Board
Diagram:

Temperature Sensor with LCD and Indicators (LED & Buzzer )


Procedure:

1. Connect the Arduino Uno board to the PC through USB cable.


2. Start Arduino IDE from PC and open new Sketch and the program/code
for that and save as Temp_sensor.
3. Verify/Compile the program and Upload the code into Arduino Uno.
4. Make necessary connections according diagram.
5. Observe the output running on the board.
6. Repeat the procedure for other programs to implement your ideas and
programming coding skill.
Program:
#include<LiquidCrystal.h>
//pins of the LCD. (RS, E, D4, D5, D6, D7)
LiquidCrystal lcd(6, 7, 5, 4, 3, 2);

const int sensor=A0; // Assigning analog pin A1 to variable 'sensor'


float tempc; //variable to store temperature in degree Celsius
float tempf; //variable to store temperature in Fahreinheit
float vout; //temporary variable to hold sensor reading
int BUZ= 8;
int Red_LED = 9;
int Green_LED = 10;

void setup()
{
pinMode(Red_LED, OUTPUT);
pinMode(Green_LED, OUTPUT);
pinMode(BUZ, OUTPUT);
pinMode(sensor,INPUT); // Configuring pin A1 as input
Serial.begin(9600);
lcd.begin(16,2);
delay(500);
}
void loop()
{
char sign = 223;
vout=analogRead(sensor);
tempc = (vout*500)/1023;
//vout=vout* 0.48828125;
lcd.setCursor(0,0);
lcd.print("***Tempeature***");
lcd.setCursor(0,1);
lcd.print(tempc);
lcd.print(sign);
lcd.print("C ");
lcd.print(" ");
lcd.print((tempc*1.8)+32);
lcd.print(sign);
lcd.print("F ");
delay(1000); //Delay of 1 second for ease of viewing in serial monitor

if (tempc > 32)


{
digitalWrite(Red_LED, HIGH);
digitalWrite(Green_LED, LOW);
digitalWrite(BUZ, HIGH);
}
else if (tempc < 32)
{
digitalWrite(Green_LED, HIGH);
digitalWrite(Red_LED, LOW);
digitalWrite(BUZ, LOW);
}
}
Assignment No. 15: Demonstration of interfacing LDR based light control
with LED.
Aim: To demonstrate LDR based light control with LED application using
Arduino Uno
Objectives:
1. To understand the basics of LDR working.
2. To develop & write LDR based light control with LED program
using Arduino Uno platform and demonstrate it.
3. To implement your ideas and programming coding skill using LDR,
LED and LCD
Software and hardware required:
1. Arduino IDE
2. FCT make Arduino Circuit Board
Diagram:

LDR based light Control with LEDs


Procedure:
1. Connect the Arduino Uno board to the PC through USB cable.
2. Start Arduino IDE from PC and open new Sketch and the program/code
for that and save as LDR.
3. Verify/Compile the program and Upload the code into Arduino Uno.
4. Make necessary connections according diagram.
5. Observe the output running on the board.
6. Repeat the procedure for other programs to implement your ideas and
programming coding skill.
Program:

#include<LiquidCrystal.h>
//pins of the LCD. (RS, E, D4, D5, D6, D7)
LiquidCrystal lcd(6, 7, 5, 4, 3, 2);

const int LDR=A0; // Assigning analog pin A0 to variable 'sensor'


float vout; //temporary variable to hold sensor reading
int Red_LED = 9;
int Green_LED = 10;
int BUZ= 8;

void setup()
{

pinMode(Red_LED, OUTPUT);
pinMode(Green_LED, OUTPUT);
pinMode(BUZ, OUTPUT);

pinMode(LDR,INPUT); // Configuring pin A0 as input


Serial.begin(9600);
lcd.begin(16,2);
delay(500);
}
void loop()
{
vout = analogRead(LDR);
Serial.print("LDRvalue = ");
Serial.print(vout);

lcd.setCursor(0,0);
lcd.print("*Light Intensity*");
lcd.setCursor(0,1);
lcd.print(vout);
delay(1000); //Delay of 1 second for ease of viewing in serial monitor
if (vout <100)
{
digitalWrite(Red_LED, HIGH);
digitalWrite(Green_LED, LOW);
digitalWrite(BUZ, HIGH);
}
else
{
digitalWrite(Green_LED, HIGH);
digitalWrite(Red_LED, LOW);
digitalWrite(BUZ, LOW);
}
}

4 - Kits for All 16 Assignment Programming

You might also like