0% found this document useful (0 votes)
6 views

Department of Electromechanical Engineering Workshop For Mechatronics

Uploaded by

ntnlzekarias
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
6 views

Department of Electromechanical Engineering Workshop For Mechatronics

Uploaded by

ntnlzekarias
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 8

Department of Electromechanical Engineering

Workshop for Mechatronics

1/8
Programming Overview

1 Introduction

2 Minimum Code

3 Important Commands

4 Libraries

2/8
Introduction

Introduction
Arduino is a prototype platform (open-source) based on an easy-to-
use hardware and software. It consists of a circuit board, which can
be programed (referred to as a microcontroller) and a ready-made
software called Arduino IDE (Integrated Development Environment),
which is used to write and upload the computer code to the physical
board.

3/8
Minimum Code

Minimum Code

setup : It is called only when the Arduino is powered on or


reset. It is used to initialize variables and pin modes
loop : The loop functions runs continuously till the device is
powered off. The main logic of the code goes here.

4/8
Minimum Code

PinMode
A pin on arduino can be set as input or output by using pinMode
function.
pinMode(13, OUTPUT); // sets pin 13 as output pin
pinMode(13, INPUT); // sets pin 13 as input pin

Reading/writing digital values


digitalWrite(13, LOW); // Makes the output voltage on pin
13, 0V
digitalWrite(13, HIGH); // Makes the output voltage on pin
13, 5V
int buttonState = digitalRead(2); // reads the value of pin 2
in buttonState

5/8
Important Commands

Important Commands
delay(ms): pauses the program for the amount of time (in millisec-
ond)specified as parameter.

The code pauses the program for one second before toggling the
output

serial: used for communication between the arduino board and a


computer or other devices. It communicates on digital pins 0 (RX)
and 1 (TX)as well as with the computer via USB. Thus, if you use
these functions, you cannot also use pins 0 and 1 for digital in/out 6/8
Important Commands

serial.begin(bits/second): sets the data rate in bits per second (baud)


for serial data transmission. For communicating with the computer,
use one of these rates: 300, 600, 1200, 2400, 4800, 9600, 14400,
19200, 28800, 38400, 57800, or 115200. you can, however, specify
other rates -for example, to communicate over pins 0 and 1 with a
component that requires a particular baud rate.

serial.prinln(val): prints data in a new line to the serial port as human


readable text. The command takes the same forms as serial.print()

7/8
Libraries

What are Libraries?


Libraries are a collection of code that makes it easy to connect to a
sensor, display, module, etc. For example, the built-in LiquidCrystal
library makes it easy to talk to character LCD displays. There are
many libraries available on the Internet for download.
How to use them?

8/8

You might also like