Arduino Code Explanation

by Mar 19, 2020Arduino IDE Programming

As soon as you open the Arduino IDE, you will see a window of the Arduino code , consisting of basically two main parts: setup and loop. The entire code written in the Arduino IDE is known as sketch. A sketch is the name that Arduino uses for a program. It’s the unit of code that is uploaded to and run on an Arduino board. they are written in C/C++.

Arduino Sketch

Arduino code: setup() and loop()

These are the two most important functions used in Arduino. The setup() function runs once in the entire program whereas loop() function is the heart of the Arduino sketch where the written commands are run over again and again. setup() is a good place to do tasks like setting pin modes or initializing libraries.  You need to include both functions in your sketch, even if you don’t need them for anything.

Other Important functions

  1. pinMode():  This function configures a pin as either an input or an output.  Syntax : pinMode(pin number, OUTPUT/INPUT);
  2. digitalWrite() : This outputs the value on a pin. Syntax: digitalWrite(pin number, HIGH/LOW) ;
  3. delay(): The delay tells the Arduino to wait for the milliseconds specified inside the brackets. Syntax : delay(number of milliseconds);

Uploading the sketch

To upload a sketch, click on the Tools option in the tools bar at the top. Select the board as Arduino Uno/nano and the port in which it is plugged. After saving the sketch, press Ctrl+U or press the second icon(the arrow button) below the tools bar.

Comments in Arduino

Everything between the /* and */ is ignored by the Arduino. It is written so that the user is able to explain exactly how the code will work, which pins are used, etc. For a single line comment, you should write ‘//’ and then the comment.

Creating a multiplication Skill in Alexa using python

Written By Anmol Punetha

Hey, I am Anmol. I am a tech blogger and an electronics engineering student at the same time. As you're reading my blog, you are getting a generous amount of information in simpler words. Hope it's of use. Thank you for visiting. Keep reading!

RELATED POSTS

Arduino Uno – A basic introduction

Arduino Uno – A basic introduction

Microcontrollers are widely used in embedded devices and make the devices reliable and cheap for our requirements. They contain CPU, RAM, ROM and some form of Input/Output ports. Microcontrollers are generally a computer on a single integrated circuit which is better...

VIDEOS – FOLLOW US ON YOUTUBE

EXPLORE OUR IOT PROJECTS

IoT Smart Gardening System – ESP8266, MQTT, Adafruit IO

Gardening is always a very calming pastime. However, our gardens' plants may not always receive the care they require due to our active lifestyles. What if we could remotely keep an eye on their health and provide them with the attention they require? In this article,...

How to Simulate IoT projects using Cisco Packet Tracer

In this tutorial, let's learn how to simulate the IoT project using the Cisco packet tracer. As an example, we shall build a simple Home Automation project to control and monitor devices. Introduction Firstly, let's quickly look at the overview of the software. Packet...

All you need to know about integrating NodeMCU with Ubidots over MQTT

In this tutorial, let's discuss Integrating NodeMCU and Ubidots IoT platform. As an illustration, we shall interface the DHT11 sensor to monitor temperature and Humidity. Additionally, an led bulb is controlled using the dashboard. Besides, the implementation will be...

All you need to know about integrating NodeMCU with Ubidots over Https

In this tutorial, let's discuss Integrating NodeMCU and Ubidots IoT platform. As an illustration, we shall interface the DHT11 sensor to monitor temperature and Humidity. Additionally, an led bulb is controlled using the dashboard. Besides, the implementation will be...

How to design a Wireless Blind Stick using nRF24L01 Module?

Introduction Let's learn to design a low-cost wireless blind stick using the nRF24L01 transceiver module. So the complete project is divided into the transmitter part and receiver part. Thus, the Transmitter part consists of an Arduino Nano microcontroller, ultrasonic...

Sending Temperature data to ThingSpeak Cloud and Visualize

In this article, we are going to learn “How to send temperature data to ThingSpeak Cloud?”. We can then visualize the temperature data uploaded to ThingSpeak Cloud anywhere in the world. But "What is ThingSpeak?” ThingSpeak is an open-source IoT platform that allows...

Amaze your friend with latest tricks of Raspberry Pi and Firebase

Introduction to our Raspberry Pi and Firebase trick Let me introduce you to the latest trick of Raspberry Pi and Firebase we'll be using to fool them. It begins with a small circuit to connect a temperature sensor and an Infrared sensor with Raspberry Pi. The circuit...

How to implement Machine Learning on IoT based Data?

Introduction The industrial scope for the convergence of the Internet of Things(IoT) and Machine learning(ML) is wide and informative. IoT renders an enormous amount of data from various sensors. On the other hand, ML opens up insight hidden in the acquired data....

Smart Display Board based on IoT and Google Firebase

Introduction In this tutorial, we are going to build a Smart Display Board based on IoT and Google Firebase by using NodeMCU8266 (or you can even use NodeMCU32) and LCD. Generally, in shops, hotels, offices, railway stations, notice/ display boards are used. They are...

Smart Gardening System – GO GREEN Project

Automation of farm activities can transform agricultural domain from being manual into a dynamic field to yield higher production with less human intervention. The project Green is developed to manage farms using modern information and communication technologies....