You are on page 1of 27

EMBEDDED SYSTEM LAB KIT

‘SMEI Make’ Embedded System Lab kit consists of all the sensor, modules required to perform
all the experiments as per the prescribed syllabus of Embedded System Lab. It’s a complete
package for providing a basic knowledge of Arduino Uno and making connection with various
sensors.

It consists of:
Arduino Uno board, Breadboard, Push Button, LED Array, Potentiometer, Servo motor,
Temperature sensor, I2C light sensor, few resistances, Jumper wires.

Arduino UNO

Introduction

Arduino is an open-source electronics platform based on easy-to-use hardware and software.


Arduino boards are able to read inputs - light on a sensor, a finger on a button, or a Text message
- and turn it into an output - activating a motor, turning on an LED, publishing something online.
You can tell your board what to do by sending a set of instructions to the microcontroller on the
board. To do so you use the Arduino programming language (based on Wiring), and the Arduino
Software (IDE), based on Processing.
Over the years Arduino has been the brain of thousands of projects, from everyday objects to
complex scientific instruments. A worldwide community of makers - students, hobbyists, artists,
programmers, and professionals - has gathered around this open-source platform, their
contributions have added up to an incredible amount of accessible knowledge that can be of great
help to novices and experts alike.
Arduino was born at the Ivrea Interaction Design Institute as an easy tool for fast prototyping,
aimed at students without a background in electronics and programming. As soon as it reached a
wider community, the Arduino board started changing to adapt to new needs and challenges,
differentiating its offer from simple 8-bit boards to products for IoT applications, wearable, 3D
printing, and embedded environments. All Arduino boards are completely open-source,
empowering users to build them independently and eventually adapt them to their particular needs.
The software, too, is open-source, and it is growing through the contributions of users worldwide.
Arduino has been used in thousands of different projects and applications. The Arduino software
is easy-to-use for beginners, yet flexible enough for advanced users. It runs on Mac, Windows,
and Linux. Teachers and students use it to build low cost scientific instruments, to prove chemistry
SCIENTICO MEDICO ENGINEERING INSTRUMENTS, AMBALA CANTT

and physics principles, or to get started with programming and robotics. Designers and architects
build interactive prototypes, musicians and artists use it for installations and to experiment with
new musical instruments. Arduino is a key tool to learn new things. Anyone - children, hobbyists,
artists, programmers - can start tinkering just following the step by step instructions of a kit, or
sharing ideas online with other members of the Arduino community.
There are many other microcontrollers and microcontroller platforms available for physical
computing. Parallax Basic Stamp, Netmedia's BX-24, Phidgets, MIT's Handyboard, and many
others offer similar functionality. All of these tools take the messy details of microcontroller
programming and wrap it up in an easy-to-use package. Arduino also simplifies the process of
working with microcontrollers, but it offers some advantage for teachers, students, and interested
amateurs over other systems:

Inexpensive - Arduino boards are relatively inexpensive compared to other microcontroller


platforms. The least expensive version of the Arduino module can be assembled by hand, and even
the pre-assembled Arduino modules cost is very less.

Cross-platform - The Arduino Software (IDE) runs on Windows, Macintosh OSX, and Linux
operating systems. Most microcontroller systems are limited to Windows.
Simple, clear programming environment - The Arduino Software (IDE) is easy-to-use for
beginners, yet flexible enough for advanced users to take advantage of as well. For teachers, it's
conveniently based on the Processing programming environment, so students learning to program
in that environment will be familiar with how the Arduino IDE works.

Open source and extensible software - The Arduino software is published as open source tools,
available for extension by experienced programmers. The language can be expanded through C++
libraries, and people wanting to understand the technical details can make the leap from Arduino
to the AVR C programming language on which it's based. Similarly, you can add AVR-C code
directly into your Arduino programs if you want to.

Open source and extensible hardware - The plans of the Arduino boards are published under a
Creative Commons license, so experienced circuit designers can make their own version of the

www.scienticomedico.com, abhi.smei@gmail.com, 0171-2972168, 9416192168 2|P ag e


SCIENTICO MEDICO ENGINEERING INSTRUMENTS, AMBALA CANTT

