PinMode ( )
The pinMode() function assigns a specific PIN as either INPUT or OUTPUT.
The Syntax is:
pinMode (pin, mode)
Pin: It is used to specify the PIN which depends on the project requirements.
Mode: Depending on whether the pin is taking INPUT or OUTPUT, it specifies the pin’s function.
Let’s consider a situation to understand the pinMode. We want to take input from the PIN 13 and then,
Code:
pinMode (13, INPUT);
PinMode in OUTPUT mode
Setting pinMode to OUTPUT is important for some pins. This mode allows the specified PIN to supply sufficient current to another circuit to activate the sensor or light the LED. When set to OUTPUT, this pin goes into a very low impedance state, making the current useful. It is important to note that excessive current or short circuits between pins can damage the Atmel chip. This explains the need for setting the mode to OUTPUT.
PinMode in INPUT mode
When digitalWrite() is used, selecting the INPUT mode for any pin turns off the low state and sets the high state as the ultimate state. The INPUT mode can be employed alongside an external pull-down resistor. For this purpose, pinMode should be set to INPUT_PULLUP. This configuration reverses the behavior of the INPUT mode. In INPUT_PULLUP mode, a sufficient current is provided to light an LED connected to the pin dimly. If the LED emits a dim light, it signifies that this condition is operational.
Given these considerations, it’s advisable to set the pin to OUTPUT mode to ensure proper functionality.
Arduino Coding Basics
In some previous articles, we have seen and understood the concepts of Arduino Boards, Arduino IDEs, and the installation procedure for Arduino software. Arduino IDE (Integrated Development Environment) is an essential which makes the task of uploading code on Arduino boards, an easy task. Instead of writing them at the assembly level, the IDEs make it convenient and the codes are written in high-level languages like C and C++. Let us get introduced to the basics of Arduino Coding.
Make sure that you have an appropriate IDE for coding before starting your journey to Arduino coding. Let us study every character, command, and function that is used in Arduino. Keep your Arduino IDE switched on so that you can apply the concepts you learn from the article.
Table of Content
- What is Arduino?
- Electronic Signals
- Brackets
- Line Comment
- Coding Screen
- Time
- pinMode ( )
- digitalWrite( )
- delay ( )
- Solved Example
- Advantages and Disadvantages of Arduino
- Application of Arduino