workshop on microcontroller - mohammed abdul …...workshop on “microcontroller based project...

Post on 22-May-2020

6 Views

Category:

Documents

0 Downloads

Preview:

Click to see full reader

TRANSCRIPT

Workshop on “Microcontroller Based

Project Development”

Presented By

Mohammed Abdul Kader

Assistant Professor, Dept. of EEE, IIUC

Email:kader05cuet@gmail.com Website: kader05cuet.wordpress.com

Organized by: EEE Club

What is Micro-Computer (Computer)?

Workshop on "Microcontroller Based Project Development", Organized by EEE Club 2

Micro-computer is a system which consist at least the following components

• Microprocessor

• Memory

• Input Port

• Output Port

What is Microcontroller?

Workshop on "Microcontroller Based Project Development", Organized by EEE Club 3

• Central Processing Unit

• Memory Unit

• System Bus

• Input/Output Unit

• Serial Communication

• Timer Unit.

• Watchdog

• Analog to Digital Converter

• Oscillator

A microcontroller may consist of

following functional units:

Micro-computer in a single chip.

Workshop on "Microcontroller Based Project Development", Organized by EEE Club 4

Central Processing Unit (CPU)- Microprocessor

It takes binary data from memory or input device and provides output processing

the data as per user instruction.

ROM

(RAM)

Input

(instruction)

[

(instruction)

]

Output

Workshop on "Microcontroller Based Project Development", Organized by EEE Club 5

System Bus

Microprocessor

MWTC

MRDC

IOWC

IORC

Address Bus

Data Bus

Read Only

Memory

ROM

Read/Write

Memory

RAM

Keyboard Printer

Workshop on "Microcontroller Based Project Development", Organized by EEE Club 6

Memory Unit

• Read Only Memory (ROM): Program Memory

• Random Access Memory (RAM): To store data (variables)

• Electrically Erasable Programmable ROM (EEPROM): Store data (variable) even

power source is shutdown.

Workshop on "Microcontroller Based Project Development", Organized by EEE Club 7

In order to make the microcontroller useful, it is necessary to connect it to peripheral devices.

Each microcontroller has one or more registers (called a port) connected to the

microcontroller pins. Why do we call them input/output ports? Because it is possible to

change a pin function according to the user's needs.

Input/output ports (I/O Ports)

Workshop on "Microcontroller Based Project Development", Organized by EEE Club 8

Timer/Counters

These are act as "stopwatches" or, “external event counter”. These are commonly 8-

or 16-bit SFRs the contents of which is automatically incremented by each coming pulse.

Workshop on "Microcontroller Based Project Development", Organized by EEE Club 9

Serial communication

The most commonly used serial

communication systems are:

• I2C (Inter Integrated Circuit)

• SPI (Serial Peripheral Interface Bus)

• UART (Universal Asynchronous

Receiver/Transmitter)

Workshop on "Microcontroller Based Project Development", Organized by EEE Club 10

Watchdog Timer

Workshop on "Microcontroller Based Project Development", Organized by EEE Club 11

Analog to Digital Converter (ADC)

An analogue to digital converter is an electronic circuit which converts continuous signals to discrete

digital numbers. In other words, this circuit converts an analogue value into a binary number and

passes it to the CPU for further processing. This module is therefore used for input pin voltage

measurement (analogue value).

Workshop on "Microcontroller Based Project Development", Organized by EEE Club 12

Prerequisites to work with Microcontroller

Basic Electronics

Digital Electronics

Programming

Microprocessor

Workshop on "Microcontroller Based Project Development", Organized by EEE Club 13

Steps of Microcontroller Based Project Development

a) Generation of Idea.

b) Think about the problem and point the objectives of the project.

c) Methodology (Theory Related to project)

d) Hardware Selection (Necessary Components).

e) Study about components.

f) Circuit Diagram

g) Algorithm

h) Program

i) Circuit Connection

j) Desired Outcome.

Name of Some Microcontroller Manufacturer

ATMEL (AVR microcontroller)

Microchip (PIC microcontroller)

Texas Instruments (TI)

Freescale

Philips

Motorola ARDUINO

Workshop on "Microcontroller Based Project Development", Organized by EEE

Club 14

Crystal Oscillator Program Loader Microcontroller Linear Voltage Regulator

Advantages of Arduino: Reduces hardware complexity

Workshop on "Microcontroller Based Project Development", Organized by EEE

Club 15

Advantages of Arduino: Programming Easy

• Programming in C

• Lot of functions in the library.

• No need to learn internal

architecture of microcontroller.

Workshop on "Microcontroller Based Project Development", Organized by EEE Club 16

Arduino UNO Digital I/O Pins

Serial

Tx-Rx Pins

Vcc and GND Pins

Workshop on "Microcontroller Based Project Development", Organized by EEE Club 17

Digital I/O Pins

Most of the important pins of microcontroller are digital input-output pins.

These pins are used to connect INPUT Device (i.e. Push Button, keypad, digital sensors

etc) and OUTPUT Device (i.e. LED, Display, Relay, Motor etc.) with microcontroller.

These pins can act as INPUT or

OUTPUT.

Digital Output pin means microcontroller

can make this pin HIGH or LOW state

(Write Operation).

Digital Input pin means microcontroller

can read HIGH or LOW state from other

devices (Read Operation).

Workshop on "Microcontroller Based Project Development", Organized by EEE Club 18

Configuring Digital I/O Pins

digitalWrite(pin number, HIGH/LOW)

