Arduino Microcontroller and Intelligent Building Systems

Overview of Arduino Uno

  • Arduino Uno is an open-source electronics board platform.

  • It utilizes a physical programmable electronics circuit board built around an Atmel AVR microcontroller.

  • The platform uses an Integrated Development Environment (IDE), which is the software used for writing and uploading programming codes to the electronics circuit board.

Key Advantages of the Arduino Uno Platform

  • Inexpensive: The platform is relatively low-cost compared to other available microcontroller platforms.

  • Cross-platform: The software is capable of running on various operating systems, including Windows, Macintosh OSX, and Linux.

  • Ease of Use: It is designed to be simple and easy to use for beginners while remaining flexible enough for advanced users.

  • Open-source and Extensible Software: The software is open-source, and libraries using C++C++ programming codes are readily available for expansion.

  • Open-source and Extensible Hardware: The hardware design is open-source, allowing users to add additional modules seamlessly.

Hardware Components and Pin Configurations

  • USB Jack: Used to establish a connection between the Arduino board and a computer using a USB cable for power and data transfer.

  • Power Jack: Specifically for powering the board directly from an external power supply unit.

  • Reset Pin and Reset Button: Both are used to restart the loaded program from the very beginning.

  • Voltage Pins: Includes a 3.3V3.3V pin, a 5V5V pin, and multiple GNDGND (Ground) pins.

  • Vin: This pin is used to power the Arduino board using an external power source.

  • In-Circuit Serial Programming (ICSP): Header used for programming the Arduino directly.

  • Analog Input Pins: Identified as pins A0A0 through A5A5.

  • Digital Input/Output Pins: Identified as pins D0D0 through D13D13.

  • Communication Pins:

    • D1 (TX): Transmit signals used for serial communication.

    • D0 (RX): Receive signals used for serial communication.

  • AREF: The Analog Reference pin, used to set an external reference voltage.

Arduino Integrated Development Environment (IDE) Structure

  • Header Section: This area is reserved for including external libraries and for the declaration of variables to be used throughout the program.

  • Setup Block (void setup()): This section hosts configuration code that runs exactly once when the program starts. It is typically used for defining pin modes.

  • Main Loop Block (void loop()): This section contains the main code of the program. The instructions within this block run repeatedly in a continuous loop.

  • User-defined Functions: These are specific tasks defined by the user that are usually called within the void loop() block to perform modular operations.

Programming Variable Declaration and Initialization

  • Component Declaration: Every component connected to the Arduino must be declared before use.

    • Example: const int buttonPin = 2; indicates that a pushbutton is connected to digital pin D2D2. The use of const implies that the value is fixed and will not change during program execution.

    • Example: int buttonState = 0; identifies buttonState as an integer variable used to store values. Initializing it to 00 means it stores that value at the start and can be updated later.

  • Initialization: Performed using the pinMode() function within the void setup() block.

    • pinMode(ledPin, OUTPUT); sets a specified LED pin as an output device.

    • pinMode(buttonPin, INPUT); sets a specified pushbutton pin as an input device.

Fundamental Arduino Functions

  • digitalWrite(): This function writes a specific state to an output device.

    • digitalWrite(ledPin, HIGH); provides power to the pin to turn an LED on.

    • digitalWrite(ledPin, LOW); cuts power to the pin to turn an LED off.

  • digitalRead(): This function reads the electrical state of an input device.

    • buttonState = digitalRead(buttonPin); reads the status of the pushbutton and saves that state (11 or 00) into the variable buttonState.

  • delay(): Pauses the program for a specific amount of time, measured in milliseconds (e.g., delay(3000); creates a 33 second pause).

Light Emitting Diode (LED) Hardware Logic

  • Active High Configuration:

    • The LED turns on when a "HIGH" state (Logic 11) is written to the pin.

    • The LED turns off when a "LOW" state (Logic 00) is written to the pin.

  • Active Low Configuration:

    • The LED turns on when a "LOW" state (Logic 00) is written to the pin.

    • The LED turns off when a "HIGH" state (Logic 11) is written to the pin.

    • This setup typically involves connecting the LED to a 5V5V source and the Arduino digital pin with a 330 Ω330\,\Omega resistor.

Practical Application: Pushbutton Controlled LED

  • Circuit Logic: A pushbutton is connected to pin D2D2. When pressed, it provides a Logic 11 signal to the pin. A current-limiting resistor is used in the circuit.

  • Program Logic:

    • const int ledPin = 8; and const int buttonPin = 2; designate the pin locations.

    • int buttonstate = 0; initializes the state variable.

    • In void setup(), ledPin is set to OUTPUT and buttonPin is set to INPUT.

    • In void loop(), the program reads buttonPin. If buttonstate == 1 (button is pressed), the LED at pin 88 flashes on for 1000 ms1000\,ms (11 second) and then off for 1000 ms1000\,ms.

Practical Application: Traffic Light Control System

  • Hardware Setup: Three LEDs (Green, Yellow, Red) are connected to pins D6D6, D7D7, and D8D8. A pushbutton is connected to pin D2D2.

  • Program Logic:

    • Standard Operation (Else condition): If the button is not pressed (Logic 00), only the Green LED remains HIGH with a delay(1000).

    • Controlled Sequence (If condition): If the button is pressed (Logic 11 at pin 22), a sequence is triggered:

      1. Green LED turns HIGH for 4000 ms4000\,ms, then LOW.

      2. Yellow LED turns HIGH for 5000 ms5000\,ms, then LOW.

      3. Red LED turns HIGH for 6000 ms6000\,ms, then LOW.

      4. A final delay(3000) occurs before the loop resets.

Learning Objectives

  • Achievement of the following skills is expected by the end of the lesson:

    • Identification of all physical parts of the Arduino microcontroller.

    • Identification and comprehension of the functionality of different sections in Arduino programming code.

    • Ability to design and program a system using a Light Dependent Resistor (LDR) to control LEDs.