Читать книгу The Smart Cyber Ecosystem for Sustainable Development - Группа авторов - Страница 22

1.5.1 Arduino

Оглавление

Arduino is low resource consuming and cheaper in cost. Due to these two characteristics, it is popular worldwide for implementing the IoT. As shown in Figure 1.4, Arduino is an open source programmable board with a built-in microcontroller and the software (IDE). So, using this Arduino board, we can have input as analog or digital signals and produce digital signal as an output and there is no need to have a separate programmer to program it like traditional microprocessor 8051 and 8085. To program the Arduino microcontroller board, open source software of Arduino IDE is utilized using C or C++ programming language. IDE can be downloaded from Arduino’s official website [22].

To do programming in the Arduino board, install Arduino IDE. Now switch on the Arduino board by attaching it with USB cable to PC and launch Arduino IDE. Using the TOOLS option of this IDE, set BOARD type and PORT type. Program coded in Arduino is known as “sketch”. So, go to the file menu and click on “Create New Sketch” to write a new program in Arduino. Sketch structure in the Arduino IDE can be divided in two major functions: Setup() and Loop(). Setup() function is just like the main() of C/C++ in which we can declare input/output variables and pinmodes can also be declared over here. As per the name, Loop() function is used for iterating the instruction(s) written under it. Using the “pinMode()” function of the Arduino IDE library, we can have the syntax of this function as given below. The common functions of the Arduino library are as given in Table 1.1.


Figure 1.4 Arduino UNO board [21].

Table 1.1 Arduino function and its description.

Function Function Description
pinMode(pin, Mode) Configure the input/output pin(s) with its pin number in the arduino board. pin = pin number on Arduino board, Mode = INPUT/ OUTPUT
digitalWriter() Write digital pin value (HIGH/LOW)
analogRead() Read from analog input pin
Delay() Provides a delay of specified time in milliseconds

Using the above common function, we can write down a program in Arduino IDE that is used for “Blinking LED”. To perform this practical on an Arduino board, we require several objects/entities as hardware such as an Arduino micro-controller board, USB connector, LED, respective capacity of resistor, bread board, connecting wires, and as a software Arduino IDE as shown in Table 1.2.

Table 1.2 Arduino programming requirement.

Activity Hardware Side Software Side
Prerequisite Arduino micro-controller board, USB connector, LED, respective capacity of Registers, Bread board, Connecting wires Arduino IDE
Process ✓ Using connecting wires, set LED on breadboard and connect it to Arduino Using USB connector, connects Arduino board to PC • Select Board and Port type • Write equivalent Sketch in Arduino IDE Verify sketch and upload it

Sample Arduino “Sketch” for Blinking LED: void Setup( ) { pinMode(12, OUTPUT); // set arduino pin number 12 for digital output } void Loop( ) { DigitalWriter(12,HIGH); // Turn ON the LED Delay(500); // wait for 500 millisecond = 0.5 second DigitalWriter(12,LOW); //Turn OFF the LED Delay(500); // wait for 500 millisecond = 0.5 second }

The Smart Cyber Ecosystem for Sustainable Development

Подняться наверх