Fundamentals of Programming Study Notes

FUNDAMENTALS OF PROGRAMMING

OBJECTIVES

  • Define energy: The capacity to do work.

  • Differentiate insulator from conductor.

  • Explain the concept of Ohm’s law.

  • Define circuit.

OBJECTIVES CONTINUED

  • Differentiate series from parallel circuit.

  • Define resistor.

  • Define program.

  • Define syntax.

OBJECTIVES CONTINUED AGAIN

  • Identify the basic programming structures used for Arduino programming.

  • Identify what a variable is, data types, and how it is created.

WHAT IS ENERGY?

  • Energy: The capacity to do work.

ELECTRICAL ENERGY

  • Electrical Energy: Derived from electric potential energy or kinetic energy.

VOLTAGE

  • Voltage (Volts): The energy that causes current by pushing electrons in a circuit in the same direction.

ELECTRICAL CURRENT

  • Electrical Current (Amperes): The total amount of charge passing through a wire.

UNIT OF POWER

  • Watt: A unit of power; defined by the formula W=VimesIW = V imes I, where:

    • W is power in watts,

    • V is voltage in volts,

    • I is current in amperes.

TYPES OF CURRENT

  • Direct Current (DC): Constant voltage that flows in one direction.

  • Alternating Current (AC): Voltage which varies on a regular basis.

RESISTANCE

  • Resistance (Ohms/Ω): A measure of how much a material opposes the flow of current.

    • Conductors: Materials that offer very little resistance.

    • Insulators: Materials that offer high resistance.

OHM'S LAW

  • States that the current passing through a conductor between two points is directly proportional to the voltage across the two points. The formula related to Ohm's Law can be expressed as: V=IimesRV = I imes R, where:

    • V = voltage,

    • I = current,

    • R = resistance.

WHAT IS ARDUINO?

  • Arduino: A microcontroller that acts as a small computational engine, enabling the creation and programming of interactive projects.

PARTS OF AN ARDUINO

  • The specific components that make up an Arduino board such as pins, microcontroller unit, and power source.

WHAT IS A CIRCUIT?

  • A circuit is an enclosed path through which electricity flows. A simple circuit is composed of:

    • A source (battery or power supply),

    • Conductors (wires),

    • A load (device that consumes power).

BREADBOARD

  • A breadboard: Also known as a protoboard, it is a solderless electronic circuit building tool that allows for the construction of circuits without needing soldering.

TYPES OF CIRCUITS

SERIES CIRCUIT

  • In a series circuit, components are connected end to end, creating a single path for current to flow.

PARALLEL CIRCUIT

  • In a parallel circuit, components are connected across each other’s leads, creating multiple paths for current to flow.

WHAT IS A RESISTOR?

  • A resistor is a passive electrical component that reduces current and voltage in a circuit.

HOW TO READ RESISTORS

  • Resistor values can be determined through color codes, which indicate their resistance value, tolerance, and more.

RESISTOR COLOR CODES

  • There are different band formats for identifying resistor values:

    • 4 bands: digit, digit, multiplier, tolerance.

    • 5 bands: digit, digit, digit, multiplier, tolerance.

    • 6 bands: digit, digit, digit, multiplier, tolerance, temperature coefficient.

TOLERANCE BAND

  • Tolerance Band: Refers to the percentage error in a resistor’s resistance, indicating how much the actual resistance can vary from the specified value.

TEMPERATURE COEFFICIENT

  • The Temperature Coefficient is the rate at which resistance varies with temperature. It is calculated using the resistance change from the reference temperature, expressed in units of parts per million per degree Celsius (ppm/C).

TYPES OF RESISTORS

  • Types:

    • Pull-up Resistor: Pulls the signal high (logic 1) when inactive.

    • Pull-down Resistor: Pulls the signal low (logic 0) when inactive.

WHAT IS A PROGRAM?

  • A program is a written coding in a programming language that enables the computer (or in this case, the microcontroller) to perform specific functions and tasks.

TRANSDUCER

  • A transducer is a device that converts energy from one form to another. Types include:

    • Sensors: Devices that receive signals.

    • Actuators: Devices that actuate or physically move something based on commands.

TYPES OF SIGNALS

ANALOG SIGNALS

  • Analog: Can take any number of values or readings (e.g., temperature).

DIGITAL SIGNALS

  • Digital: Represented by 2 values: either High or Low / On or Off.

ARDUINO STRUCTURE

  • void setup(): A function that initializes settings (like pin modes) at the beginning of each program.

    • Example structure:

  void setup() {
      pinMode(ledPin, OUTPUT);
  }
  • void loop(): A core function that Arduino continuously runs, executing commands repeatedly.

    • Example structure:

  void loop() {
      digitalWrite(ledPin, HIGH);
      delay(1000);
      digitalWrite(ledPin, LOW);
      delay(1000);
  }

SYNTAX

  • Syntax: A set of rules that determine whether a group of words forms a valid sentence in programming.

PUNCTUATION IN SYNTAX

  • ; (semicolon): Signifies the end of a command line.

  • {} (curly braces): Group code statements together; proper placement is crucial.

  • () (parentheses): Used for grouping arguments for functions and should follow PEMDAS (Parenthesis, Exponentiation, Multiplication, Division, Addition, Subtraction).

COMMENTS IN CODE

  • Comments:

    • Single line: // comments ignore all code from that point until the end of the line.

    • Multi-line: /* comment */ ignores all characters between the opening /* and closing */.

DATA TYPES

  • Integer (int): Used to store whole numbers (no decimals).

  • Floating point (float): Used to store numbers that include decimals.

  • String: Composed of a group of letters and special characters.

  • Boolean (bool): Holds one of two values: true or false.

  • Character (char): Used to store single character letters.

NAMING A VARIABLE

  • Rules for naming variables:

    • Must start with a letter.

    • May contain letters, numbers, and underscore characters.

    • Should NOT be a reserved word in the Arduino IDE.

    • Should NOT contain white space.

FUNCTIONS IN ARDUINO

  • void setup(): Initializes settings for pins and configurations.

  • void loop(): Contains the code that runs repeatedly during the operation of the program.

  • digitalWrite(): Command to send either 5V or 0V to an output pin, using HIGH or LOW arguments.

  • delay(): Stops the Arduino from executing anything for a specified period; takes time in milliseconds as an argument.