Digital Input/Output Pins

June 2, 2017

Introduction

Under the Magic Lid of evive, there are 28 Digital 5V Input and Output (I/O) pins.

Digital I/O stands for Digital Input and Output. Digital Inputs allow a microcontroller to detect logic states, and Digital Outputs allow a microcontroller to output logic states.

Digital Input: A digital input detects if a voltage is above/below a specific threshold. If the voltage is higher than some value, evive will detect the digital input as HIGH/1. If the voltage is lower than some value, evive will detect the digital input as LOW/0.

Digital Output: A digital output allows you to control a voltage with evive. If evive instructs the output to be high, the output will produce a voltage (generally about 5 or 3.3 volts). If evive instructs the output to be LOW, it is connected to the ground and produces no voltage.

Controlling digital pins in Arduino IDE

Using the digital pin as Input

evive digital I/O pins are default assigned as inputs and hence they don’t need to be explicitly declared as input initially in the program. But it is advisable that one should declare each and every pin as input or output for consistency.

Digital Input pins can be configured as pinMode(pin, INPUT), where the pin is the digital pin number you want to initialize. Often it is useful to steer an input pin to a known state if no input is present. This can be done by adding a pull-up resistor (to +5V), or a pulldown resistor (resistor to ground) on the input. A 10K resistor is a good value for a pull-up or pulldown resistor.

If the pin is configured as INPUT_PULLUP during initialization, it inverts the behavior of the INPUT mode, where HIGH means the sensor is OFF and LOW means the sensor is ON. It is because there are 20K pull-up resistors built into the Atmega chip that can be accessed from software.

Using the digital pin as Output

Pins can be configured as OUTPUT with pinMode(pin, OUTPUT), where the pin is the digital pin number you want to initialize as output. These pins are also in a low-impedance state. This means that they can provide a substantial amount of current to other circuits. Atmega pins can source (provide positive current) or sink (provide negative current) up to 40 mA (milliamps) of current to other devices/circuits. This is enough current to brightly light up an LED (don’t forget the series resistor), or run many sensors, for example, but not enough current to run most relays, solenoids, or motors.

Short circuits on digital pins, or attempting to run high current devices from them, can damage or destroy the output transistors in the pin, or damage the entire Atmega chip. Often this will result in a “dead” pin in the microcontroller but the remaining chip will still function adequately. For this reason, it is a good idea to connect OUTPUT pins to other devices with 470Ω or 1kΩ resistors, unless maximum current draw from the pins is required for a particular application.

digitalWrite()

Using digitalWrite() function in Arduino IDE, you can write a digital pin, to a HIGH or LOW value.

If the pin has been configured as an OUTPUT with pinMode(), its voltage will be set to the corresponding value: 5V for HIGH, 0V for LOW.

If the pin is configured as an INPUT, digitalWrite() will enable (HIGH) or disable (LOW) the internal pull-up on the input pin. It is recommended to set the pinMode() to INPUT_PULLUP to enable the internal pull-up resistor.

The analog input pins can also be used as digital pins, referred to as A0, A1, etc.

Example

digitalRead()

Using digitalRead() function in Arduino IDE, you can read the value from a specific digital pin as HIGH or LOW.

Example

Controlling digital pins in PictoBlox (Scratch)

Digital Output

Set digital pin () output as () block is used for digital output on a digital pin. It sets the digital state of specified digital pin either “High” or “Low”.

  1. If the output is High, the pin will be at 5V and
  2. If the output is Low the pin will be at 0V.

set digital pin output as

The pin can be selected from the drop-down menu. This block can be used in Upload Mode as well as in Stage Mode.

Example

Controlling Pin 13 LED using Space key. If the output is High, LED glows, and if the output is Low, LED turns off.

digital write example

Digital Read

Read status of digital pin () block available in evive extension is used for digital read in PictoBlox. It reads the state of the digital pin on evive (“High” or “Low”). If the state of the pin is “High”, it returns True, else False.

read state of digital pin

Available  pins for digital read in evive:

  • 26 digital pins available for the user (2-27)

You can choose these pins from the drop-down menu.

This block can be used in Upload Mode as well as in Stage Mode.

Example

Displaying the state of the tactile switch in Scratch Mode.

read digital state example

Share this Documentation
Share on facebook
Facebook
Share on twitter
Twitter
Share on google
Google+
Share on pinterest
Pinterest
Share on reddit
Reddit
Share on print
Print
Related Tutorials & Projects
Smartphone Controlled Plant Watering 600px

Plant Monitoring System

IntroductionMonitoring plant health is very important for their fast growth. In this busy world, people…
set digital pin output as

set digital pin () output as ()

The block sets the digital state of the specified digital pin to either “High” or “Low”. If the output is High, the pin will be at 5V and if the output is Low the pin will be at 0V.
All articles loaded
No more articles to load
Featured Projects
Arcade-Basketball-Game

DIY Arcade Basketball Game

Introduction“We don’t stop playing because we grow old; we grow old because we stop playing.”…
All articles loaded
No more articles to load

Leave a Reply

Close Menu
×

Cart