Arduino and Its IDE
Arduino and Its IDE
a) Arduino Equipment
1. Microcontroller:
1 https://nitw.ac.in/siemens/
In the Arduino Uno, pins 3, 5, 6, 9, 10, and 11 can be used for
PWM.
3. Power Supply:
USB Power:
Arduino boards can be powered via a USB cable connected to
a computer or a power bank.
External Power Supply:
A DC power jack allows external power sources, such as
batteries or adapters, typically between 7-12V.
Voltage Regulators:
These convert the incoming voltage to a level usable by the
Arduino, usually 5V or 3.3V, depending on the board.
4. Clock:
Arduino boards contain a crystal oscillator that helps control the
timing of the microcontroller.
The Arduino Uno operates with a 16 MHz clock, which sets the
timing for executing instructions.
5. Reset Button:
A physical button on the board allows users to restart the program
that’s running without disconnecting the power.
6. ICSP Header:
In-Circuit Serial Programming (ICSP) is used to program the
Arduino’s microcontroller directly.
This is useful for burning the bootloader or when using Arduino in
advanced setups.
7. Serial Communication (TX/RX):
Arduino boards are capable of communicating with other devices via
serial communication.
The TX (Transmit) and RX (Receive) pins allow communication
with other hardware, and they can also be used with the built-in USB
to communicate with a computer.
2 https://nitw.ac.in/siemens/
Popular Arduino boards include:
Arduino Uno:
Arduino Nano:
Arduino Mega:
A larger board designed for more complex projects with many I/O
requirements.
It features 54 digital I/O pins, 16 analog inputs, and uses the
ATmega2560 microcontroller.
Arduino Due:
Arduino Leonardo:
3 https://nitw.ac.in/siemens/
Key Features of Arduino
Open Source:
Modularity:
Ease of Use:
Cross-Platform:
The Arduino IDE is available for Windows, macOS, and Linux, making it
accessible to developers on all major platforms.
Applications of Arduino:
1. Robotics:
4 https://nitw.ac.in/siemens/
2. Home Automation:
4. Wearable Devices:
Boards like the Arduino Nano and Pro Mini are used to create wearable
electronics, often in combination with sensors like accelerometers and
gyroscopes to track movement.
5. Environmental Monitoring:
6. Prototyping:
5 https://nitw.ac.in/siemens/
Limitations:
1. Limited Processing Power:
2. No Operating System:
6 https://nitw.ac.in/siemens/
With integrated features like over-the-air updates and device
management, Arduino IoT Cloud simplifies the creation of connected
projects.
setup(): Initializes variables, sets pin modes, and runs once when the
board is powered up.
loop(): Contains the main code that runs repeatedly after the setup().
Serial Monitor:
This tool in the IDE allows communication between the Arduino and
a computer.
You can send and receive data, which is useful for debugging.
7 https://nitw.ac.in/siemens/
Libraries:
The IDE also allows you to compile code, check for errors, and upload code
directly to the Arduino board via a USB cable.
Below will show you how to install the Arduino IDE on Windows 10.
8 https://nitw.ac.in/siemens/
Step 2: Click on the Download Link
Scroll down until you see the link that says 'Windows installer' and click on it.
9 https://nitw.ac.in/siemens/
After clicking on the download link you'll be redirected to the donation page,
here you can donate or skip it if you like by clicking on the 'Just download' link.
A new window will open asking you to agree to the license agreement.
10 https://nitw.ac.in/siemens/
Step 5: Select What to Install
Now you'll see all the available options to install the software with.
If you don't know what you need, it is best to keep everything checked as you
can change it later when the installation has finished.
11 https://nitw.ac.in/siemens/
Now you have to choose the path the software will be installed in.
it is fine to leave it at the configured location but if you want the Arduino IDE
somewhere else installed you can change that here.
When the installation is finished you may click on 'close' to end the setup
wizard.
12 https://nitw.ac.in/siemens/
Step 8: Launch the Arduino IDE
To launch the IDE you can click on the Desktop icon that was created for you,
or by searching for it in the start menu.
c) Arduino Programming
Basic Syntax:
Variables: You can define variables for storing data.
Functions: These are blocks of code that can be reused.
Control Structures: Arduino uses standard programming control
structures like if, for, and while loops.
Pin Functions:
o pinMode(pin, mode): Sets whether a pin is an input or output.
13 https://nitw.ac.in/siemens/
o digitalWrite(pin, value): Writes a HIGH or LOW value to a digital
pin.
o digitalRead(pin): Reads a HIGH or LOW value from a digital pin.
o analogRead(pin): Reads an analog value from a pin.
o analogWrite(pin, value): Writes a PWM (Pulse Width Modulation)
signal to a pin.
Arduino Uno
1. Overview:
The Arduino Uno is one of the most popular microcontroller boards
in the Arduino family, based on the ATmega328P microcontroller.
It's widely used for developing both simple and complex electronics
projects.
The board is known for its ease of use, robust community support,
and versatility, making it suitable for hobbyists, students, and
professionals alike.
2. Key Specifications:
Microcontroller: ATmega328P
Operating Voltage: 5V
Input Voltage (recommended): 7-12V
Input Voltage (limit): 6-20V
Digital I/O Pins: 14 (of which 6 can provide PWM output)
Analog Input Pins: 6
DC Current per I/O Pin: 20 mA
DC Current for 3.3V Pin: 50 mA
Flash Memory: 32 KB (ATmega328P), 0.5 KB used by the bootloader
SRAM: 2 KB (ATmega328P)
EEPROM: 1 KB (ATmega328P)
Clock Speed: 16 MHz
USB Port: Type B for communication with a computer and power
supply.
Power Supply Pins: Vin, 3.3V, 5V, GND
14 https://nitw.ac.in/siemens/
Dimensions: 68.6 mm x 53.4 mm
Weight: Approximately 25g
3. Features:
15 https://nitw.ac.in/siemens/
The tool enables users to write code, connect components, and test their
circuits before deploying them to a real Arduino Uno board.
Key Features:
1. Online Platform: TinkerCAD is cloud-based, so no installations are
necessary, and it can be accessed from anywhere with an internet connection.
2. Simulation Environment: You can simulate real-time interaction between the
components and the Arduino Uno board, which is ideal for testing and
troubleshooting.
3. Code Editor with Arduino IDE Integration: TinkerCAD allows you to write,
compile, and run Arduino sketches directly within the platform. It supports both
block-based coding (for beginners) and text-based coding using the Arduino IDE
language (C/C++).
4. Component Library: TinkerCAD offers a vast library of virtual components,
including resistors, LEDs, buttons, sensors, and motors. These can be connected
to the virtual Arduino Uno for simulations.
5. Shared and Collaborative Design: Users can collaborate on projects in real-
time or share their designs with others, which is useful for teamwork and
education.
6. Learning Resources: TinkerCAD provides built-in tutorials, sample circuits,
and learning modules that guide users through the basics of electronics and
Arduino programming.
16 https://nitw.ac.in/siemens/
this includes selecting the Arduino Uno board and other relevant components
(e.g., LEDs, sensors).
3. Wiring and Circuit Layout: Components can be connected using virtual
wires, following the correct circuit diagram rules. The platform checks for
common issues like short circuits or incorrect wiring.
4. Writing Arduino Code: Once the circuit is built, users can write the Arduino
code. TinkerCAD offers two coding modes:
- Blocks: Visual programming for beginners where users connect blocks that
represent code functions.
- Text Editor: Users can write actual Arduino code in C/C++ using the built-in
editor, similar to the Arduino IDE.
5. Simulation: After the components are wired and the code is written, users can
simulate the project. The simulation allows real-time testing of how the code
interacts with the circuit. The Arduino Uno responds to inputs like button presses
or sensor data, and the output (like LED blinking or motor rotation) is displayed
accordingly.
6. Exporting Code: Once the circuit and code have been successfully simulated,
the Arduino code can be exported to the Arduino IDE for uploading to a physical
Arduino board.
17 https://nitw.ac.in/siemens/
- Connect the LED anode (positive leg) to digital pin 13 of the Arduino using a
jumper wire.
- Connect the LED cathode (negative leg) to a 220-ohm resistor and then to the
ground (GND) pin on the Arduino.
- Write the code in the TinkerCAD editor:
- We are writing the code in cpp
void setup() {
pinMode(13, OUTPUT);
}
void loop() {
digitalWrite(13, HIGH); // Turn the LED on
delay(1000); // Wait for a second
digitalWrite(13, LOW); // Turn the LED off
delay(1000); // Wait for a second
}
- Run the simulation to see the LED blinking on the virtual Arduino board.
18 https://nitw.ac.in/siemens/
3. Instant Feedback: The simulation feature helps users understand if their code
and circuit are working properly before transferring the project to a physical
board.
4. Educational Tool: It’s a great platform for teaching and learning electronics
and programming because it offers a safe, virtual environment to experiment
without the risk of damaging components.
Limitations
1. Limited Advanced Components: While TinkerCAD offers a wide array of
components, certain advanced or custom parts may not be available in its library.
2. Performance: Simulating complex or resource-heavy circuits may be slower
than on a physical Arduino board, especially when many components are
involved.
3. No Real-Time Serial Monitor: Although TinkerCAD supports basic serial
monitoring, it lacks some advanced debugging features available in the actual
Arduino IDE.
Conclusion
TinkerCAD is an invaluable tool for Arduino Uno users, especially
beginners and educators.
Its cloud-based design environment, combined with real-time simulation
and integrated coding tools, make it easy to build, test, and iterate on
projects.
While it has some limitations in terms of component availability and
performance for very complex projects, it is an excellent starting point for
learning and prototyping in embedded systems.
19 https://nitw.ac.in/siemens/
Other Programs in TinkerCAD
Code:
#define led 7
#define button 2
int s;
void setup()
{
pinMode(led,OUTPUT);
pinMode(button,INPUT);
}
void loop()
{
s = digitalRead(button);
20 https://nitw.ac.in/siemens/
if(s == 1)
{
digitalWrite(led,0);
}
else if(s == 0)
{
digitalWrite(led,1);
}
}
void loop()
{
Serial.println("Welcome to IoT webinar");
delay(1000);
}
After uploading the code, open “Serial Monitor” and set the baud rate to 9600
and check the output.
21 https://nitw.ac.in/siemens/
Program: Writing a code to check the Photoresistor (LDR) sensor.
Code:
#define LDR A2
void setup() {
pinMode(LDR, INPUT);
Serial.begin(9600);
}
void loop() {
int a;
a = analogRead(LDR);
Serial.println(a);
}
22 https://nitw.ac.in/siemens/
Program: Writing a code to check the Temperature (LM35) sensor
Code:
#define Temp A2
float celsius = 0;
void setup() {
pinMode(Temp, INPUT);
Serial.begin(9600);
}
void loop() {
celsius = map(((analogRead(Temp) - 20) * 3.04), 0, 1023, -40, 125);
Serial.println(celsius);
}
23 https://nitw.ac.in/siemens/
Program: Writing a code to check the PWM with a Buzzer
Code:
#define Buzzer 6
void setup() {
pinMode(Buzzer,OUTPUT);
}
void loop() {
for(int i = 0; i <= 255; i++)
{
analogWrite(Buzzer,i);
delay(50);
}
}
24 https://nitw.ac.in/siemens/
Program: Write a Code using Ultrasonic Sensor, L293D Motor Driver, Servo
Motor and a DC motor
Code:
#include<Servo.h>
#define trigPin 4
#define echoPin 2
#define servoPin 8
#define in1 11
#define in2 10
#define in3 6
#define in4 5
Servo myservo;
void setup() {
pinMode(trigPin, OUTPUT);
pinMode(echoPin, INPUT);
pinMode(in1, INPUT);
25 https://nitw.ac.in/siemens/
pinMode(in2, INPUT);
pinMode(in3, INPUT);
pinMode(in4, INPUT);
Serial.begin(9600);
myservo.attach(servoPin);
myservo.write(0);
delay(1000);
myservo.write(180);
delay(1000);
myservo.write(0);
delay(1000);
}
void loop()
{
digitalWrite(in1, HIGH);
digitalWrite(in2, LOW);
digitalWrite(in3, HIGH);
digitalWrite(in4, LOW);
digitalWrite(trigPin, HIGH);
delay(10);
digitalWrite(trigPin, LOW);
float duration = pulseIn(echoPin, HIGH);
float distance = duration * 0.034 / 2;
Serial.println(distance);
26 https://nitw.ac.in/siemens/
if(distance <= 40)
{
digitalWrite(in1, LOW);
digitalWrite(in2, LOW);
digitalWrite(in3, HIGH);
digitalWrite(in4, HIGH);
myservo.write(0);
delay(1000);
myservo.write(180);
delay(1000);
myservo.write(0);
delay(1000);
}
}
27 https://nitw.ac.in/siemens/