module, extending it and improving it. Even relatively inexperienced users can build the
breadboard version of the module in order to understand how it works and save money.
HOW TO GET STARTED WITH ARDUINO UNO

SMEI MAKE IOT Lab Trainer consists of Arduino Uno both heart and brain of the trainer.
To use Arduino Uno follow the following steps.

Step 1
Download the IDE from the official Arduino website www.arduino.cc. Since the Arduino uses a
USB to serial converter (which allow it to communicate with the host computer), the Arduino
board is compatible with most computers that have a USB port. Once downloaded, install the IDE
and ensure that you enable most (if not all) of the options, INCLUDING the drivers.

Step 2
After connecting the Arduino Uno board using USB cable. Next step is to get Arduino Com Port
Number. For getting com port, right click on ‘Computer’ in the ‘Start Menu’ and click ‘Manage’.
A “Computer Management” pop-up menu will open. Clicking the device manger on the left menu
will show the com port number. Windows can change the com port so, it is advisable to check the
com port on every start.

Step 3
Now, we have to configure the IDE i.e arduino software. This means we have to tell which arduino
board we are going to connect and on which com port.
For this we will open IDE and click Tools Tab and Board as “Arduino / Genuino UNO”. And by
clicking PORT we will going to select “COM #” (# is the number which will get from the previous
step).

Step 4
Loading the Basic Example will make on board LED blink for a second and continuously.
To load this example, click File > Examples > 01.Basics > Blink.

With the example loaded, it’s time to verify and upload the code. The verify stage checks the code
for errors, then compiles the ready-for-uploading code to the Arduino.
To verify and compile the code, press the check mark button in the upper left window.
If the compilation stage was successful, upload the code in the Arduino Uno. To do this, click the
arrow next to the check mark.

www.scienticomedico.com, abhi.smei@gmail.com, 0171-2972168, 9416192168 3|P ag e


SCIENTICO MEDICO ENGINEERING INSTRUMENTS, AMBALA CANTT

Technical Specifications of Arduino UNO

Microcontroller ATmega328P
Operating Voltage 5V
Input Voltage (recommended) 7-12V
Input Voltage (limit) 6-20V
Digital I/O Pins 14 (of which 6 provide PWM output)
PWM Digital I/O Pins 6
Analog Input Pins 6
DC Current per I/O Pin 20 mA
DC Current for 3.3V Pin 50 mA
Flash Memory 32 KB (ATmega328P) of which 0.5 KB used by bootloader
SRAM 2 KB (ATmega328P)
EEPROM 1 KB (ATmega328P)
Clock Speed 16 MHz
LED_BUILTIN 13
Length 68.6 mm
Width 53.4 mm

www.scienticomedico.com, abhi.smei@gmail.com, 0171-2972168, 9416192168 4|P ag e


SCIENTICO MEDICO ENGINEERING INSTRUMENTS, AMBALA CANTT

PIN Configuration of Arduino Uno

Pin type Definitions

Reset Reset Arduino Sketch on Board


3v3 3.3 V in & out
5v 5 V in & out
Gnd Ground
Vin Voltage IN for sources over 7V (9V – 12V)
Analog In Analog inputs, can also be used as Digital
Rx / Tx Serial comm. Receive and Transmit
Digital In /Out Input or output, HIGH or LOW
PWM (~) Digital pins with output option of PWM
ARef External reference voltage used for analog

www.scienticomedico.com, abhi.smei@gmail.com, 0171-2972168, 9416192168 5|P ag e


SCIENTICO MEDICO ENGINEERING INSTRUMENTS, AMBALA CANTT

For connecting LCD to arduino, follow the following steps

LCD Pin -> Arduino Pin


4 -> 12
6 -> 11
11 -> 5
12 -> 4
13 -> 3
14 -> 2

LCD Pin -> Rail of the breadboard


1,5,16 -> GND
2 -> 5V
15 -> 5V (using the 220 ohm resistor!)
3 -> Middle pin of 10K pot. (Connect Vcc and Gnd to remaining pins of pot)

