Download presentation
Presentation is loading. Please wait.
1
Microcontroller basics
Embedded systems for mortals
2
Lesson 1 Working with Arduino IDE Basic electric components
Your first program Digital input and output
3
Arduino IDE Download from: http://arduino.cc/en/Main/Software
Version or newer
4
About Arduino Uno 14 Digital I/O pins (6 PWM) Reset button USB port
12 V input Get its name Uno, meaning one in Italian, because it was first released at the same time as Arduino IDE version 1.0 Pin 13 is also assigned to the intregrated LED GND is ground, 5 Volt is and 5 volt output 6 Analog Input pins 3.3 V and 5 V outputs
5
Setting up Arduino IDE Remeber to all check that the port is correct! (COM4 for example)
6
Structure of an Arduino code
1. Define Variables Before going to the setup function constant variables should be defined int pin = 1; 2. Setting up functions void setup() {} Setup function is run once, when the microcontroller boots up or resets. After setup function the processor moves to run code inside the loop function. Code inside loop function will be run over and over until the microcontroller is shut down. void loop() {} 3. Eternal loop It’s required to have both setup() and loop() functions in the code
7
Arduino C – Basic functions
pinMode(var1, var2) pinMode functions sets the mode of given pin. Var1 is the number of the pin and var2 is the mode (INPUT, INPUT_PULLUP, OUTPUT) digitalWrite(var1, var2) digitalWrite changes the status of the pin. Var1 is the number of the pin and var2 is the status (LOW, HIGH). IMPORTANT TO NOTICE: Depending whether the pin is set as an OUTPUT or INPUT the actual effect of digitalWrite() is different INPUT_PULLUP uses an internal pullup resistor: Unlike pinMode(INPUT), there is no pull-down resistor necessary. An internal 20K-ohm resistor is pulled to 5V. This configuration causes the input to read HIGH when the switch is open, and LOW when it is closed. Explain about the need of a pull-up or pull-down resistor
8
Writing your first program
Basic blinking LED int ledPin = 13; //Variable to store the pin number void setup() { pinMode(ledPin, OUTPUT); //set ledPin as output } void loop() digitalWrite(ledPin, HIGH); //LED ON delay(1000); //Wait 1000ms (=0,1s) digitalWrite(ledPin, LOW); //LED OFF delay(1000); //Wait 1000ms (=1s)
9
Uploading the program Click Verify The program is checked Click Upload
The program is uploaded to the Arduino mCu board 2. 1.
10
Breadboard Terminals with blue and red lines are called power busses and are connected together horizontally. Terminals in the middle are connected together vertically. The gap in the middle separates the two sides.
11
Basic Components Passive components Active components Resistor LED
Capacitor Transistor Push button Integrated circuit (IC) IC contains a lot of transistors. Inductor
12
Example 2 – Push Button Reading digital input
13
Example 2 - Code Reading digital input (Using push button)
byte ledPin = 13; byte buttonPin = 2; void setup() { pinMode(ledPin, OUTPUT); digitalWrite(ledPin, LOW); //set ledPin off as default pinMode(buttonPin, INPUT); //set buttonPin as input digitalWrite(buttonPin, HIGH); //set the default state of the pin to HIGH (+5V) } void loop() if(digitalRead(buttonPin) == LOW) digitalWrite(ledPin, HIGH); //LED ON else digitalWrite(ledPin, LOW); //LED OFF
14
Microcontrollers typically operate on low voltages (0-5V) →You must be careful when connecting devices Know the electrical limits of the microcontroller: Uno can handle max 5V/40mA per pin Always double check the wiring! If you see smoke it’s already too late!
15
P=U*I M U=R*I To prevent overloading a pin or a component with excessive current you need to use a resistor Example: Using an LED – Calculating the required resistor size Operation voltage for LED: 5V Recommended current 23mA 𝑈=𝑅∗𝐼→𝑅= 𝑈 𝐼 = 5𝑉 0,023𝐴 ≈220Ω Ask the class, wha is calculated?
16
Check resistor power-rating
Check resistor power-rating! These resistors are meant for signal processing (max.25 W)
17
Example 3 – adding a LED Longer pin
18
Analog input Timers Interrupts
In next lesson Analog input Timers Interrupts
Similar presentations
© 2025 SlidePlayer.com. Inc.
All rights reserved.