Hands Notes - Basics of Arduino
Hands Notes - Basics of Arduino
INTRODUCTION TO ARDUINO
2.1. WHAT IS ARDUINO?
Arduino is an open-source electronics platform based on easy-to-use hardware and
software. Arduino boards are able to read inputs and turn it into an output. Basically Arduino
is a microcontroller board. You can tell your board what to do by sending a set of
instructions. To do so, the following are required:
● Arduino programming language,
There are many other types of Arduino boards available, e.g., Mega for more interfaces,
Mini or Nano for small size, LilyPad for wearable use, etc. All Arduino boards have one
thing in common: they are programmed through the Arduino IDE. This is the software that
allows you to write and upload code. Some boards are designed to be embedded and have no
programming interface (hardware) which you would need to buy separately. Some can run
directly from a 3.7V battery, others need at least 5V. The following figure shows various
types of Arduino Boards (fig.2).
Arduino is open source, which means anyone can copy, modify, produce new firmware and
use their own Arduino board (often, it is cheaper and easier to buy). Lot of the electronic
hardware and software is required to build Arduino-based applications and systems is
available online, so you can focus on building your own projects and products in a short time
(called Rapid Prototyping). So, even school children in high, middle, or even elementary
schools can start working on Arduino projects.
You can download the Installer (.exe; recommended) or Zip package. The Zip package can
be used for portable installation (https://www.arduino.cc/en/Guide/PortableIDE). Choose the
appropriate operating system installation package for your computer (including 32 or 64-bit
OS). Store the software in a hardware directory of your choice.
CMR College of Engineering & Technology Page 4
CENTRE FOR ENGINEERING EDUCATION RESEARCH– BASICS OF ARDUINO
The install step extracts and installs all required files for operating the Arduino board.
b. Connect your Arduino: to one of your computer’s USB ports using the USB Type A to Type
B cable provided.
a. Plug in your board and wait for Windows to begin its driver installation process.
c. While in the Control Panel, navigate to System. Next, open the Device Manager.
d. Look under Ports (COM & LPT). You should see an open port named "Arduino (COMxx)"
where xx stands for two digits representing the port number.
e. Right click on the "Arduino (COMxx)" port and choose the "Update Driver Software" option.
g. Finally, navigate to and select the driver file named arduino.inf, located in the Drivers folder
of the Arduino Software download (not the "FTDI USB Drivers" sub-directory).
Open the Arduino IDE software on your computer by double clicking the Arduino icon in
the directory. Poke around and familiarize yourself with the interface.
2. Upload: Send the code from the computer to the Arduino board. When this command is
selected, Arduino will perform the step-step-by instructions in the code.
4. Open: This button will let you open an existing sketchor program.
6. Serial Monitor: This will open a window that displays any serial information your
Arduino is transmitting. It is very useful for debugging (find and remove errors from)
your code.
7. Sketch Name: This shows the name of the sketch you are currently working on.
8. Code Area: This is the area where you compose the code for your sketch.
9. Message Area: This is where the IDE displays messages on the results of operation,
including errors.
Go to Tools under the menu bar, navigate to the Board dropdown menu (indicated by right
arrow ►) and select the board used (e.g., Arduino Uno). The selected board appears on the
Task Bar right side.
Next, select the Serial Port (as noted from Windows Device Manager) of the Arduino board
from the Tools | Port| Serial Ports pull down menu (here, COM3).
Components Required:
1. Arduino board
3. One LED
4. Resistor (470 Ω)
Circuit diagram:
1. Make the connections as in circuit diagram Figure 9. That is, connect Pin 9 from Arduino
board to one end of the resistor on the breadboard. The other end of the resistor is connected to
the LED positive lead. The LED negative lead is connected to the Ground Pin of Arduino
through the breadboard. In this circuit, we say that the LED and resistor are connected in series.
3. In the Arduino IDE, select Uno as the board and select the appropriate COM port.
4. In Arduino IDE, under … select Examples sketch the proper LED blinking program is
executed by verifying the program by clicking the verify option in menu bar.
5. If the program compiles with success, then upload the coding to Arduino by clicking the
upload option in menu bar.
6. After the program is uploaded to the Arduino board, the LED blinks.
Code:
// Note that the spaces around = are immaterial, but add to readability
// The setup routine runs once when you press Reset button
Void setup()
{
// Initialize the digital pin as an output
pinMode(led,OUTPUT);
}
// The loop routine runs over and over again forever:
void loop(){
digitalWrite(led,HIGH); // turn the LED on by making voltage HIGH
delay(1000); // wait for a second
digitalWrite(led,LOW); // turn the LED off by making the voltage LOW
delay(1000); // wait for a second
}
Results and Discussions:
How does the hardware and software work together in this exercise?
An Arduino program has a setup function and a loop function. The setup function as
the name implies, specifies details like if a pin is used as digital input or output, or as analog
input, and also specifies parameters like communication speed (baud rate), etc. In addition, as in
C programs, we also have declaration statements, e.g., the statement
means that the Pin 9 of Arduino is to be used. digitalWrite and delay are functions
belonging to the Arduino library. We can write another declaration statement as int PAUSE =
1000; and then use PAUSE as parameter for the delay function calls. In this case, if you want
to decrease or increase the delay, it is sufficient to change PAUSE value just once.
The loop function contains the step-by-step instructions of the program for execution.
The statement digitalWrite(led,HIGH); sends a positive (+5 volts) signal to Pin 9 and
therefore to the LED anode and the LED is turned ON. The LED stays ON for the duration) of
the delay (1000, or one second).
Next, when the digitalWrite(led,LOW); is executed, Pin 9 and therefore the LED
anode is sent a LOW (zero volts) signal, and so the LED is turned OFF for a period of one
second. As the loop is executed indefinitely (till you unplug the board!), the LED blinks on and
off for one second each. The LED blinking frequency is 0.5 Hz (hertz, the unit for frequency), or
equivalently the period of LED blinking is two seconds.
The Serial Monitor can be used to print out the values of interest on the computer’s
output window, using the command Serial.println( ).
To make an LED glow when controller detects a button pressed using Arduino .
Components Required:
2. Breadboard
4. Jumper Wires
5. LED
Circuit Diagram:
1. First, fix the button in the breadboard; connect the longer end of button with Pin 7 of Arduino
and shorter end of button with ground (first row or bottom row) of breadboard.
CMR College of Engineering & Technology Page 12
CENTRE FOR ENGINEERING EDUCATION RESEARCH– BASICS OF ARDUINO
Code:
Serial.begin(9600);
pinMode(buttonPin, INPUT);
Serial.println(buttonState);
if(buttonState == HIGH) {
digitalWrite(ledPin, HIGH);
delay(1000);
}
else {
digitalWrite(ledPin, LOW);
delay(1000);
CMR College of Engineering & Technology Page 13
CENTRE FOR ENGINEERING EDUCATION RESEARCH– BASICS OF ARDUINO
To read the temperature and display the same in serial monitor using Arduino
Components Required:
1. Arduino
2. Breadboard
3. LM35 temperature sensor
4. Jumper wires
Circuit diagram:
Accuracy ±0.5°C
Procedure:
Code:
/*Temperature Sensor */
float temp;
int tempPin = 4;
void setup()
{
Serial.begin(9600);
}
void loop()
{
temp = analogRead(tempPin);
temp = temp * 0.48828125; // Calibration for degree Celsius
Serial.print("TEMPRATURE = ");
Serial.print(temp);
Serial.print("*C");
Serial.println();
delay(1000);
}
Results and Discussions:
Temperature control is a major part of climate control systems in homes and offices
(HVAC – heating, ventilation, and air conditioning).
To interface the Liquid Crystal Display (LCD) with the Arduino Uno to enable displaying the
characters on the LCD.
Components used:
1. Arduino or Genuino Board
2. LCD Screen (compatible with Hitachi HD44780 driver)
3. pin headers to solder to the LCD display pins
4. 10k ohm potentiometer
5. 220 ohm resistor
6. hook-up wires
7. breadboard
LCD Schematic:
Technical Specifications:
Parameter Values
Interface I2C
Connections Guide:
1. Write the program on the Arduino IDE (The program is given below for your reference)
3. Connect the supply voltage(Vcc) and ground(GND) pins of the LCD module to the 5V and
GND pins of Arduino microcontroller.
CMR College of Engineering & Technology Page 18
CENTRE FOR ENGINEERING EDUCATION RESEARCH– BASICS OF ARDUINO
4. Connect the SDA and SCL pins of the LCD module to Analog pins (A4&A5) of the Arduino
microcontroller.
Notes:
The LCDs have a parallel interface, meaning that the microcontroller has to manipulate
several interface pins at once to control the display. The interface consists of the following pins:
- A register select (RS) pin that controls where in the LCD's memory you're
writing data to. You can select either the data register, which holds what goes
on the screen, or an instruction register, which is where the LCD's controller
looks for instructions on what to do next.
- A Read/Write (R/W) pin that selects reading mode or writing mode
- An Enable pin that enables writing to the registers 8 data pins (D0 -D7). The
states of these pins (high or low) are the bits that you're writing to a register
when you write, or the values you're reading when you read.
- There's also a display constrast pin (Vo), power supply pins (+5V and
Gnd) and LED Backlight (Bklt+ and BKlt-) pins that you can use to power
the LCD, control the display contrast, and turn on and off the LED backlight,
respectively.
The process of controlling the display involves putting the data that form the image of what you
want to display into the data registers, then putting instructions in the instruction register.
The LiquidCrystal Library simplifies this for you so you don't need to know the low-level
instructions.
The Hitachi-compatible LCDs can be controlled in two modes: 4-bit or 8-bit. The 4-bit mode
requires seven I/O pins from the Arduino, while the 8-bit mode requires 11 pins. For displaying
text on the screen, you can do most everything in 4-bit mode, so example shows how to control a
2x16 LCD in 4-bit mode.
Important note:
Before wiring the LCD screen to your Arduino or Genuino board we suggest to solder a pin
header strip to the 14 (or 16) pin count connector of the LCD screen, as you can see in the image
above.
To wire your LCD screen to your board, connect the following pins:
● LCD RS pin to digital pin 12
Hitachi HD44780 driver. There are many of them out there, and you
can usually tell them by the 16-pin interface.
The circuit:
* LCD RS pin to digital pin 12
* LCD Enable pin to digital pin 11
* LCD D4 pin to digital pin 5
* LCD D5 pin to digital pin 4
* LCD D6 pin to digital pin 3
* LCD D7 pin to digital pin 2
* LCD R/W pin to ground
* LCD VSS pin to ground
* LCD VCC pin to 5V
* 10K resistor:
* ends to +5V and ground
* wiper to LCD VO pin (pin 3)
http://www.arduino.cc/en/Tutorial/LiquidCrystalHelloWorld
*/
#include <LiquidCrystal.h>
// initialize the library by associating any needed LCD interface pin with the arduino pin number
it is connected to
void setup() {
lcd.begin(16, 2);
lcd.print("hello, world!");
void loop()
{
// (note: line 1 is the second row, since counting begins with 0):
lcd.setCursor(0, 1);
lcd.print(millis() / 1000);
Conclusion:
In this experiment, the LCD is successfully interfaced with the Arduino board.
Reference: https://www.arduino.cc/en/Tutorial/HelloWorld
To interface the FC-51 Infrared sensor (IR) sensor with the Arduino Uno to sense the path is
clear/ indicate the presence of any obstacles.
Components Required:
4. Desktop or laptop PC
5. Jumper wires
Infrared sensor:
Current
23 mA- 43mA
Consumption
Methodology:
This module has built-in IR transmitter and receiver that sends out IR signals to detect the
presence of any obstacles. The module also has an on board potentiometer to vary the
detection range. It can sense hurdles even in complete darkness. By using an LED which
produces light at the same wavelength as what the sensor is looking for, you can look at the
intensity of the received light. When an object is close to the sensor, the light from the LED
bounces off the object and into the light sensor. This results in a large jump in the intensity,
which we already know can be detected using a threshold.
1. Connect the Vcc and GND of the sensor to the 5V and GND pins of the Arduino Uno
respectively.
2. Connect the OUT pin of the sensor (the input pin) to the digital pin 7 of the Arduino Uno.
void setup()
{
pinMode(LED, OUTPUT);
pinMode(obstaclePin, INPUT);
Serial.begin(9600);
}
void loop()
{
hasObstacle = digitalRead(obstaclePin); //Reads the output of the obstacle
sensor from the 7th PIN of the Digital section of the arduino
else
{
Serial.println("Path is clear");
digitalWrite(LED, LOW);
}
delay(200);
Output (Screenshot)
Components used:
4. Desktop or Laptop PC
5. Interfacing program
6. Jumper wires
Ultrasonic Sensor:
Methodology:
Ultrasonic sensors compute the distance to the target object by emitting short, high-frequency
sound pulses at regular intervals that propagate in air at the velocity of sound. As these pulses
hit the object, they are reflected back as echo signals to the sensor which then computes the
distance based on time-span between the emitting the signal and receiving the echo.
Technical Specifications:
Parameter Values
Supply voltage 5V DC
CMR College of Engineering & Technology Page 26
CENTRE FOR ENGINEERING EDUCATION RESEARCH– BASICS OF ARDUINO
Maximum Range 4m
Connections guide:
1. Write the program on the Arduino IDE (The program is given below for your reference)
3. Connect the pins Vcc and Gnd of the sensor to 5v and Gnd of the Arduino.
Program:
void setup() {
}
void loop()
// and the distance result in inches and centimeters: long duration, inches, cm;
pinMode(trigPin, OUTPUT);
digitalWrite(trigPin, LOW);
delayMicroseconds(2);
digitalWrite(trigPin, HIGH);
delayMicroseconds(10);
digitalWrite(trigPin, LOW);
pinMode(echoPin, INPUT);
inches = microsecondsToInches(duration);
cm = microsecondsToCentimeters(duration);
Serial.print(inches);
Serial.print("in, ");
Serial.print(cm);
Serial.print("cm");
Serial.println();
delay(100);
return microseconds / 74 / 2;
// The ping travels out and back, so to find the distance of the
return microseconds / 29 / 2;
}
Output:
Conclusion:
In this experiment, the ultrasonic analog sensor is interfaced with the Arduino board and the
distances of various objects were determined using the Arduino microcontroller.