User interface, or UI, describes the way in which a human interacts with a machine. Though
technically something as simple as a light switch could be considered an instrument of UI, most
modern references relate to computers and other electronic devices.

UI makes the exchange between users and machines possible. Without it, this vital form of
communication ceases to exist.

There are four prevalent types of user interface and each has a range of advantages and
disadvantages:

 Command Line Interface


 Menu-driven Interface
 Graphical User Interface
 Touchscreen Graphical User Interface

Command Line Interface


The command line interface is no longer common as a form of basic user interface in everyday
consumer products, but it is still in use under certain circumstances. Command Line Interface
requires users to type appropriate instructions into the command line. The computer is commanded
to first go to the required file or directory. From there, a whole host of commands become
available, from retrieving files to running programs.

Advantages:

www.scienticomedico.com, abhi.smei@gmail.com, 0171-2972168, 9416192168 6|P ag e


SCIENTICO MEDICO ENGINEERING INSTRUMENTS, AMBALA CANTT

 Simple structure
 Minimal memory usage
 Great for slow-running computers, or those low on memory
 An expert CLI user can give commands and perform tasks much faster than when using an
alternative UI type
Disadvantages:

 Difficult to learn command language


 Complex for novice users
 Minimal error message information
 Menu-Driven Interface
 The menu-driven user interface provides you with a range of commands or options in the
form of a list or menu displayed in full-screen, pop-up, pull-down, or drop-down. An ATM
is an example of a menu-driven interface.

Advantages:

 It is not necessary to remember a long list of manual commands


 Simple interface for novices
 Self-explanatory menu options
Disadvantages:

 Slower for experienced users


 Limited menu options
 Often requires you to access multiple menu screens to perform simple functions
Graphical User Interface
The graphical user interface, or GUI, is the type of interface with which the majority of people are
the most familiar. You interact with these interfaces by using a mouse, tack pad, or other peripheral
to point and click on graphics or icons.

Advantages:

 Self-explanatory
 Easy to use
 Memorizing command lists is not necessary
 Allows for running multiple applications, programs, and tasks simultaneously
 Solid support facilities
 The similar format among different programs adds familiarity
 WYSIWYG makes for easy design and formatting
Disadvantages:

www.scienticomedico.com, abhi.smei@gmail.com, 0171-2972168, 9416192168 7|P ag e


SCIENTICO MEDICO ENGINEERING INSTRUMENTS, AMBALA CANTT

 Uses large amounts of memory – although this is less of a concern as computers get more
powerful
Touchscreen Graphical User Interface
The touchscreen GUI is very similar to the regular GUI, except that you use your fingers or a stylus
to select icons and perform tasks, rather than a mouse or trackpad. Touchscreen GUIs are
commonly found on tablets, smartphones, and medical devices, like the t:slim insulin pump. The
touchscreen GUI has the same benefits and disadvantages as standard GUIs, but also offers a more
intimate method of interaction. The lack of peripherals makes touchscreen GUIs very convenient.

Of the four types of user interface, the graphical user interface is by far the most common, followed
by the touchscreen variation. Despite the alternative technologies that already exist and continue
to emerge, the GUI remains the preferred standard. This is largely due to the simplicity and ease
of use.

Graphical user interfaces are easier for most end users to understand as the icons and menus are
generally self-explanatory and the GUI does not require the user to remember or input complex
commands.

While they do take up considerable memory space compared to other UIs, this is a secondary
concern as devices continue to have larger, more efficient storage than their predecessors.

www.scienticomedico.com, abhi.smei@gmail.com, 0171-2972168, 9416192168 8|P ag e


SCIENTICO MEDICO ENGINEERING INSTRUMENTS, AMBALA CANTT

ARDUINO – BOOLEAN AND BITWISE OPERATORS


https://www.tutorialspoint.com/arduino/arduino_operators.htm
An operator is a symbol that tells the compiler to perform specific mathematical or logical
functions.
BOOLEAN OPERATORS
There are 3 logical operators in Arduino IDE:

LOGICAL OPERATOR OPERATOR SYMBOL EXAMPLE

OR || a || b

AND && a && b

NOT ! !a

Truth Table of OR Operator

X1 X2 Y = X1 || X2

