Arduino Programming Worksheet
1. What is an Arduino? What are programs called in the Arduino programming environment? What is the
extension for an Arduino program?
Arduino is a microcontroller which allows you to easily control sensors and actuators.
2. What is the difference between “Digital” and “Analog” pins. What purpose do they fulfill on an
Arduino.
Digital pins are used for simple on/off operations, while analog pins are used to read varying values.
3. Why are you required to import libraries in Arduino IDE?
Libraries make programming easier by providing code for common tasks. Instead of writing everything
from scratch, you can just use a library to do things like control hardware or perform calculations.
4. What is the purpose of the push button on the Arduino Uno board?
The push button on the Arduino Uno board is used to reset the board.
5. What are comments, and why are they necessary?
Comments are like notes you write in your code to explain what it does. They help you and others
understand the code better.
6. Give two examples of datatypes that can be used in Arduino programming.
int,float
7. What is the difference between a local variable and a global variable?
A local variable is used only inside its function, while a global variable can be used anywhere in the
program.
8. Answer the following the questions based on the code snippet below:
a) Create a variable called motorSpeed that will store the speed of the dc motors. Rewrite the code
above so that the variable is substituted for the value 150 and the motors are spinning in the
opposite directions.
void loop() {
int motorSpeed = 150;
analogWrite(enA, motorSpeed);
digitalWrite(in1, LOW);
digitalWrite(in2, HIGH);
analogWrite(enB, motorSpeed);
digitalWrite(in3, LOW);
digitalWrite(in4, HIGH);
}
b) Create a second variable motorSpeed2. Using motorSpeed and motorSpeed2, modify the code so
that the motor B spinning at twice the speed of motor A in the same direction.
void loop() {
int motorSpeed = 150;
int motorSpeed2 = motorSpeed * 2;
analogWrite(enA, motorSpeed);
digitalWrite(in1, HIGH);
digitalWrite(in2, LOW);
analogWrite(enB, motorSpeed2);
digitalWrite(in3, HIGH);
digitalWrite(in4, LOW);
}