Microcontroller lab viva questions, with answers you can test
Beginner
Or see every lesson.
- 261parts on the bench
- 31boards running now
- 1.00xreal time, on every board
These are questions that often come up in a microcontroller or Arduino lab viva, with short answers. They are grouped by the experiment they usually follow, from the first blink to serial and I2C.
Reading an answer is not the same as knowing it. So each group points to a circuit you can run on this site. The one above is a dimmer on an Arduino Uno. Turn the knob, and the LED on pin 9 gets brighter or dimmer. Two viva favorites, analogRead and analogWrite, are both in it.
The numbers here are for the Arduino Uno and its ATmega328P chip, the board most first labs use. If your lab uses another board, check its numbers on its own board page.
The board and the chip
What is the difference between a microcontroller and a microprocessor? A microcontroller has the processor, the memory and the input and output pins on one chip. A microprocessor needs other chips for memory and I/O. The ATmega328P on an Uno is a microcontroller.
What are the main numbers of the Uno? It runs at 16 MHz. It has 32 KB of flash for the program, 2 KB of SRAM for variables and 1 KB of EEPROM. It has 14 digital pins, six of them with PWM, and six analog inputs.
What is the difference between flash, SRAM and EEPROM? Flash holds the program and keeps it with the power off. SRAM holds variables while the program runs and loses them at power off. EEPROM keeps small values, like a setting, across power off.
Why does every sketch have setup() and loop()? setup() runs once after a reset. Then loop() runs again and again, for as long as the board has power.
Digital output: blink and LEDs
What does pinMode() do? It sets a pin as an input or an output. A pin you write to with digitalWrite() must be an output first.
Why is there a resistor in series with the LED? To limit the current. With 5 V, a red LED that drops about 2 V and a 220 ohm resistor, the current is 3 V divided by 220 ohms, about 14 mA.
What happens without the resistor? On a real board, too much current flows. It can damage the LED or the pin. In Mokxi no part burns out, so the simulator will not show you this one. Give the bench answer.
Try it: the blink tutorial runs the circuit. Change the delay, press Run again, and watch the rate change.
Digital input: buttons
What is a floating input? An input pin with nothing connected can read HIGH or LOW at random on a real board. A pull-up or pull-down resistor gives it a fixed level.
What does INPUT_PULLUP do? It turns on a resistor inside the chip, from the pin to 5 V. The pin reads HIGH while the button is open, and LOW while the button connects it to ground.
What is switch bounce? A mechanical contact makes and breaks several times in the first few milliseconds. One press can be read as several presses. Debouncing waits for the input to settle, in code or with an RC filter.
Try it: the pushbutton in Mokxi bounces for a few milliseconds, like a real one. The button debounce tutorial shows the problem and the fix.
Analog input and PWM output
What is the ADC resolution of the Uno? Ten bits. analogRead() returns 0 to 1023. With a 5 V reference, one step is 5 V divided by 1024, about 4.9 mV.
Does analogWrite() make an analog voltage? No. It makes PWM: a square wave whose duty cycle is set by a value from 0 to 255. An LED looks dimmer because it is on for less of each cycle.
Which pins give PWM on the Uno? Pins 3, 5, 6, 9, 10 and 11, marked with a ~ on the board. The frequency is about 490 Hz on most of them, and about 980 Hz on pins 5 and 6.
How does the dimmer turn 0 to 1023 into 0 to 255? It shifts the reading right by two bits, which is the same as dividing by four. The map() function is the other common answer.
Try it: run the dimmer above and open the serial monitor. It prints the knob position and the PWM value each time you turn it.
Timing and interrupts
What is the difference between delay() and millis()? delay() stops the program for a time. millis() returns the milliseconds since the board started, so the program can check the time and keep doing other work.
What is an interrupt? A signal that pauses the main program, runs a short function called an ISR, and then returns. On the Uno, pins 2 and 3 have external interrupts.
What is the difference between an interrupt and polling? Polling reads a pin over and over in loop(). An interrupt reacts to the change when it happens, so a short press is not missed while the program is busy.
Try it: the interrupts vs polling page runs both ways side by side.
Serial, I2C and SPI
What is a baud rate? The number of bits sent per second on a serial line. At 9600 baud, with 8 data bits, no parity and one stop bit, each character takes 10 bits, so about 960 characters go each second. Both ends must use the same rate.
How many wires do UART, I2C and SPI use? UART uses TX and RX, plus ground. I2C uses two, SDA and SCL, shared by many devices, and each device has an address. SPI uses MOSI, MISO and SCK, plus one chip select line for each device.
Where are I2C and SPI on the Uno? I2C is on A4 (SDA) and A5 (SCL). SPI is on pins 11 (MOSI), 12 (MISO) and 13 (SCK).
Try it: the UART, I2C and SPI explainers each run a circuit. The logic analyzer in Mokxi can decode the bytes on the wires, so you can see an address or a character go by.
How to prepare in one evening
Go through your lab record one experiment at a time. For each one, open the matching circuit, run it, and change one thing. Then explain out loud what changed and why.
Examiners often ask "what if" questions. What if the resistor were 1 k? What if the button had no pull-up? What if you used delay() here? The simulator answers these in seconds, and nothing breaks.
Practice with a friend. One person asks, and the other answers with no notes. Then swap. Share a project with a link, and you can both look at the same circuit.
Questions
Are these the exact questions my examiner will ask?
Nobody can promise that. These are common topics in a first microcontroller lab. Your own lab record and syllabus are the best guide to what your examiner will ask.
Do I need an account to run the circuits?
No. The circuits run in your browser with no account. A free account lets you save any number of public projects, and up to five private or link-only ones.
My lab uses the 8051. Does this still help?
The ideas carry over: ports, timers, interrupts and serial. Mokxi does not simulate the 8051, so the circuits here run on the Arduino Uno and other boards.
Can I use it on my phone?
Yes. The editor works on a phone, with a layout made for a small screen. A laptop is easier when you write code.
Keep going
Build this for real
Open the editor, change a value and watch the number move with it. Nothing to install, and no account needed.