0 0 0

0 1 1

1 0 1

1 1 1

Truth Table of AND Operator

X1 X2 Y = X1 && X2

0 0 0

0 1 0

1 0 0

1 1 1

Truth Table of NOT Operator

X Y=!X

0 0

www.scienticomedico.com, abhi.smei@gmail.com, 0171-2972168, 9416192168 9|P ag e


SCIENTICO MEDICO ENGINEERING INSTRUMENTS, AMBALA CANTT

X Y=!X

0 0

BITWISE OPERATORS
Change numbers to hexadecimal and then BCD
Assume variable A = 60 (0x3c) and variable B = 13 (0xd) then

Operator Operator Description Example


name simple

(A & B) will give


Binary AND Operator copies a bit to the result if
and & 12 which is 0000
it exists in both operands. 00111100 & 00001100
1100

Binary OR Operator copies a bit if it exists in (A | B) will give 61


or |
either operand 00111100 | 00001100 which is 0011 1101

Binary XOR Operator copies the bit if it is set in (A ^ B) will give 49


xor ^
one operand but not both. 00111100 ^ 00001100 which is 0011 0001

Binary Ones Complement Operator is unary and (~A ) will give -61
not ~
has the effect of 'flipping' bits. ~ 00111100 which is 0011 1101

Binary Left Shift Operator. The left operands


A << 2 will give
value is moved left by the number of bits specified
shift left << 240 which is 1111
by the right operand.
0000
00111100 <<2

Binary Right Shift Operator. The left operands


value is moved right by the number of bits A >> 2 will give 15
shift right >>
specified by the right operand. which is 0000 1111
00111100 >>2

www.scienticomedico.com, abhi.smei@gmail.com, 0171-2972168, 9416192168 10 | P a g e


SCIENTICO MEDICO ENGINEERING INSTRUMENTS, AMBALA CANTT

COMPOUND OPERATORS
Assume variable A holds 10 and variable B holds 20 then –

Operator name Operator Description Example


simple

Increment operator, increases integer value


increment ++ A++ will give 11
by one

Decrement operator, decreases integer value


decrement -- A-- will give 9
by one

Add AND assignment operator. It adds right B += A is


compound
+= operand to the left operand and assign the equivalent to B =
addition
result to left operand B+ A

Subtract AND assignment operator. It B -= A is


compound
-= subtracts right operand from the left operand equivalent to B =
subtraction
and assign the result to left operand B-A

Multiply AND assignment operator. It B*= A is


compound
*= multiplies right operand with the left equivalent to B =
multiplication
operand and assign the result to left operand B* A

Divide AND assignment operator. It divides B /= A is


compound
/= left operand with the right operand and equivalent to B =
division
assign the result to left operand B/A

Modulus AND assignment operator. It takes B %= A is


compound
%= modulus using two operands and assign the equivalent to B =
modulo
result to left operand B%A

compound bitwise inclusive OR and assignment A |= 2 is same as


|=
bitwise or operator A=A|2

compound A &= 2 is same


&= Bitwise AND assignment operator
bitwise and as A = A & 2

www.scienticomedico.com, abhi.smei@gmail.com, 0171-2972168, 9416192168 11 | P a g e


SCIENTICO MEDICO ENGINEERING INSTRUMENTS, AMBALA CANTT

EXPERIMENTS
Experiment No. 1
Bulit-in LED state Control by push button sketch implementation

Connections

1. Connect data cable to usb port and upload the code.


2. Connect one leg of button to Pin 2 of Arduino and other to GND
pin of Arduino.
3. Press button and observe the change in LED.

Soft code
const int BUTTON = 2;
int BUTTONstate = 0;

void setup()
{
pinMode(BUTTON, INPUT); // or INPUT_PULLUP
pinMode(LED_BUILTIN, OUTPUT);
}

void loop()
{
BUTTONstate = digitalRead(BUTTON);
if (BUTTONstate == LOW)
{
digitalWrite(LED_BUILTIN, LOW);
}
else{
digitalWrite(LED_BUILTIN, HIGH);
}
}

