You are on page 1of 18

MECHATRONICS

(Module 3)

Arduino Programming

Department of Electronics and Communication Engineering


Index
 Arduino Programming with
 Interfacing of LED with Arduino
 Interfacing of switch with Arduino
Module Learning Outcomes
 Construct prototype circuits and connect them to the Arduino

 Design low level Smart systems applications.


LED (Light Emitting Diode):

Types of LEDs:
LED Electrical characteristics:
Item Symbol Absolute Maximum Rating
Forward Current IF 20mA
Peak Forward Current IFP 30mA
Suggestion Current ISU 14 - 18 mA
Forward Voltage VF 1.8 – 2.2 V

𝑉𝑠 − 𝑉𝐹 5𝑉 − 2𝑉
𝑅𝑠 = = = 100𝛺
𝐼𝐹 30𝑚𝐴
Activity
 Draw the 2nd LED into the circuit diagram in series with first
LED. (2M)
 Wire a breadboard LED light circuit to get two LEDs to light
up which are in series. (2M)
 What happens to the brightness of the LEDs. (2M)
 Evaluate and reconstruct the circuit to overcome the problem
of the brightness of the LEDs. (4M)

Assessment Process:
Question TLO Addressed CO Addressed
1 TLO 4 CO 1
2 TLO 4 CO 1
3 TLO 4 CO 1
4 TLO 4 CO 1
Connection of LED to an Arduino board:

VCC

222 Ohm
13
PIN 222 Ohm
LED

11
ARDUINO BOARD PIN

ARDUINO BOARD LED

ACTIVE HIGH-LED CONNECTED TO PIN-13 ACTIVE LOW-LED CONNECTED TO PIN-11


Aim: To turn ON an LED (Active High)

Equipment's Required:
SOURCE CODE:
void setup()
{
// put your setup code here, to run once:
pinMode(13,OUTPUT); //Configure digital pin 13 as output
}
void loop()
{
//put your main code here, to run repeatedly:
digitalWrite(13,HIGH); //To make LED ON connected to pin 13
}
CIRCUIT: 222 Ohm
13
PIN
LED

ARDUINO BOARD

ACTIVE HIGH-LED CONNECTED TO PIN-13


Activity
1. To blink an LED with a duration of 1-sec (3M)
(Turn ON an LED for 1-sec and turn OFF for 1-sec )
2. To blink two-LEDs with a duration of 2-sec (3M)
(Turn ON both LEDs for 1-sec and turn OFF both for 1-sec )
3. To blink an alternate LED with a duration of 3-sec (4M)
(Turn ON one LED and turn OFF another LED for 3-sec
and vice-versa)
Switches
 A switch is a device which is designed to interrupt the
current flow in a circuit, in other words, it can make or
break an electrical circuit.
Aim: To turn ON an LED (Active High) when switch pressed
(Active Low) using Arduino Mega 2560.

Equipment's Required:
1. Personal computer/Laptop/Mobile
2. Arduino software
3. Arduino Mega 2560 board
4. Universal Serial Bus(USB) Cable
5. Bread Board
6. Connecting Wires
7. Push button Switch
8. Light Emitting Diode(LED)
9. Resistor(220Ω)
Connection of LED to an Arduino board:

VCC

222 Ohm
13
PIN 222 Ohm
LED

11
ARDUINO BOARD PIN

ARDUINO BOARD LED

ACTIVE HIGH-LED CONNECTED TO PIN-13 ACTIVE LOW-LED CONNECTED TO PIN-11


Switch (Push Button):

Connection of switch to Arduino:


VCC VCC

8
222 Ohm PIN

switch
8
PIN 222 Ohm
ARDUINO BOARD
switch

ARDUINO BOARD

ACTIVE LOW-SWITCH ACTIVE HIGH-SWITCH


CIRCUIT(SCHEMATIC):
SOURCE CODE:
void setup()
{
pinMode(8,INPUT); //Configure digital pin 8 as input
pinMode(13,OUTPUT); //Configure digital pin 13 as output
}
void loop()
{
int x = digitalRead(8);
if(x == LOW) // Switch is Pressed or not
{
//To make LED ON
digitalWrite(13,HIGH);
}
else
{
//To make LED OFF
digitalWrite(13,LOW);
}
}
Activity
1. Design mechatronics system such that
LED1 should glow during the switch1
is pressed and LED2 should glow
during the switch2 is pressed. (LED-
active high, switch-active high). (5M)
2. Design mechatronics system such that
LED should glow during both the
switches are pressed. (LED-active
Low, switch-active high) (5M)
THANK YOU

Questions…..?

You might also like