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 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 pin, a pin, and multiple (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 through .
Digital Input/Output Pins: Identified as pins through .
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 . The use ofconstimplies that the value is fixed and will not change during program execution.Example:
int buttonState = 0;identifiesbuttonStateas an integer variable used to store values. Initializing it to means it stores that value at the start and can be updated later.
Initialization: Performed using the
pinMode()function within thevoid 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 ( or ) into the variablebuttonState.
delay(): Pauses the program for a specific amount of time, measured in milliseconds (e.g.,
delay(3000);creates a second pause).
Light Emitting Diode (LED) Hardware Logic
Active High Configuration:
The LED turns on when a "HIGH" state (Logic ) is written to the pin.
The LED turns off when a "LOW" state (Logic ) is written to the pin.
Active Low Configuration:
The LED turns on when a "LOW" state (Logic ) is written to the pin.
The LED turns off when a "HIGH" state (Logic ) is written to the pin.
This setup typically involves connecting the LED to a source and the Arduino digital pin with a resistor.
Practical Application: Pushbutton Controlled LED
Circuit Logic: A pushbutton is connected to pin . When pressed, it provides a Logic signal to the pin. A current-limiting resistor is used in the circuit.
Program Logic:
const int ledPin = 8;andconst int buttonPin = 2;designate the pin locations.int buttonstate = 0;initializes the state variable.In
void setup(),ledPinis set toOUTPUTandbuttonPinis set toINPUT.In
void loop(), the program readsbuttonPin. Ifbuttonstate == 1(button is pressed), the LED at pin flashes on for ( second) and then off for .
Practical Application: Traffic Light Control System
Hardware Setup: Three LEDs (Green, Yellow, Red) are connected to pins , , and . A pushbutton is connected to pin .
Program Logic:
Standard Operation (Else condition): If the button is not pressed (Logic ), only the Green LED remains
HIGHwith adelay(1000).Controlled Sequence (If condition): If the button is pressed (Logic at pin ), a sequence is triggered:
Green LED turns
HIGHfor , thenLOW.Yellow LED turns
HIGHfor , thenLOW.Red LED turns
HIGHfor , thenLOW.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.