www.scienticomedico.com, abhi.smei@gmail.com, 0171-2972168, 9416192168 12 | P a g e


SCIENTICO MEDICO ENGINEERING INSTRUMENTS, AMBALA CANTT

EXPERIMENT NO. 2
Bulit-in LED blinking sketch implementation.

Connections

1. Connect data cable to usb port and upload the code.


2. Observe LED at position L marked on the board starts blinking.
3. By changing the value of delay LED ON or OFF time will vary.

Soft code

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
}

www.scienticomedico.com, abhi.smei@gmail.com, 0171-2972168, 9416192168 13 | P a g e


SCIENTICO MEDICO ENGINEERING INSTRUMENTS, AMBALA CANTT

`EXPERIMENT NO. 3
Built-in LED blinking by toggling states based on Binary Operation.

Connections

1. Connect data cable to usb port and upload the code.


2. Connect one leg of button to Pin 2 of Arduino and other to GND
pin of Arduino.
3. Observe LED at position L marked on the board starts blinking.
4. Press button and observe the change in LED.
5. By changing the value of delay LED ON or OFF time will vary.

Soft code

const int BUTTON = 2;


int BUTTONstate = 0;

void setup()
{
pinMode(BUTTON, INPUT_PULLUP);
pinMode(LED_BUILTIN, OUTPUT);
}

void loop()
{
BUTTONstate = digitalRead(BUTTON);
if (BUTTONstate == LOW)
{
digitalWrite (LED_BUILTIN, HIGH);
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

}
else{
digitalWrite(LED_BUILTIN, LOW);
}
}

www.scienticomedico.com, abhi.smei@gmail.com, 0171-2972168, 9416192168 14 | P a g e


SCIENTICO MEDICO ENGINEERING INSTRUMENTS, AMBALA CANTT

EXPERIMENT NO. 4
Built-in LED state control by user interface through serial port.
Connections

1. Connect data cable to usb port and upload the code.

Soft code

void setup()
{
pinMode(LED_BUILTIN, OUTPUT);
Serial.begin(9600);
while (!Serial);
Serial.println("Input 1 to Turn LED on and 2 to Turn LED off");
}
void loop() {
if (Serial.available())
{
int state = Serial.parseInt();
if (state == 1)
{
digitalWrite(LED_BUILTIN, HIGH);
Serial.println("Command completed LED turned ON");
}
if (state == 2)
{
digitalWrite(LED_BUILTIN, LOW);
Serial.println("Command completed LED turned OFF");
}
}
}

www.scienticomedico.com, abhi.smei@gmail.com, 0171-2972168, 9416192168 15 | P a g e


SCIENTICO MEDICO ENGINEERING INSTRUMENTS, AMBALA CANTT

EXPERIMENT NO. 5
User interface for Boolean Operation and bitwise operation through
serial port.

Connections
1. Connect data cable to usb port and upload the code.
Soft code for Boolean Operation
int a = 9;
int b = 4;
void setup(){
Serial.begin(9600);
}
void loop () {
bool c = false;
if((a > b)&& (b < a))
{
c = true;
Serial.println("True1");
}
else
{ c = false;
Serial.println("False1");}
if((a == b)|| (b < a))
{ c = true;
Serial.println("True2");}
else
{ c = false;
Serial.println("False2");}

if( !(a == b)&& (b < a))


{ c = true;
Serial.println("True3");}
else
{c = false;
Serial.println("False3");}
delay(1000);
}

Result for Boolean Operation


True1
True2
True3 and so on…

www.scienticomedico.com, abhi.smei@gmail.com, 0171-2972168, 9416192168 16 | P a g e


SCIENTICO MEDICO ENGINEERING INSTRUMENTS, AMBALA CANTT

Soft code for bitwise operation


// Change numbers to hexadecimal and then BCD
int a = 60;
int b = 13;
int c = 0;

void setup(){
Serial.begin(9600);

c = (a & b) ;
Serial.println(c);

c = a | b ;
Serial.println(c);

c = a ^ b ;
Serial.println(c);

c = ~a ;
Serial.println(c);

c = a << 2 ;
Serial.println(c);

c = a >> 2 ;
Serial.println(c);

delay(1000);

void loop () {

Result for Bitwise Operation

(A & B) will give 12 which is 0000 1100


(A | B) will give 61 which is 0011 1101

(A ^ B) will give 49 which is 0011 0001

(~A ) will give -61 which is 0011 1101


A << 2 will give 240 which is 1111 0000

A >> 2 will give 15 which is 0000 1111

Note: It will show the result only once.

www.scienticomedico.com, abhi.smei@gmail.com, 0171-2972168, 9416192168 17 | P a g e


SCIENTICO MEDICO ENGINEERING INSTRUMENTS, AMBALA CANTT

EXPERIMENT NO. 6
User interface for compounded operation through serial port.

Connections

1. Connect data cable to usb port and upload the code.

Soft code

int a = 10;
int b = 20;
int c = 0;

void setup(){
Serial.begin(9600);

a++; // initially a = 10; result = 11


Serial.println(a);

a--; // now initially a = 11; result = 10


Serial.println(a);

b += a; // now initially a = 10, b = 20; result = 30


Serial.println(b);

b -= a; // now initially a = 10, b = 30; result = 20


Serial.println(b);

b *= a; // now initially a = 10, b = 20; result = 200


Serial.println(b);

b /= a; // now initially a = 10, b = 200; result = 20


Serial.println(b);

a %= b; // now initially a = 10, b = 20; result = 10


Serial.println(a);

a |= b; // now initially a = 10, b = 10; result = 30


Serial.println(a);

a &= b; // now initially a = 10, b = 30; result = 20


Serial.println(a);

delay(1);

void loop () {

www.scienticomedico.com, abhi.smei@gmail.com, 0171-2972168, 9416192168 18 | P a g e


SCIENTICO MEDICO ENGINEERING INSTRUMENTS, AMBALA CANTT

EXPERIMENT NO. 7
Looping mechanism to check the state of pin and if change, print its
status on serial port.

Connections

1. Connect data cable to usb port and upload the code.

Soft code

int buttonPin = 2; // the number of the pushbutton pin

// variables will change:


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

void setup() {

// initialize the LED pin as an output:


pinMode(LED_BUILTIN, OUTPUT);

// initialize the pushbutton pin as an input:


pinMode(buttonPin, INPUT_PULLUP);

Serial.begin(9600);
}

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 == LOW) {
// turn LED on:
digitalWrite(LED_BUILTIN, HIGH);
Serial.println("Button is ON");

} else {
// turn LED off:
digitalWrite(LED_BUILTIN, LOW);
Serial.println("Button is OFF");
}
delay(500);
}

www.scienticomedico.com, abhi.smei@gmail.com, 0171-2972168, 9416192168 19 | P a g e


SCIENTICO MEDICO ENGINEERING INSTRUMENTS, AMBALA CANTT

EXPERIMENT NO. 8
Controlling multiple LEDs with a loop and array.
Blinking Multiple LEDs with a loop and array

Connections

1. Connect data cable to usb port and upload the code.


2. Connect LED array to Arduino. Gnd of LED array to GND of Arduino.
Positive of LED1, LED2, LED3 to Pin No. 9,10,11 of Arduino
respectively.
3. Observe LEDs blinking.
4. By changing the value and position of delay() will control LED ON or
OFF in different patterns.

Soft code

#define LED_PIN_1 11
#define LED_PIN_2 10
#define LED_PIN_3 9
#define LED_NUMBER 3
byte LEDPinArray[LED_NUMBER] = { LED_PIN_1,
LED_PIN_2,
LED_PIN_3 };
void setup()
{
for (int i = 0; i < LED_NUMBER; i++) {
pinMode(LEDPinArray[i], OUTPUT);
}
}

void loop()
{
for (int i = 0; i < LED_NUMBER; i++) {
digitalWrite(LEDPinArray[i], HIGH);
//delay(1000);
}
delay(100);
for (int i = 0; i < LED_NUMBER; i++) {
digitalWrite(LEDPinArray[i], LOW);
//delay(1000);
}
delay(100);
}

www.scienticomedico.com, abhi.smei@gmail.com, 0171-2972168, 9416192168 20 | P a g e


SCIENTICO MEDICO ENGINEERING INSTRUMENTS, AMBALA CANTT

EXPERIMENT NO. 9
Use a potentiometer to control the blinking of a LED.
Connections

1. Connect data cable to usb port and upload the code.


2. Connect Pot to Arduino. Gnd of Pot to GND of Arduino. Positive of
Pot to Positive of Arduino. Middle pin of Pot to A0 of Arduino.
3. You can observe blinking of in-built LED or you can connect an external
one as shown previously.
4. By changing the position of pot blinking pattern of LED can be
observed.

Soft code
void setup() {
// put your setup code here, to run once:
// designate pin 13 as an OUTPUT pin for the LED
pinMode (13, OUTPUT);
// designate pin A0 as an Analog INPUT for the potentiometer
pinMode (A0, INPUT);
Serial.begin(9600);
}

void loop() {
// put your main code here, to run repeatedly:

int potValue = analogRead (A0);

Serial.println (potValue);
//potValue = map(potValue, 0, 1023, 0, 255);
//Serial.println (potValue);
digitalWrite (13, HIGH);
delay (potValue);
digitalWrite (13, LOW);
delay (potValue);
}

www.scienticomedico.com, abhi.smei@gmail.com, 0171-2972168, 9416192168 21 | P a g e


SCIENTICO MEDICO ENGINEERING INSTRUMENTS, AMBALA CANTT

EXPERIMENT NO. 10
Uses an analog output (PWM pin) to fade an LED.
Connections

1. Connect data cable to usb port and upload the code.


2. Connect LED to Arduino. Gnd of LED to GND of Arduino through
resistance. Positive of LED to Pin9 of Arduino.
3. You can observe fading of LED.
4. By changing the fadeAmount and delay different fading patterns can
be observed.

Soft code

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


int brightness = 0; // how bright the LED is
int fadeAmount = 15; // 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 80 milliseconds to see the dimming effect
delay(80);
}

NOTE: This effect will not appear if LED is not connected to PWM pin

www.scienticomedico.com, abhi.smei@gmail.com, 0171-2972168, 9416192168 22 | P a g e


SCIENTICO MEDICO ENGINEERING INSTRUMENTS, AMBALA CANTT

EXPERIMENT NO. 11
Servomotor control using PWM.

Connections

1. Connect data cable to usb port and upload the code.


2. Connect red wire of servo motor to positive of Arduino. Brown
wire of servo motor to GND pin of Arduino and Orange wire of
servo motor to pin 3 of Arduino.
3. You can observe turning of servo motor in different angles.

Soft code

The following code will turn a servo motor to 0 degrees, wait 1 second,
then turn it to 90, wait one more second, turn it to 180, and then go
back.

// Include the Servo library


#include <Servo.h>
// Declare the Servo pin
int servoPin = 3;
// Create a servo object
Servo Servo1;
void setup() {
// We need to attach the servo to the used pin number
Servo1.attach(servoPin);
}
void loop(){
// Make servo go to 0 degrees
Servo1.write(0);
delay(1000);
// Make servo go to 90 degrees
Servo1.write(90);
delay(1000);
// Make servo go to 180 degrees
Servo1.write(180);
delay(1000);
}

www.scienticomedico.com, abhi.smei@gmail.com, 0171-2972168, 9416192168 23 | P a g e


SCIENTICO MEDICO ENGINEERING INSTRUMENTS, AMBALA CANTT

EXPERIMENT NO. 12
Temperature Sensor interfacing and sending its reading over serial port

Connections
1. Connect data cable to usb port and upload the code.
2. Connect middle pin of LM35 to A1 of Arduino. Pin1 of LM35 to Positive
pin of Arduino and rest one to Gnd of Arduino.
3. You can observe room temperature in serial monitor.

Soft code
int val;
int tempPin = A1;
void setup()
{
Serial.begin(9600);
}
void loop()
{
val = analogRead(tempPin);
float mv = ( val/1024.0)*5000;
float cel = mv/10;
float farh = (cel*9)/5 + 32;
Serial.println("Scientico Medico Engineering Instruments ");
Serial.print("TEMPERATURE = ");
Serial.print(cel);
Serial.print("*C");
Serial.println();
delay(1000);
/* uncomment this to get temperature in Fahrenheit
Serial.print("TEMPRATURE = ");
Serial.print(farh);
Serial.print("*F");
Serial.println();
*/
}

www.scienticomedico.com, abhi.smei@gmail.com, 0171-2972168, 9416192168 24 | P a g e


SCIENTICO MEDICO ENGINEERING INSTRUMENTS, AMBALA CANTT

EXPERIMENT NO. 13

//https://randomnerdtutorials.com/arduino-bh1750-ambient-light-sensor/

The BH1750 is a 16-bit ambient light sensor that communicates via I2C protocol. It outputs
luminosity measurements in lux (SI-derived unit of illuminance). It can measure a minimum
of 1 lux and a maximum of 65535 lux.

BH1750 Features
Here’s a list of the BH1750 sensor features. For more information consult the BH1750 sensor
datasheet.

 I2C bus Interface


 Spectral responsibility is approximately human eye response
 Illuminance to digital converter
 Range: 1 – 65535 lux
 Low current by power down function
 50Hz / 60Hz Light noise reject-function
 It is possible to select 2 different I2 C slave-addresses
 Small measurement variation (+/- 20%)
 The influence of infrared is very small
 Supports continuous measurement mode
 Supports one-time measurement mode

Measurement Modes
The sensor supports two different measurement modes: continuous measurement mode, and
one-time measurement mode. Each mode supports three different resolution modes.

In continuous measurement mode, the sensor continuously measures ambient light values. In
one-time measurement mode, the sensor measures the ambient light value once, and then it
goes to power down mode.

Applications
The BH1750 is an ambient light sensor so it can be used in a wide variety of projects. For
example:
 to detect if it is day or night;
 to adjust or turn on/off LED’s brightness accordingly to ambient light;
 to adjust LCDs and screen’s brightness;
 to detect if an LED is lit;

www.scienticomedico.com, abhi.smei@gmail.com, 0171-2972168, 9416192168 25 | P a g e


SCIENTICO MEDICO ENGINEERING INSTRUMENTS, AMBALA CANTT

BH1750 Pinout:

VCC Powers the sensor (3.3V or 5V)

GND Common GND

SCL SCL pin for I2C communication

SDA (Data) SDA pin for I2C communication

ADD* Selects address

The ADD pin is used to set the I2C sensor address. If the voltage on that pin is less than 0.7VCC
(pin is left floating or connected to GND), the I2C address is 0x23. But, if the voltage is higher
than 0.7xVCC (pin is connected to VCC), the address is 0x5C. In summary:
 ADD pin floating or connected to GND → address: 0x23
 ADD pin connected to VCC → address: 0x5C

BH1750 I2C Interface

The BH1750 ambient light sensor supports I2C interface.

BH1750 Arduino

VCC 5V

GND GND

SCL A5

SDA (Data) A4

ADD* Don’t connect

By not connecting the ADD pin, we’re selecting 0x23 I2C address. Connect it to 3.3V to select
0x5C address instead.

www.scienticomedico.com, abhi.smei@gmail.com, 0171-2972168, 9416192168 26 | P a g e


SCIENTICO MEDICO ENGINEERING INSTRUMENTS, AMBALA CANTT

Soft Code

#include <Wire.h>
#include <BH1750.h>

BH1750 lightMeter;

void setup(){

Serial.begin(9600);

// Initialize the I2C bus (BH1750 library doesn't do this automatically)


Wire.begin();

// On esp8266 you can select SCL and SDA pins using Wire.begin(D4, D3);
// For Wemos / Lolin D1 Mini Pro and the Ambient Light shield use Wire.begin(D2, D1);

lightMeter.begin();

Serial.println(F("BH1750 Test begin"));


}

void loop() {
float lux = lightMeter.readLightLevel();
Serial.print("Light: ");
Serial.print(lux);
Serial.println(" lx");
delay(1000);
}

www.scienticomedico.com, abhi.smei@gmail.com, 0171-2972168, 9416192168 27 | P a g e

You might also like