{"id":132427,"date":"2023-07-27T16:09:11","date_gmt":"2023-07-27T16:09:11","guid":{"rendered":"https:\/\/randomnerdtutorials.com\/?p=132427"},"modified":"2023-09-20T14:15:33","modified_gmt":"2023-09-20T14:15:33","slug":"raspberry-pi-pico-outputs-inputs-arduino","status":"publish","type":"post","link":"https:\/\/randomnerdtutorials.com\/raspberry-pi-pico-outputs-inputs-arduino\/","title":{"rendered":"Raspberry Pi Pico: Control Digital Outputs and Read Digital Inputs (Arduino IDE)"},"content":{"rendered":"\n<p>Learn how to set the Raspberry Pi Pico GPIOs as digital inputs and digital outputs using Arduino IDE. You&#8217;ll learn how to read digital inputs like a button switch and how to control a digital output like an LED.<\/p>\n\n\n<div class=\"wp-block-image\">\n<figure class=\"aligncenter size-full\"><img data-recalc-dims=\"1\" fetchpriority=\"high\" decoding=\"async\" width=\"1200\" height=\"675\" src=\"https:\/\/i0.wp.com\/randomnerdtutorials.com\/wp-content\/uploads\/2023\/06\/Raspberry-Pi-Pico-Digital-Inputs-Outputs-Arduino-IDE.jpg?resize=1200%2C675&#038;quality=100&#038;strip=all&#038;ssl=1\" alt=\"Raspberry Pi Pico Control Digital Outputs and Read Digital Inputs Arduino IDE\" class=\"wp-image-132445\" srcset=\"https:\/\/i0.wp.com\/randomnerdtutorials.com\/wp-content\/uploads\/2023\/06\/Raspberry-Pi-Pico-Digital-Inputs-Outputs-Arduino-IDE.jpg?w=1280&amp;quality=100&amp;strip=all&amp;ssl=1 1280w, https:\/\/i0.wp.com\/randomnerdtutorials.com\/wp-content\/uploads\/2023\/06\/Raspberry-Pi-Pico-Digital-Inputs-Outputs-Arduino-IDE.jpg?resize=300%2C169&amp;quality=100&amp;strip=all&amp;ssl=1 300w, https:\/\/i0.wp.com\/randomnerdtutorials.com\/wp-content\/uploads\/2023\/06\/Raspberry-Pi-Pico-Digital-Inputs-Outputs-Arduino-IDE.jpg?resize=1024%2C576&amp;quality=100&amp;strip=all&amp;ssl=1 1024w, https:\/\/i0.wp.com\/randomnerdtutorials.com\/wp-content\/uploads\/2023\/06\/Raspberry-Pi-Pico-Digital-Inputs-Outputs-Arduino-IDE.jpg?resize=768%2C432&amp;quality=100&amp;strip=all&amp;ssl=1 768w\" sizes=\"(max-width: 1200px) 100vw, 1200px\" \/><\/figure><\/div>\n\n\n<p class=\"rntbox rntclblue\"><strong>New to the Raspberry Pi Pico?<\/strong> Read the following guide: <a href=\"https:\/\/randomnerdtutorials.com\/getting-started-raspberry-pi-pico-w\/\">Getting Started with Raspberry Pi Pico (and Pico W)<\/a>. <\/p>\n\n\n\n<p>If you&#8217;re used to programming the Arduino, ESP32 and\/or the ESP8266 using Arduino IDE, you&#8217;ll find that it&#8217;s pretty similar to programming the Raspberry Pi Pico.<\/p>\n\n\n\n<h2 class=\"wp-block-heading\">Prerequisites<\/h2>\n\n\n\n<p>You need to install the Raspberry Pi Pico boards on Arduino IDE and you must know how to upload code to the board. Check out the following tutorial first if you haven&#8217;t already:<\/p>\n\n\n\n<ul class=\"wp-block-list\">\n<li><a href=\"https:\/\/randomnerdtutorials.com\/programming-raspberry-pi-pico-w-arduino-ide\/\" title=\"\">Programming Raspberry Pi Pico with Arduino IDE<\/a><\/li>\n<\/ul>\n\n\n\n<h2 class=\"wp-block-heading\">Project Overview<\/h2>\n\n\n\n<p>To show you how to use digital inputs and digital outputs, we&#8217;ll build a simple project example with a pushbutton and an LED. We&#8217;ll read the state of the pushbutton and light up the LED accordingly as illustrated in the following figure.<\/p>\n\n\n<div class=\"wp-block-image\">\n<figure class=\"aligncenter size-full\"><img data-recalc-dims=\"1\" decoding=\"async\" width=\"825\" height=\"411\" src=\"https:\/\/i0.wp.com\/randomnerdtutorials.com\/wp-content\/uploads\/2019\/04\/led_pushbutton.png?resize=825%2C411&#038;quality=100&#038;strip=all&#038;ssl=1\" alt=\"Control Digital Outputs and Read Digital Inputs pushbutton pressed led on off\" class=\"wp-image-84228\" srcset=\"https:\/\/i0.wp.com\/randomnerdtutorials.com\/wp-content\/uploads\/2019\/04\/led_pushbutton.png?w=825&amp;quality=100&amp;strip=all&amp;ssl=1 825w, https:\/\/i0.wp.com\/randomnerdtutorials.com\/wp-content\/uploads\/2019\/04\/led_pushbutton.png?resize=300%2C149&amp;quality=100&amp;strip=all&amp;ssl=1 300w, https:\/\/i0.wp.com\/randomnerdtutorials.com\/wp-content\/uploads\/2019\/04\/led_pushbutton.png?resize=768%2C383&amp;quality=100&amp;strip=all&amp;ssl=1 768w\" sizes=\"(max-width: 825px) 100vw, 825px\" \/><\/figure><\/div>\n\n\n<h2 class=\"wp-block-heading\">Raspberry Pi Pico GPIOs<\/h2>\n\n\n\n<p>The Raspberry Pi Pico comes with 40 pins, 26 of which are programmable GPIOs that you can use to connect peripherals.<\/p>\n\n\n\n<p>You can use the following pinouts as a reference to identify and locate each GPIO on your board. The pinout is slightly different for the Pico and Pico W.<\/p>\n\n\n\n<p>The following picture shows the Raspberry Pi Pico pinout (which functions are supported by each pin).<\/p>\n\n\n<div class=\"wp-block-image\">\n<figure class=\"aligncenter size-full\"><a href=\"https:\/\/i0.wp.com\/randomnerdtutorials.com\/wp-content\/uploads\/2023\/05\/Raspberry-Pi-Pico-pinout.png?quality=100&#038;strip=all&#038;ssl=1\"><img data-recalc-dims=\"1\" decoding=\"async\" width=\"842\" height=\"642\" src=\"https:\/\/i0.wp.com\/randomnerdtutorials.com\/wp-content\/uploads\/2023\/05\/Raspberry-Pi-Pico-pinout.png?resize=842%2C642&#038;quality=100&#038;strip=all&#038;ssl=1\" alt=\"Raspberry Pi Pico Pinout\" class=\"wp-image-130916\" srcset=\"https:\/\/i0.wp.com\/randomnerdtutorials.com\/wp-content\/uploads\/2023\/05\/Raspberry-Pi-Pico-pinout.png?w=842&amp;quality=100&amp;strip=all&amp;ssl=1 842w, https:\/\/i0.wp.com\/randomnerdtutorials.com\/wp-content\/uploads\/2023\/05\/Raspberry-Pi-Pico-pinout.png?resize=300%2C229&amp;quality=100&amp;strip=all&amp;ssl=1 300w, https:\/\/i0.wp.com\/randomnerdtutorials.com\/wp-content\/uploads\/2023\/05\/Raspberry-Pi-Pico-pinout.png?resize=768%2C586&amp;quality=100&amp;strip=all&amp;ssl=1 768w\" sizes=\"(max-width: 842px) 100vw, 842px\" \/><\/a><figcaption class=\"wp-element-caption\">Image source: <a href=\"https:\/\/raspberrypi.com\" target=\"_blank\" rel=\"noopener\" title=\"\">raspberrypi.com<\/a><\/figcaption><\/figure><\/div>\n\n<div class=\"wp-block-image\">\n<figure class=\"aligncenter size-full\"><a href=\"https:\/\/i0.wp.com\/randomnerdtutorials.com\/wp-content\/uploads\/2023\/05\/Raspberry-Pi-Pico-W-Pinout.png?quality=100&#038;strip=all&#038;ssl=1\"><img data-recalc-dims=\"1\" loading=\"lazy\" decoding=\"async\" width=\"861\" height=\"620\" src=\"https:\/\/i0.wp.com\/randomnerdtutorials.com\/wp-content\/uploads\/2023\/05\/Raspberry-Pi-Pico-W-Pinout.png?resize=861%2C620&#038;quality=100&#038;strip=all&#038;ssl=1\" alt=\"Raspberry Pi Pico W pinout\" class=\"wp-image-130917\" srcset=\"https:\/\/i0.wp.com\/randomnerdtutorials.com\/wp-content\/uploads\/2023\/05\/Raspberry-Pi-Pico-W-Pinout.png?w=861&amp;quality=100&amp;strip=all&amp;ssl=1 861w, https:\/\/i0.wp.com\/randomnerdtutorials.com\/wp-content\/uploads\/2023\/05\/Raspberry-Pi-Pico-W-Pinout.png?resize=300%2C216&amp;quality=100&amp;strip=all&amp;ssl=1 300w, https:\/\/i0.wp.com\/randomnerdtutorials.com\/wp-content\/uploads\/2023\/05\/Raspberry-Pi-Pico-W-Pinout.png?resize=768%2C553&amp;quality=100&amp;strip=all&amp;ssl=1 768w\" sizes=\"(max-width: 861px) 100vw, 861px\" \/><\/a><\/figure><\/div>\n\n\n<p>The pins marked in red are power pins that output 3.3V. The black pins are GND pins. All pins in light green can be used as &#8220;regular&#8221; GPIOs (input and output).<\/p>\n\n\n\n<h2 class=\"wp-block-heading\">Digital Inputs<\/h2>\n\n\n\n<p>To set a GPIO as a digital input or output, you use the <span class=\"rnthl rntliteral\">pinMode()<\/span> function that accepts as arguments the GPIO and its mode.<\/p>\n\n\n\n<pre class=\"wp-block-code language-c\"><code>pinMode(GPIO, MODE);<\/code><\/pre>\n\n\n\n<p>The Raspberry Pi Pico supports three input modes:<\/p>\n\n\n\n<ul class=\"wp-block-list\">\n<li><span class=\"rnthl rntliteral\">INPUT<\/span>: regular input;<\/li>\n\n\n\n<li><span class=\"rnthl rntliteral\">INPUT_PULLUP<\/span>: input with an internal pull-up resistance;<\/li>\n\n\n\n<li><span class=\"rnthl rntliteral\">INPUT_PULLDOWN<\/span>: input with an internal pull-down resistance.<\/li>\n<\/ul>\n\n\n\n<p>For example, to create an input for a button on GPIO 21 (for buttons, it is very practical to use the internal pull-down resistance because you don&#8217;t need to add it to your circuit):<\/p>\n\n\n\n<pre class=\"wp-block-code language-c\"><code>pinMode(21, INPUT_PULLDOWN);<\/code><\/pre>\n\n\n\n<h3 class=\"wp-block-heading\">digitalRead()<\/h3>\n\n\n\n<p>To read a digital input, like a button, you use the&nbsp;<span class=\"rnthl rntliteral\">digitalRead()<\/span>&nbsp;function. This function accepts as an argument the GPIO you are referring to. It&#8217;s as simple as that.<\/p>\n\n\n\n<pre class=\"wp-block-code language-c\"><code>digitalRead(GPIO);<\/code><\/pre>\n\n\n\n<p>This returns HIGH (or True, or 1) or LOW (or False or 0).<\/p>\n\n\n\n<h2 class=\"wp-block-heading\">Digital Outputs<\/h2>\n\n\n\n<p>To set a GPIO as a digital output, use the <span class=\"rnthl rntliteral\">pinMode()<\/span> function as follows:<\/p>\n\n\n\n<pre class=\"wp-block-code language-c\"><code>pinMode(GPIO, OUTPUT);<\/code><\/pre>\n\n\n\n<h3 class=\"wp-block-heading\">digitalWrite()<\/h3>\n\n\n\n<p>To control a digital output you need to use the <span class=\"rnthl rntliteral\">digitalWrite()<\/span> function. This function accepts as arguments, the GPIO you are referring to, and the state, either <span class=\"rnthl rntliteral\">HIGH<\/span> or <span class=\"rnthl rntliteral\">LOW<\/span>.<\/p>\n\n\n\n<pre class=\"wp-block-code language-c\"><code>digitalWrite(GPIO, STATE);<\/code><\/pre>\n\n\n\n<h2 class=\"wp-block-heading\">Schematic<\/h2>\n\n\n\n<p>For this example, we&#8217;ll wire an LED to GPIO 20 and a pushbutton to GPIO 21. You can use any other GPIO pins as long as you modify the code accordingly.<\/p>\n\n\n\n<h3 class=\"wp-block-heading\">Parts Required<\/h3>\n\n\n\n<p>Here\u2019s a list of the parts you need to build the circuit:<\/p>\n\n\n\n<ul class=\"wp-block-list\">\n<li><a href=\"https:\/\/makeradvisor.com\/tools\/raspberry-pi-pico-w\/\" target=\"_blank\" rel=\"noopener\" title=\"\">Raspberry Pi Pico<\/a><\/li>\n\n\n\n<li><a href=\"https:\/\/makeradvisor.com\/tools\/3mm-5mm-leds-kit-storage-box\/\" target=\"_blank\" rel=\"noopener\" title=\"\">5 mm LED<\/a><\/li>\n\n\n\n<li><a href=\"https:\/\/makeradvisor.com\/tools\/resistors-kits\/\" target=\"_blank\" rel=\"noopener\" title=\"\">330 Ohm resistor<\/a><\/li>\n\n\n\n<li><a href=\"https:\/\/makeradvisor.com\/tools\/pushbuttons-kit\/\" target=\"_blank\" rel=\"noopener\" title=\"\">Pushbutton<\/a><\/li>\n\n\n\n<li><a href=\"https:\/\/makeradvisor.com\/tools\/resistors-kits\/\" target=\"_blank\" rel=\"noopener\" title=\"\">10k Ohm resistor<\/a><\/li>\n\n\n\n<li><a rel=\"noreferrer noopener\" href=\"https:\/\/makeradvisor.com\/tools\/mb-102-solderless-breadboard-830-points\/\" target=\"_blank\">Breadboard<\/a><\/li>\n\n\n\n<li><a rel=\"noreferrer noopener\" href=\"https:\/\/makeradvisor.com\/tools\/jumper-wires-kit-120-pieces\/\" target=\"_blank\">Jumper wires<\/a><\/li>\n<\/ul>\n\n\n<p>You can use the preceding links or go directly to <a href=\"https:\/\/makeradvisor.com\/tools\/?utm_source=rnt&utm_medium=post&utm_campaign=post\" target=\"_blank\">MakerAdvisor.com\/tools<\/a> to find all the parts for your projects at the best price!<\/p><p style=\"text-align:center;\"><a href=\"https:\/\/makeradvisor.com\/tools\/?utm_source=rnt&utm_medium=post&utm_campaign=post\" target=\"_blank\"><img data-recalc-dims=\"1\" decoding=\"async\" src=\"https:\/\/i0.wp.com\/randomnerdtutorials.com\/wp-content\/uploads\/2017\/10\/header-200.png?w=1200&#038;quality=100&#038;strip=all&#038;ssl=1\"><\/a><\/p>\n\n\n\n<h3 class=\"wp-block-heading\">Schematic \u2013 Raspberry Pi Pico<\/h3>\n\n\n\n<p>You can use the following diagram as a reference to connect the pushbutton and LED to the Raspberry Pi Pico board.<\/p>\n\n\n\n<ul class=\"wp-block-list\">\n<li>LED \u00bb GPIO 20<\/li>\n\n\n\n<li>Pushbutton \u00bb GPIO 21<\/li>\n<\/ul>\n\n\n<div class=\"wp-block-image\">\n<figure class=\"aligncenter size-full\"><img data-recalc-dims=\"1\" loading=\"lazy\" decoding=\"async\" width=\"606\" height=\"842\" src=\"https:\/\/i0.wp.com\/randomnerdtutorials.com\/wp-content\/uploads\/2023\/06\/Raspberry-pico-pushbutton-led-circuit_diagram.png?resize=606%2C842&#038;quality=100&#038;strip=all&#038;ssl=1\" alt=\"Raspberry Pi Pico Pushbutton LED Circuit Schematic Diagram\" class=\"wp-image-132443\" srcset=\"https:\/\/i0.wp.com\/randomnerdtutorials.com\/wp-content\/uploads\/2023\/06\/Raspberry-pico-pushbutton-led-circuit_diagram.png?w=606&amp;quality=100&amp;strip=all&amp;ssl=1 606w, https:\/\/i0.wp.com\/randomnerdtutorials.com\/wp-content\/uploads\/2023\/06\/Raspberry-pico-pushbutton-led-circuit_diagram.png?resize=216%2C300&amp;quality=100&amp;strip=all&amp;ssl=1 216w\" sizes=\"(max-width: 606px) 100vw, 606px\" \/><\/figure><\/div>\n\n\n<p>The easiest way to assemble the circuit is to use a breadboard. The Raspberry Pi Pico fits perfectly on a regular breadboard.<\/p>\n\n\n<div class=\"wp-block-image\">\n<figure class=\"aligncenter size-full\"><img data-recalc-dims=\"1\" loading=\"lazy\" decoding=\"async\" width=\"750\" height=\"422\" src=\"https:\/\/i0.wp.com\/randomnerdtutorials.com\/wp-content\/uploads\/2023\/06\/Raspberry-Pi-Pico-Pushbutton-LED-circuit.jpg?resize=750%2C422&#038;quality=100&#038;strip=all&#038;ssl=1\" alt=\"Raspberry Pi Pico LED Pushbutton Circuit\" class=\"wp-image-132439\" srcset=\"https:\/\/i0.wp.com\/randomnerdtutorials.com\/wp-content\/uploads\/2023\/06\/Raspberry-Pi-Pico-Pushbutton-LED-circuit.jpg?w=750&amp;quality=100&amp;strip=all&amp;ssl=1 750w, https:\/\/i0.wp.com\/randomnerdtutorials.com\/wp-content\/uploads\/2023\/06\/Raspberry-Pi-Pico-Pushbutton-LED-circuit.jpg?resize=300%2C169&amp;quality=100&amp;strip=all&amp;ssl=1 300w\" sizes=\"(max-width: 750px) 100vw, 750px\" \/><\/figure><\/div>\n\n\n<h2 class=\"wp-block-heading\">Raspberry Pi Pico &#8211; Digital Inputs and Outputs Example Code<\/h2>\n\n\n\n<p>The following code reads the state of the pushbutton and lights up the LED accordingly.<\/p>\n\n\n<pre style=\"max-height: 40em; margin-bottom: 20px;\"><code class=\"language-c\">\/*********\n  Rui Santos\n  Complete project details at https:\/\/RandomNerdTutorials.com\/raspberry-pi-pico-outputs-inputs-arduino\/\n  \n  Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files.\n  The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.\n*********\/\n\n\/\/ set pin numbers\nconst int buttonPin = 21;     \/\/ the number of the pushbutton pin\nconst int ledPin =  20;       \/\/ the number of the LED pin\n\n\/\/ variable for storing the pushbutton status \nint buttonState = 0;\n\nvoid setup() {\n  Serial.begin(115200);  \n  \/\/ initialize the pushbutton pin as an input\n  pinMode(buttonPin, INPUT_PULLDOWN);\n  \/\/ initialize the LED pin as an output\n  pinMode(ledPin, OUTPUT);\n}\n\nvoid loop() {\n  \/\/ read the state of the pushbutton value\n  buttonState = digitalRead(buttonPin);\n  Serial.println(buttonState);\n  \/\/ check if the pushbutton is pressed.\n  \/\/ if it is, the buttonState is HIGH\n  if (buttonState == HIGH) {\n    \/\/ turn LED on\n    digitalWrite(ledPin, HIGH);\n  } else {\n    \/\/ turn LED off\n    digitalWrite(ledPin, LOW);\n  }\n}\n<\/code><\/pre>\n\t<p style=\"text-align:center\"><a class=\"rntwhite\" href=\"https:\/\/github.com\/RuiSantosdotme\/Random-Nerd-Tutorials\/raw\/master\/Projects\/Raspberry-Pi-Pico\/Arduino\/Pushbutton_LED_Inputs_Outputs.ino\" target=\"_blank\">View raw code<\/a><\/p>\n\n\n\n<h3 class=\"wp-block-heading\">How the Code Works<\/h3>\n\n\n\n<p>Let&#8217;s take a quick look at how the code works. Continue reading or skip to the <a href=\"#demonstration\" title=\"\">Demonstration<\/a> section.<\/p>\n\n\n\n<p>In the following two lines, you create variables to assign pins:<\/p>\n\n\n\n<pre class=\"wp-block-code language-c\"><code>const int buttonPin = 21;&nbsp;\nconst int ledPin = 20;<\/code><\/pre>\n\n\n\n<p>The button is connected to GPIO 21, and the LED is connected to GPIO 20.<\/p>\n\n\n\n<p>Next, you create a variable to hold the button state.<\/p>\n\n\n\n<pre class=\"wp-block-code language-c\"><code>int buttonState = 0;<\/code><\/pre>\n\n\n\n<p>In the <span class=\"rnthl rntliteral\">setup()<\/span>, you initialize the button as an <span class=\"rnthl rntliteral\">INPUT_PULLDOWN<\/span>, and the <span class=\"rnthl rntliteral\">LED<\/span> as an <span class=\"rnthl rntliteral\">OUTPUT<\/span>. For that, you use the <span class=\"rnthl rntliteral\">pinMode()<\/span> function that accepts the pin you are referring to, and the mode, as we&#8217;ve seen previously.<\/p>\n\n\n\n<pre class=\"wp-block-code language-c\"><code>pinMode(buttonPin, INPUT_PULLDOWN);\npinMode(ledPin, OUTPUT);<\/code><\/pre>\n\n\n\n<p>In the&nbsp;<span class=\"rnthl rntliteral\">loop()<\/span>&nbsp;is where you put the lines of code that will run indefinitely. That&#8217;s where we&#8217;ll read the button state and set the LED accordingly.<\/p>\n\n\n\n<p>In the next line, you read the button state and save it in the&nbsp;<span class=\"rnthl rntliteral\">buttonState<\/span>&nbsp;variable. As we\u2019ve seen previously, you use the&nbsp;<span class=\"rnthl rntliteral\">digitalRead()<\/span>&nbsp;function.<\/p>\n\n\n\n<pre class=\"wp-block-code language-c\"><code>buttonState = digitalRead(buttonPin);<\/code><\/pre>\n\n\n\n<p>The following&nbsp;if&nbsp;statement checks whether the button state is <span class=\"rnthl rntliteral\">HIGH<\/span>. If it is, it turns the LED on using the&nbsp;<span class=\"rnthl rntliteral\">digitalWrite()<\/span>&nbsp;function that accepts as arguments the&nbsp;<span class=\"rnthl rntliteral\">ledPin<\/span>, and the state, <span class=\"rnthl rntliteral\">HIGH<\/span>.<\/p>\n\n\n\n<pre class=\"wp-block-code language-c\"><code>if (buttonState == HIGH) {\n  digitalWrite(ledPin, HIGH);\n}<\/code><\/pre>\n\n\n\n<p>If the button state is not <span class=\"rnthl rntliteral\">HIGH<\/span>, you set the LED off, by writing <span class=\"rnthl rntliteral\">LOW<\/span> as second argument in the&nbsp;<span class=\"rnthl rntliteral\">digitalWrite()<\/span>&nbsp;function.<\/p>\n\n\n\n<pre class=\"wp-block-code language-c\"><code>else {\n&nbsp; digitalWrite(ledPin, LOW);\n}<\/code><\/pre>\n\n\n\n<h2 class=\"wp-block-heading\">Uploading the Code to the Raspberry Pi Pico<\/h2>\n\n\n\n<p>For you to be able to upload code to the Raspberry Pi Pico, it needs to be in bootloader mode.<\/p>\n\n\n\n<p>If the Raspberry Pi is currently running MicroPython firmware, you need to manually put it into bootloader mode. For that, connect the Raspberry Pi Pico to your computer while holding the BOOTSEL button at the same time.<\/p>\n\n\n<div class=\"wp-block-image\">\n<figure class=\"aligncenter size-full\"><img data-recalc-dims=\"1\" loading=\"lazy\" decoding=\"async\" width=\"750\" height=\"422\" src=\"https:\/\/i0.wp.com\/randomnerdtutorials.com\/wp-content\/uploads\/2023\/05\/Raspberry-Pi-Pico-Bottloader-mode.jpg?resize=750%2C422&#038;quality=100&#038;strip=all&#038;ssl=1\" alt=\"Raspberry Pi Pico Bootloader mode\" class=\"wp-image-130903\" srcset=\"https:\/\/i0.wp.com\/randomnerdtutorials.com\/wp-content\/uploads\/2023\/05\/Raspberry-Pi-Pico-Bottloader-mode.jpg?w=750&amp;quality=100&amp;strip=all&amp;ssl=1 750w, https:\/\/i0.wp.com\/randomnerdtutorials.com\/wp-content\/uploads\/2023\/05\/Raspberry-Pi-Pico-Bottloader-mode.jpg?resize=300%2C169&amp;quality=100&amp;strip=all&amp;ssl=1 300w\" sizes=\"(max-width: 750px) 100vw, 750px\" \/><\/figure><\/div>\n\n\n<p>For future uploads using Arduino IDE, the board should go automatically into bootloader mode without the need to press the BOOTSEL button.<\/p>\n\n\n\n<p>Now, select your COM port in <strong>Tools <\/strong>&gt; <strong>Port<\/strong>. It may be the case that the COM port is grayed out. If that&#8217;s the case, don&#8217;t worry it will automatically find the port once you hit the upload button.<\/p>\n\n\n<div class=\"wp-block-image\">\n<figure class=\"aligncenter size-full\"><img data-recalc-dims=\"1\" loading=\"lazy\" decoding=\"async\" width=\"595\" height=\"684\" src=\"https:\/\/i0.wp.com\/randomnerdtutorials.com\/wp-content\/uploads\/2023\/06\/Raspberry-Pi-Pico-COM-port-not-showing.png?resize=595%2C684&#038;quality=100&#038;strip=all&#038;ssl=1\" alt=\"Raspberry Pi Pico - COM port not found Arduino IDE\" class=\"wp-image-132415\" srcset=\"https:\/\/i0.wp.com\/randomnerdtutorials.com\/wp-content\/uploads\/2023\/06\/Raspberry-Pi-Pico-COM-port-not-showing.png?w=595&amp;quality=100&amp;strip=all&amp;ssl=1 595w, https:\/\/i0.wp.com\/randomnerdtutorials.com\/wp-content\/uploads\/2023\/06\/Raspberry-Pi-Pico-COM-port-not-showing.png?resize=261%2C300&amp;quality=100&amp;strip=all&amp;ssl=1 261w\" sizes=\"(max-width: 595px) 100vw, 595px\" \/><\/figure><\/div>\n\n\n<p>Upload the code.<\/p>\n\n\n<div class=\"wp-block-image\">\n<figure class=\"aligncenter size-full\"><img data-recalc-dims=\"1\" loading=\"lazy\" decoding=\"async\" width=\"30\" height=\"30\" src=\"https:\/\/i0.wp.com\/randomnerdtutorials.com\/wp-content\/uploads\/2021\/05\/arduino-2-0-upload-button.png?resize=30%2C30&#038;quality=100&#038;strip=all&#038;ssl=1\" alt=\"Arduino 2.0 Upload Button\" class=\"wp-image-103678\"\/><\/figure><\/div>\n\n\n<p>You should get a success message.<\/p>\n\n\n<div class=\"wp-block-image\">\n<figure class=\"aligncenter size-full\"><img data-recalc-dims=\"1\" loading=\"lazy\" decoding=\"async\" width=\"595\" height=\"249\" src=\"https:\/\/i0.wp.com\/randomnerdtutorials.com\/wp-content\/uploads\/2023\/06\/success-uploading-code-Rpi-pico.png?resize=595%2C249&#038;quality=100&#038;strip=all&#038;ssl=1\" alt=\"\" class=\"wp-image-132414\" srcset=\"https:\/\/i0.wp.com\/randomnerdtutorials.com\/wp-content\/uploads\/2023\/06\/success-uploading-code-Rpi-pico.png?w=595&amp;quality=100&amp;strip=all&amp;ssl=1 595w, https:\/\/i0.wp.com\/randomnerdtutorials.com\/wp-content\/uploads\/2023\/06\/success-uploading-code-Rpi-pico.png?resize=300%2C126&amp;quality=100&amp;strip=all&amp;ssl=1 300w\" sizes=\"(max-width: 595px) 100vw, 595px\" \/><\/figure><\/div>\n\n\n<h2 class=\"wp-block-heading\" id=\"demonstration\">Demonstration<\/h2>\n\n\n\n<p>After uploading the code, test your circuit. Your LED should light up when you press the pushbutton. And turn it off when you release it.<\/p>\n\n\n\n<div class=\"wp-block-jetpack-tiled-gallery aligncenter is-style-rectangular\"><div class=\"tiled-gallery__gallery\"><div class=\"tiled-gallery__row\"><div class=\"tiled-gallery__col\" style=\"flex-basis:50.00000%\"><figure class=\"tiled-gallery__item\"><img decoding=\"async\" srcset=\"https:\/\/i1.wp.com\/randomnerdtutorials.com\/wp-content\/uploads\/2023\/06\/Raspberry-Pi-Pico-Pushbutton-LED-off-demonstration.jpg?strip=info&#038;w=600&#038;ssl=1 600w, https:\/\/i1.wp.com\/randomnerdtutorials.com\/wp-content\/uploads\/2023\/06\/Raspberry-Pi-Pico-Pushbutton-LED-off-demonstration.jpg?strip=info&#038;w=750&#038;ssl=1 750w\" alt=\"Raspberry Pi Pico Pushbutton LED off\" data-height=\"422\" data-id=\"132441\" data-link=\"https:\/\/randomnerdtutorials.com\/?attachment_id=132441#main\" data-url=\"https:\/\/randomnerdtutorials.com\/wp-content\/uploads\/2023\/06\/Raspberry-Pi-Pico-Pushbutton-LED-off-demonstration.jpg\" data-width=\"750\" src=\"https:\/\/i1.wp.com\/randomnerdtutorials.com\/wp-content\/uploads\/2023\/06\/Raspberry-Pi-Pico-Pushbutton-LED-off-demonstration.jpg?ssl=1\" data-amp-layout=\"responsive\"\/><\/figure><\/div><div class=\"tiled-gallery__col\" style=\"flex-basis:50.00000%\"><figure class=\"tiled-gallery__item\"><img decoding=\"async\" srcset=\"https:\/\/i1.wp.com\/randomnerdtutorials.com\/wp-content\/uploads\/2023\/06\/Raspberry-Pi-Pico-Pushbutton-LED-demonstration.jpg?strip=info&#038;w=600&#038;ssl=1 600w, https:\/\/i1.wp.com\/randomnerdtutorials.com\/wp-content\/uploads\/2023\/06\/Raspberry-Pi-Pico-Pushbutton-LED-demonstration.jpg?strip=info&#038;w=750&#038;ssl=1 750w\" alt=\"Raspberry Pi Pico Pushbutton LED on\" data-height=\"422\" data-id=\"132440\" data-link=\"https:\/\/randomnerdtutorials.com\/?attachment_id=132440#main\" data-url=\"https:\/\/randomnerdtutorials.com\/wp-content\/uploads\/2023\/06\/Raspberry-Pi-Pico-Pushbutton-LED-demonstration.jpg\" data-width=\"750\" src=\"https:\/\/i1.wp.com\/randomnerdtutorials.com\/wp-content\/uploads\/2023\/06\/Raspberry-Pi-Pico-Pushbutton-LED-demonstration.jpg?ssl=1\" data-amp-layout=\"responsive\"\/><\/figure><\/div><\/div><\/div><\/div>\n\n\n\n<h2 class=\"wp-block-heading\">Wrapping Up<\/h2>\n\n\n\n<p>In summary, to set a GPIO as a digital input or as a digital output, you need to use the <span class=\"rnthl rntliteral\">pinMode()<\/span> function. After that, you can use the <span class=\"rnthl rntliteral\">digitalRead()<\/span> function to read the state of an input or the <span class=\"rnthl rntliteral\">digitalWrite()<\/span> function to control the state of an output.<\/p>\n\n\n\n<p>As an example you&#8217;ve learned how to read a pushbutton and how to control an LED. What you learned can be applied to any digital input or output.<\/p>\n\n\n\n<p>We hope you&#8217;ve found this tutorial useful. If you&#8217;re just getting started with the Raspberry Pi Pico, make sure you read our getting started guides:<\/p>\n\n\n\n<ul class=\"wp-block-list\">\n<li><a href=\"https:\/\/randomnerdtutorials.com\/getting-started-raspberry-pi-pico-w\/\" title=\"\">Getting Started with Raspberry Pi Pico (and Pico W)<\/a><\/li>\n\n\n\n<li><a href=\"https:\/\/randomnerdtutorials.com\/programming-raspberry-pi-pico-w-arduino-ide\/\" title=\"\">Programming Raspberry Pi Pico with Arduino IDE<\/a><\/li>\n<\/ul>\n\n\n\n<p><a href=\"https:\/\/randomnerdtutorials.com\/projects-raspberry-pi-pico\/\">Check out all our Raspberry Pi Pico Guides \u00bb<\/a><\/p>\n\n\n\n<p>Thanks for reading.<\/p>\n","protected":false},"excerpt":{"rendered":"<p>Learn how to set the Raspberry Pi Pico GPIOs as digital inputs and digital outputs using Arduino IDE. You&#8217;ll learn how to read digital inputs like a button switch and &#8230; <\/p>\n<p class=\"read-more-container\"><a title=\"Raspberry Pi Pico: Control Digital Outputs and Read Digital Inputs (Arduino IDE)\" class=\"read-more button\" href=\"https:\/\/randomnerdtutorials.com\/raspberry-pi-pico-outputs-inputs-arduino\/#more-132427\" aria-label=\"Read more about Raspberry Pi Pico: Control Digital Outputs and Read Digital Inputs (Arduino IDE)\">CONTINUE READING \u00bb<\/a><\/p>\n","protected":false},"author":5,"featured_media":132445,"comment_status":"open","ping_status":"closed","sticky":false,"template":"","format":"standard","meta":{"jetpack_post_was_ever_published":false,"_jetpack_newsletter_access":"","_jetpack_dont_email_post_to_subs":false,"_jetpack_newsletter_tier_id":0,"_jetpack_memberships_contains_paywalled_content":false,"_jetpack_memberships_contains_paid_content":false,"footnotes":""},"categories":[324,325],"tags":[],"class_list":["post-132427","post","type-post","status-publish","format-standard","has-post-thumbnail","hentry","category-raspberry-pi-pico","category-raspberry-pi-pico-arduino-ide"],"aioseo_notices":[],"jetpack_featured_media_url":"https:\/\/i0.wp.com\/randomnerdtutorials.com\/wp-content\/uploads\/2023\/06\/Raspberry-Pi-Pico-Digital-Inputs-Outputs-Arduino-IDE.jpg?fit=1280%2C720&quality=100&strip=all&ssl=1","jetpack_sharing_enabled":true,"_links":{"self":[{"href":"https:\/\/randomnerdtutorials.com\/wp-json\/wp\/v2\/posts\/132427","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/randomnerdtutorials.com\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/randomnerdtutorials.com\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/randomnerdtutorials.com\/wp-json\/wp\/v2\/users\/5"}],"replies":[{"embeddable":true,"href":"https:\/\/randomnerdtutorials.com\/wp-json\/wp\/v2\/comments?post=132427"}],"version-history":[{"count":11,"href":"https:\/\/randomnerdtutorials.com\/wp-json\/wp\/v2\/posts\/132427\/revisions"}],"predecessor-version":[{"id":136655,"href":"https:\/\/randomnerdtutorials.com\/wp-json\/wp\/v2\/posts\/132427\/revisions\/136655"}],"wp:featuredmedia":[{"embeddable":true,"href":"https:\/\/randomnerdtutorials.com\/wp-json\/wp\/v2\/media\/132445"}],"wp:attachment":[{"href":"https:\/\/randomnerdtutorials.com\/wp-json\/wp\/v2\/media?parent=132427"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/randomnerdtutorials.com\/wp-json\/wp\/v2\/categories?post=132427"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/randomnerdtutorials.com\/wp-json\/wp\/v2\/tags?post=132427"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}