Organized by: EEE Club 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
What is Micro-Computer (Computer)? Micro-computer is a system which consist at least the following components Microprocessor Memory Input Port Output Port 2
Micro-computer in a single chip. A microcontroller may consist of following functional units: Central Processing Unit Memory Unit System Bus Input/Output Unit Serial Communication Timer Unit. Watchdog Analog to Digital Converter Oscillator What is Microcontroller? 3
Central Processing Unit (CPU)- Microprocessor It takes binary data from memory or input device and provides output processing the data as per user instruction. (RAM) Input ROM (instruction) [ (instruction) ] Output 4
System Bus Address Bus Microprocessor Data Bus MWTC MRDC IOWC IORC Read Only Memory ROM Read/Write Memory RAM Keyboard Printer 5
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. 6
Input/output ports (I/O Ports) 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. 7
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. 8
Serial communication The most commonly used serial communication systems are: I 2 C (Inter Integrated Circuit) SPI (Serial Peripheral Interface Bus) UART (Universal Asynchronous Receiver/Transmitter) 9
Watchdog Timer 10
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). 11
Prerequisites to work with Microcontroller Basic Electronics Digital Electronics Programming Microprocessor 12
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. 13
Name of Some Microcontroller Manufacturer ATMEL (AVR microcontroller) Microchip (PIC microcontroller) Texas Instruments (TI) Freescale Philips Motorola ARDUINO 14 Workshop on "Microcontroller Based Project Development", Organized by EEE Club
Advantages of Arduino: Reduces hardware complexity Crystal Oscillator Program Loader Microcontroller Linear Voltage Regulator 15 Workshop on "Microcontroller Based Project Development", Organized by EEE Club
Advantages of Arduino: Programming Easy Programming in C Lot of functions in the library. No need to learn internal architecture of microcontroller. 16
Arduino UNO Digital I/O Pins Serial Tx-Rx Pins 17 Vcc and GND Pins
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). 18
Configuring Digital I/O Pins Configuring as 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(pin Number, OUTPUT) pinmode(13, OUTPUT) Making a Pin HIGH or LOW Microcontroller can make a digital pin HIGH or LOW by digitalwrite function. digitalwrite(pin number, HIGH/LOW) digitalwrite(13,high) digitalwrite(13,low) 19
Program Structure in ARDUINO Verify Program Load Program Serial monitor Processor run the instructions written here only once after loading program or reset. Processor run the instructions written here repeatedly after loading program or reset. i.e. void loop() function creates an infinite loop. 20
LED Blinking void setup() { pinmode(13,output); } void loop() { digitalwrite(13,high); delay(300); digitalwrite(13,low); delay(300); } Note: To insert a time delay in the program use following functiondelay(time_in_ms); 21
Project-1: Home Appliance Control by TV Remote All on/ All off 22
Required Components TV Remote Microcontroller IR Receiver Relay 23
Basics of IR Remote (Transmitter and Receiver Circuit) 24 Arduino Foundation Course, Lecture-11, By-Mohammaed Abdul Kader, B.Sc in EEE, CUET
Code Transmitted from TV Remote 25 Decimal Binary Hexadecimal 948321248 = 11 1000 1000 0110 0011 1011 1110 0000= 3886 3BE0
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). 26
Functions Related to IR Remote 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. 27 Arduino Foundation Course, Lecture-11, By-Mohammaed Abdul Kader, B.Sc in EEE, CUET
Circuit Diagram 28
Program #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; 29 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(); }}
Project-2: Home Appliance Control by Smart Phone 30
Bluetooth Module F A G D E C B 31
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; } Program of Project-2 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); }} 32