2.0 EMBEDDED CONTROLLER Engr. Hj. Mohamad Fauzi bin Zakaria Department of Mechatronics and Robotics Engineering Faculty of Electrical and Electronic Engineering
Course Contents A.Microcontroller Overview B.Arduino Uno C.Software Sketch D.Application 1 – LED Blinking E.Application 2 – LED and Button F.Application 3 – Analog Input G.Application 4 – LCD Keypad H.Demonstration – Line Following Mobile Robot
Learning Outcome At the end of this course the participant will be able to: Recognize the variety of open microcontroller system. Familiar with Arduino Uno microcontroller configuration. Construct an application of Arduino-based microcontroller system.
Microcontroller System What is a microcontroller? It has Processor, ROM, RAM, and other peripheral such as input/output digital, analog to digital convertor (ADC), timer/counter, pulse width modulation (PWM), interrupt, Universal Synchronous Asynchronous Receiver Transmitter (USART), inter-integrated circuit (I2C), serial peripheral interface (SPI). Can be differentiate with processing size: 8, 16 and 32 bits. Processing speed: Hz – needs internal or external clock generator to be executed.
Microcontroller Prototyping Platform Arduino (arduino.cc) Pinguino (pinguino.cc) Maple (leaflabs.com) Sparkcore (spark.io) mbed (mbed.org) Raspberry pi (raspberrypi.org) Beaglebone (beagleboard.org) HARDWARE SOFTWARE follow Arduino Technology
MicrocontrollerAtmel AVR - ATmega328 Operating Voltage5V Input Voltage (recommended) 7-12V Input Voltage (limits)6-20V Digital I/O Pins14 (of which 6 provide PWM output) Analog Input Pins6 DC Current per I/O Pin40 mA DC Current for 3.3V Pin50 mA Flash Memory 32 KB (ATmega328) of which 0.5 KB used by bootloader SRAM2 KB (ATmega328) EEPROM1 KB (ATmega328) Clock Speed16 MHz Length68.6 mm Width53.4 mm Weight25 g Arduino Uno
7
8
Software Sketch A sketch: uses for a program by Arduino community that contains the unit of code would be uploaded to and run on an Arduino board. It relies on C language. Therefore, we have to familiar on how to create Structure Variables Functions or subroutines or Refer to Arduino Cheat Sheet
Application 1 – LED Blinking 1.Problem Definition: Construct a system for LED blinking (ON and OFF) every 1s on D13 pin of Arduino Uno microcontroller 2.Knowledge needed: Sinking or sourcing mode for digital output interface. 3.Identify the suitable components and construct its circuit. 4.Need to use Digital Output and Delay Functions: pinMode(pin,direction) digitalWrite(pin,value) delay(value in ms) using Sequential Programming method
Application 2 – LED and Button 1.Problem Definition: Create a system for LED ON when a button is pressed and LED OFF whenever the button is released by using Arduino Uno microcontroller. 2.Knowledge needed: Sinking or sourcing mode for digital output interface and pull-up or down resistor for digital input interface. 3.Identify the suitable components and construct its circuit. 4.Need to use Digital I/O Functions: pinMode(pin,direction) digitalWrite(pin,value) digitalRead(pin) using Sequential Programming method
Application 3 – Analog Input 1.Problem Definition: Construct a temperature indication system which has LM35 that connected to an analog pin of Arduino Uno microcontroller. When temperature reading over than 30°C, a LED indicator will be ON. 2.Knowledge needed: ADC and digital output interface mode. 3.Identify the suitable components and construct its circuit. 4.Need to use Analog Input and Digital I/O Functions: pinMode(pin,direction) digitalWrite(pin,value) analogRead(pin) using Sequential Programming method
Application 4 – LCD Keypad 1.Problem Definition: Develop an user interface shield which consists of an Alphanumeric LCD and analog keypad for Arduino Uno microcontroller. 2.Knowledge needed: Analog keypad input and LCD interface. 3.Identify the suitable components and construct its circuit. 4.Need to use Analog Input and LCD Functions: #include LiquidCrystal(rs, enable, d4, d5, d6, d7) lcd.begin(cols, rows) lcd.setCursor(col, row) lcd.print(data) analogRead(pin) Further Information For_Arduino_SKU:_DFR0009 using Sequential Programming method
Arrow- bot A Teaching Tool A line following differential wheel mobile robot LabelComponents 15 Voltage Battery Supply 2L293DNE Motor Driver 3Power ON/OFF Switch 4LED Indicator 52 x Motors DC 6Programmer Pin 7Inter-integrated Communication 8ATmega328P with Arduino Uno Bootloader 9Serial Peripheral Interface 10Start Button 11Reset Button TOP VIEW BOTTOM VIEW
System Architecture Arduino Pin Assignment
PCB – using Proteus Ares
Software Algorithm (Procedure) 1.setup() 1.Configure output and input pins 2.Wait for user button activation. During waiting activity, read analog sensor data and send to UART for debugging purpose. 2.loop() 1.Read or update analog sensor data 2.Convert analog sensor data to Boolean data and update LED indicator 3.Control motor based on Boolean data as in the table. MOVEMENTIRLIRMIRR Straight Left110 Heavy Left100 Right011 Heavy Right001 Stop000 using Sequential Programming method
Arduino Sketch = Program Code #define LEDL 7 #define LEDM 4 #define LEDR 8 #define IRL 1 #define IRM 2 #define IRR 3 #define LEDL_ON digitalWrite(LEDL,HIGH) #define LEDM_ON digitalWrite(LEDM,HIGH) #define LEDR_ON digitalWrite(LEDR,HIGH) #define LEDL_OFF digitalWrite(LEDL,LOW) #define LEDM_OFF digitalWrite(LEDM,LOW) #define LEDR_OFF digitalWrite(LEDR,LOW) boolean IRL_STATUS, IRM_STATUS, IRR_STATUS; //status for line detection or not. using Sequential Programming method
void Motor(uint8_t speed1, uint8_t speed2) { speed1=map(speed1,0,100,0,255); speed2=map(speed2,0,100,0,255); //=======================MOTOR1 analogWrite(3,0); //PWM1 analogWrite(5,speed1); //PWM2 //=======================MOTOR2 analogWrite(6,speed2); //PWM3 analogWrite(9,0); //PWM4 } void setup() { pinMode(LEDL,OUTPUT); pinMode(LEDM,OUTPUT); pinMode(LEDR,OUTPUT); pinMode(2,INPUT); Serial.begin(9600); while(digitalRead(2)==HIGH) //Wait for user button and used for debugging { Serial.print(analogRead(IRL)); Serial.print("\t"); Serial.print(analogRead(IRM)); Serial.print("\t"); Serial.println(analogRead(IRR)); } using Sequential Programming method
void loop() { //READ SENSOR======================================== int data_IRL = analogRead(IRL); int data_IRM = analogRead(IRM); int data_IRR = analogRead(IRR); //UPDATE SENSOR STATUS AND LED INDICATOR============= if((data_IRL > 154)&&(data_IRL < 460)) {IRL_STATUS=HIGH; LEDL_ON;} else {IRL_STATUS=LOW; LEDL_OFF;} if((data_IRM > 154)&&(data_IRM < 460)) {IRM_STATUS=HIGH; LEDM_ON;} else {IRM_STATUS=LOW; LEDM_OFF;} if((data_IRR > 154)&&(data_IRR < 460)) {IRR_STATUS=HIGH; LEDR_ON;} else {IRR_STATUS=LOW; LEDR_OFF;} //MOTOR CONTROL====================================== if((IRL_STATUS&&IRM_STATUS&&IRR_STATUS)||(!IRL_STATUS&&IRM_STATUS&&!IRR_STATUS)) Motor(100,70); //STRAIGHT else if(IRL_STATUS&&IRM_STATUS&&!IRR_STATUS) Motor(60,70); //MOVE LEFT else if(IRL_STATUS&&!IRM_STATUS&&!IRR_STATUS) Motor(0,70); //MOVE HEAVY LEFT else if(!IRL_STATUS&&IRM_STATUS&&IRR_STATUS) Motor(100,40); //MOVE RIGHT else if(!IRL_STATUS&&!IRM_STATUS&&IRR_STATUS) Motor(100,0); //MOVE HEAVY RIGHT else if(!IRL_STATUS&&!IRM_STATUS&&!IRR_STATUS) Motor(0,0); //STOP } using Sequential Programming method
Conclusion Hope that you have: Know the variety of open microcontroller system available in the market. Familiar with Arduino Uno microcontroller pin mapping configuration. {Main business} Confident in designing, developing and testing any application of Arduino-based microcontroller system by referring closely in Arduino website. Tips for starting the system design are draw the system architecture, identify the microcontroller pin assignment and draw software algorithm before sketch the program.