digitalWrite(13,HIGH)

digitalWrite(13,LOW)

pinMode(pin Number, OUTPUT)

An LED is connected with pin 13.

The pin should be an OUTPUT pin.

We can configure a pin as OUTPUT by

“pinMode” function.

pinMode(13, OUTPUT)

Configuring as OUTPUT

Making a Pin HIGH or LOW

Microcontroller can make a digital pin HIGH or LOW by

digitalWrite function.

Workshop on "Microcontroller Based Project Development", Organized by EEE Club 19

Program Structure in ARDUINO

Verify Program

Load Program

Processor run the instructions

written here only once after

loading program or reset .

Serial monitor

Processor run the instructions written here

repeatedly after loading program or reset .

i.e. void loop() function creates an infinite

loop.

Workshop on "Microcontroller Based Project Development", Organized by EEE Club 20

void setup()

{

pinMode(13,OUTPUT);

}

void loop()

{

digitalWrite(13,HIGH);

delay(300);

digitalWrite(13,LOW);

delay(300);

}

LED Blinking

Note: To insert a time delay in the program use following function-

delay(time_in_ms);

Workshop on "Microcontroller Based Project Development", Organized by EEE Club 21

Workshop on "Microcontroller Based Project Development", Organized by EEE Club 22

Project-1: Home Appliance Control by TV Remote

All on/ All off

Required Components

TV Remote

Microcontroller

IR Receiver

Workshop on "Microcontroller Based Project Development", Organized by EEE Club 23

Relay

Arduino Foundation Course, Lecture-11, By-Mohammaed Abdul Kader, B.Sc in EEE, CUET 24

Basics of IR Remote (Transmitter and Receiver Circuit)

Workshop on "Microcontroller Based Project Development", Organized by EEE Club 25

948321248 = 11 1000 1000 0110 0011 1011 1110 0000= 3886 3BE0

Decimal Binary Hexadecimal

Code Transmitted from TV Remote

Workshop on "Microcontroller Based Project Development", Organized by EEE Club 26

RELAY

A relay is an electromagnetic switch operated by a

relatively small electric current that can turn on or off a

much larger electric current. The heart of a relay is an

electromagnet (a coil of wire that becomes a temporary

magnet when electricity flows through it).

Arduino Foundation Course, Lecture-11, By-Mohammaed Abdul Kader, B.Sc in EEE, CUET 27

Receiving

IRrecv irrecv(receivePin): Create the receiver object, using a name of your choice.

irrecv.enableIRIn() :Begin the receiving process. This will enable the timer interrupt which

consumes a small amount of CPU every 50 µs.

irrecv.decode(&results): Attempt to receive a IR code. Returns true if a code was received, or

false if nothing received yet. When a code is received, information is stored into "results".

results.value: The actual IR code (0 if type is UNKNOWN)

irrecv.resume(): After receiving, this must be called to reset the receiver and prepare it to

receive another code.

Functions Related to IR Remote

Workshop on "Microcontroller Based Project Development", Organized by EEE Club 28

Circuit Diagram

Workshop on "Microcontroller Based Project Development", Organized by EEE Club 29

#include <IRremote.h>

int RECV_PIN = 8;

const int LightPin=13;

const int FanPin=12;

const int DLightPin=11;

IRrecv irrecv(RECV_PIN);

decode_results results;

void setup()

{

pinMode(LightPin, OUTPUT);

pinMode(FanPin,OUTPUT);

pinMode(DLightPin, OUTPUT);

Serial.begin(9600);

irrecv.enableIRIn();

}

boolean LIGHT = 0;

boolean FAN=0;

boolean DLIGHT=0;

boolean all=0;

void loop() {

if (irrecv.decode(&results)) {

if (results.value==0x38863BE0) {

LIGHT = !LIGHT;

digitalWrite(LightPin,LIGHT);

}

else if(results.value==0x38863BD0)

{

FAN=!FAN;

digitalWrite(FanPin,FAN); }

else if(results.value==0x38863BF0)

{

DLIGHT=!DLIGHT;

digitalWrite(DLightPin,DLIGHT); }

else if(results.value==0x38863BD2)

{

all=!all;

digitalWrite(LightPin,all);

digitalWrite(FanPin,all);

digitalWrite(DLightPin,all); }

irrecv.resume();

}}

Program

Workshop on "Microcontroller Based Project Development", Organized by EEE Club 30

Project-2: Home Appliance Control by Smart Phone

Workshop on "Microcontroller Based Project Development", Organized by EEE Club 31

Bluetooth Module

B

A

C D

E

F G

Workshop on "Microcontroller Based Project Development", Organized by EEE Club 32

char i;

boolean a=0,b=0,c=0;

void setup() {

Serial.begin(9600);

pinMode(13,OUTPUT);

pinMode(12,OUTPUT);

pinMode(11,OUTPUT);

}

void loop() {

if(Serial.available()>0)

i=Serial.read();

Serial.println(i);

delay(10);

if(i=='A' )

{

a=!a;

digitalWrite(13,a);

i=0;

}

if(i=='B')

{

b=!b;

digitalWrite(12,b);

i=0; }

if(i=='C')

{

c=!c;

digitalWrite(11,c);

i=0; }

if(i=='D')

{

digitalWrite(13,1);

digitalWrite(12,1);

}

if(i=='E') {

digitalWrite(11,0);

digitalWrite(12,0);

digitalWrite(13,0);

}}

Program of Project-2

top related