Arduino is a popular platform. What is its main purpose?
Think about small computers that control lights, motors, and sensors.
Arduino is mainly used to build electronic projects by programming microcontrollers to interact with sensors and actuators.
Look at this Arduino code snippet. What will it do when run?
void setup() {
pinMode(13, OUTPUT);
}
void loop() {
digitalWrite(13, HIGH);
delay(1000);
digitalWrite(13, LOW);
delay(1000);
}Pin 13 is often connected to an onboard LED on Arduino boards.
This code sets pin 13 as output and turns it on and off every 1000 milliseconds (1 second), blinking the LED.
Find the error in this Arduino code that prevents the LED from blinking.
void setup() {
pinMode(13, OUTPUT);
}
void loop() {
digitalWrite(13, HIGH);
delay(1000);
digitalWrite(13, LOW);
delay(1000);
}Check punctuation carefully in the setup function.
The missing semicolon after pinMode(13, OUTPUT) causes a syntax error, so the code won't compile.
Choose the correct Arduino code to declare a variable that stores analog input from pin A0.
Analog input uses a specific function to read voltage levels.
analogRead(A0) reads the voltage on analog pin A0 and returns a value between 0 and 1023.
Given this Arduino code, how many times does the LED connected to pin 13 blink in 10 seconds?
void setup() {
pinMode(13, OUTPUT);
}
void loop() {
digitalWrite(13, HIGH);
delay(250);
digitalWrite(13, LOW);
delay(250);
}Calculate the total time for one blink cycle (on + off) and divide 10 seconds by that.
Each blink cycle takes 250ms on + 250ms off = 500ms. 10 seconds / 0.5 seconds = 20 cycles. Each cycle is one blink on and off, so LED blinks 20 times.
