University Institute of Engineering and Technology, Kurukshrtra University, Kurukshetra
University Institute of Engineering and Technology, Kurukshrtra University, Kurukshetra
SESSION: 2020-24
Objectives: To study about Arduino and basic awareness about it and learn to use Tinkercad.
Outcomes: Students will be able to understand Arduino, and learn to use Tinkercad, create simple
electronic circuits using electrical components and simulate the electronic circuit.
Arduino is an open-source electronics platform based on easy-to-use hardware and software. Arduino
boards are able to read inputs - light on a sensor, a finger on a button, or a Twitter message - and turn it
into an output - activating a motor, turning on an LED, publishing something online. You can tell your
board what to do by sending a set of instructions to the microcontroller on the board. To do so you use the
Arduino programming language (based on Wiring), and the Arduino Software (IDE), based on Processing.
Figure 1.1: Basic Arduino microcontroller Figure 1.2: Cable for connection
Arduino Uno
Arduino Uno is the most standard board available and probably the best choice for a beginner. We can
directly connect the board to the computer via a USB Cable which performs the function of supplyingthe
power as well as acting as a serial port.
Figure 1.3. Arduino Uno Pin details
Vin: This is the input voltage pin of the Arduino board used to provide input supply from an external
power source.
5V: This pin of the Arduino board is used as a regulated power supply voltage and it is used to give supply
to the board as well as onboard components.
3.3 V: This pin of the board is used to provide a supply of 3.3V which is generated from a voltage regulator
on the board.
GND: This pin of the board is used to ground the Arduino board.
Reset: This pin of the board is used to reset the microcontroller. It is used to Resets the microcontroller.
Analog Pins: The pins A0 to A5 are used as an analog input and it is in the range of 0-5V.
Digital Pins: The pins 0 to 13 are used as a digital input or output for the Arduino board.
Serial Pins: These pins are also known as a UART pin. It is used for communication between the Arduino
board and a computer or other devices. The transmitter pin number 1 and receiver pin number 0is used to
transmit and receive the data resp.
External Interrupt Pins: This pin of the Arduino board is used to produce the External interrupt and it
is done by pin numbers 2 and 3.
PWM Pins: These pins of the board is used to convert the digital signal into an analog by varying the
width of the Pulse. The pin numbers 3,5,6,9,10 and 11 are used as a PWM pin.
SPI Pins: This is the Serial Peripheral Interface pin, it is used to maintain SPI communication with the
help of the SPI library.
LED Pin: The board has an inbuilt LED using digital pin-13. The LED glows only when the digital pin
becomes high.
AREF Pin: This is an analog reference pin of the Arduino board. It is used to provide a reference
voltage from an external power supply.
Workspace
It is an area where the electronic components and 3D objects are placed.
Components of a circuit
TinkerCAD displays the electronic components used to create circuits in the panel usually at the right
side of the page.
Some of the electronic components used to create circuits are:-
1. Basic components – It consists of a battery, push button, resistor, LED, capacitor, etc.
2. Circuit Assembly ‐ Circuit assemblies are simple, pre‐made circuits that can be incorporated
into the 3D designs. Some of the circuit assemblies available are glow circuit, move circuit and
spin circuit.
Rotate
It is used to rotate by 360 degrees any component placed onto the workspace.
Start/Stop Simulation
Simulation is an imitation of an operation of a real‐world process or system. In Tinkercad, Start/Stop
Simulation tests the working of the circuits and the components.
1) LED
A Light Emitting Diode (LED) is a semiconductor device, which can emit light when an electric
current passes through it. To do this, holes from p-type semiconductors recombine with electrons from
n-type semiconductors to produce light.
Figure 1.5. LED pin diagram
2) Pushbutton
A pushbutton is one kind of switch, a mechanical device that connects or breaks a circuit. The surface
of a pushbutton switch can be either flat or a shape that you can quickly press or depress with your
finger. Furthermore, try not to confuse push button switches with regular switches. While switches
have permanent on and off positions, pushbuttons only have temporary on and off functions. Also,
when you press a pushbutton switch, it stays in that depressed state until you press it again to release
it. One in input button and one is output. Out of two one is for ground. They are internally connected
with pair of 2.
3) Relay SPDT
A single-pole double-throw (SPDT) relay has one pole and two throws. Based on the default position
of the pole, one throw is considered normally open (NO) while the other is normally closed (NC).
Most relay modules (whether 5V or 12V) will come with the aforementioned connection and hence
all you need is to give power supply to the relay module i.e. 5V and GND and connect the control
signal from Arduino to control pin on the relay board.
4) Motor Drivers
78M05 Voltage regulator will be enabled only when the jumper is placed. When the power supply is
less than or equal to 12V, then the internal circuitry will be powered by the voltage regulator and the
5V pin can be used as an output pin to power the microcontroller. The jumper should not be placed
when the power supply is greater than 12V and separate 5V should be given through 5V terminal to
power the internal circuitry. ENA & ENB pins are speed control pins for Motor A and Motor B
while IN1& IN2 and IN3 & IN4 are direction control pins for Motor A and Motor B.
VCC pin supplies power to the motor. Voltage anywhere between 5 to 35V can be applied. Remember, if
the 5V-EN jumper is in place, you need to supply 2 extra volts than the motor’s actual voltage requirement,
in order to run the motor at its maximum speed.
GND is the common ground pin.
5V pin supplies power to the switching logic circuitry inside the L298N IC. If the 5V-EN jumper is in
place, this pin acts as output and can be used to power up the Arduino. If the 5V-EN jumper is removed,
you need to connect it to the 5V pin on Arduino.
ENA pins are utilized to control the speed of Motor A. Supplying this pin with HIGH logic makes the
Motor A rotate, supplying it with LOW logic causes the motor to stop. Removing the jumper and
connecting this pin to the PWM input let us control the speed of the Motor A.
IN1 & IN2 pins are used to control the direction of Motor A. If IN1 is HIGH and IN2 is LOW, Motor A
spins in a certain direction. To change the direction, make IN1 LOW and IN2 HIGH. If both the inputs
are either HIGH or LOW, the Motor A stops.
IN3 & IN4 pins are used to control the direction of the Motor B. If IN3 is HIGH and IN4 is LOW,
Motor B spins in a certain direction. To change the direction, make IN3 LOW and IN4 HIGH. If both the
inputs are either HIGH or LOW, the Motor B stops.
ENB pin can be used to control the speed of Motor B. Supplying this pin with the HIGH signal makes the
Motor B turn, supplying it LOW cause the motor to stop. Eliminating the jumper and interfacing this pin
to PWM information let us control the speed of Motor B.
Aim: To interface LED with Arduino and write a program to turn ON/OFF LED.
Theory:
LED stands for Light Emitting Diode. It is a semiconductor device that emits light when an electric current
is passed through it. LEDs are commonly used in various applications, such as electronic displays,
lighting, and indicators. LEDs have several advantages over traditional light sources, such as incandescent
bulbs and fluorescent lamps, including lower energy consumption, longer lifespan, and smaller size. LEDs
can emit light in different colors, depending on the material used in the semiconductor. LED technology
has advanced rapidly in recent years, and LEDs are now widely used in many products, including
smartphones, TVs, and automobiles.
Text Code:
void setup()
{
pinMode(13, OUTPUT);
}
void loop()
{
digitalWrite(13, HIGH);
delay(1000); // Wait for 1000 millisecond(s)
digitalWrite(13, LOW);
delay(1000); // Wait for 1000 millisecond(s)
}
Block Code:
Output:
Aim: To interface Push Button with Arduino and write a program to turn ON LED when push button
is pressed.
Components Required: Arduino UNO, LED, Resistor, Push button, Connecting wires.
Theory:
A Push Button is a type of switch work on a simple mechanism called “Push-to-make”. Initially, it remains
in off state or normally open state but when it is pressed, it allows the current to pass through it or we can
say it makes the circuit when pressed. Push Button structure has four legs, two on one side and other two
on another side. So, we can operate two lines of the circuit by single Push Button.
Text Code:
int button = 0;
void setup()
{
pinMode(6, INPUT);
Serial.begin(9600);
pinMode(13, OUTPUT);
}
void loop()
{
button = digitalRead(6);
Serial.println(button);
if (button == 1) {
digitalWrite(13, HIGH);
} else {
digitalWrite(13, LOW);
}
delay(10); // Delay a little bit to improve simulation performance
}
Block Code:
Output:
Aim: To interface push button using relay with Arduino and write a program to turn ON the bulb when
push button is pressed.
Components Required: Arduino UNO, Bulb, Power Supply, Relay, Push button, Resistor,
Connecting Wires.
Theory:
A relay is an electrically operated switch. It consists of a set of input terminals for single or multiple
control signals, and a set of operating contact terminals. The switch may have any number of contacts in
multiple contact forms, such as make contacts, break contacts, or combinations thereof.
Relays are used where it is necessary to control a circuit by an independent low-power signal, or where
several circuits must be controlled by one signal. Relays were first used in long-distance telegraph circuits
as signal repeaters: they refresh the signal coming in from one circuit by transmitting it on another circuit.
Relays were used extensively in telephone exchanges and early computers to perform logical operations.
Text Code:
int button = 0;
void setup()
{
pinMode(4, INPUT);
Serial.begin(9600);
pinMode(2, OUTPUT);
}
void loop()
{
button = digitalRead(4);
Serial.println(button);
if (button == 1) {
digitalWrite(2, HIGH);
} else {
digitalWrite(2, LOW);
}
delay(10); // Delay a little bit to improve simulation performance
}
Block Code:
Output:
Aim: To interface ultrasonic sensor with Arduino and write a program to turn ON LED when the
distance is less than 100 cm.
Components Required: Arduino UNO, Ultrasonic sensor, LED, Resistor, Connecting Wires.
Theory:
Ultrasonic Sensor HC-SR 04. Actually it consist of an ultrasonic transmitter and an ultrasonic reciver.
First ultrasonic transmitter send an ultrasonic wave. This signal will collide with the object and reflect the
signal. The receiver will receive the reflected signal. The distance calculated by the time taken to receive
the reflected. and the speed of sound in air. The speed of sound in air at room temperature is 340
Meter/Second or 0.034 centimeter/microsecond. The equation for calculating time is,
Time=Distance/speed of sound
If the object is 10 CM away from the sensor, We will get the time as per the equation is, 10/0.034 =
294.11 Microseconds.
But we will get the value from the Echo pin is 588.22. This is because of the sound wave needs to travel
forward and bounce backward. So we need to divide that value by 2 for get the actual value(time). Here
we want to calculate the distance from the time. So re-arrange the equation we will get,
Text Code:
int dist = 0;
void setup()
{
pinMode(13, OUTPUT);
}
void loop()
{
dist = 0.01723 * readUltrasonicDistance(8, 7);
if (dist < 100) {
digitalWrite(13, HIGH);
} else {
digitalWrite(13, LOW);
}
delay(10); // Delay a little bit to improve simulation performance
}
Block Code:
Output:
LED is glowing successfully when ultrasonic sensor reads less than 100cm.
EXPERIMENT NO. - 06
Aim: To interface Ultrasonic sensor using relay with Arduino and write a program to turn the bulb
ON/OFF as per the distance measured by sensor.
Components Required: Arduino UNO, Ultrasonic sensor, Relay, power supply, bulb, connecting
wires.
Theory:
Ultrasonic Sensor HC-SR 04. Actually it consist of an ultrasonic transmitter and an ultrasonic reciver.
First ultrasonic transmitter send an ultrasonic wave. This signal will collide with the object and reflect the
signal. The receiver will receive the reflected signal. The distance calculated by the time taken to receive
the reflected. and the speed of sound in air. The speed of sound in air at room temperature is 340
Meter/Second or 0.034 centimeter/microsecond. The equation for calculating time is,
Time=Distance/speed of sound
If the object is 10 CM away from the sensor, We will get the time as per the equation is, 10/0.034 =
294.11 Microseconds.
But we will get the value from the Echo pin is 588.22. This is because of the sound wave needs to travel
forward and bounce backward. So we need to divide that value by 2 for get the actual value(time). Here
we want to calculate the distance from the time. So re-arrange the equation we will get,
Text Code:
//C++ Code
int dist = 0;
void setup()
{
Serial.begin(9600);
pinMode(4, OUTPUT);
}
void loop()
{
dist = 0.01723 * readUltrasonicDistance(8, 7);
Serial.println(dist);
if (dist < 100) {
digitalWrite(4, HIGH);
} else {
digitalWrite(4, LOW);
}
delay(10); // Delay a little bit to improve simulation performance
}
Block Code:
Output:
The bulb is glowing successfully when ultrasonic sensor reads distance less than 100 cm.
EXPERIMENT NO. - 07
Aim: To interface temperature sensor with Arduino and write a program to turn ON/OFF the LED
when temperature sensor data is above 50 C.
Theory:
A temperature sensor is a device that measures the temperature of a system or environment. Temperature
sensors are used in a wide range of applications, including industrial processes, environmental monitoring,
medical equipment, and consumer electronics.
There are several types of temperature sensors, including thermocouples, resistance temperature detectors
(RTDs), thermistors, and infrared sensors. Each type of sensor has its own advantages and disadvantages,
and is suitable for different applications.
Text Code:
int temp = 0;
void setup()
{
pinMode(A0, INPUT);
Serial.begin(9600);
pinMode(13, OUTPUT);
}
void loop()
{
Serial.println((-40 + 0.488155 * (analogRead(A0) - 20)));
temp = (-40 + 0.488155 * (analogRead(A0) - 20));
if (temp < 50) {
digitalWrite(13, LOW);
} else {
digitalWrite(13, HIGH);
}
delay(10); // Delay a little bit to improve simulation performance
}
Block Code:
Output:
Led is glowing successfully when the temperature sensed by the sensor is above 50 degree celcius.
EXPERIMENT NO. - 08
Aim: To interface motor using motor driver with Arduino and write a program to turn the motor
clockwise and anti-clockwise.
Theory:
A DC motor is a device that converts electrical energy into mechanical energy. It has two wires, positive
and negative, that can be connected to a power source. When the power source is connected, the motor
rotates. The direction of rotation depends on the polarity of the power source. If the positive wire is
connected to the positive terminal of the power source, and the negative wire to the negative terminal, the
motor rotates in one direction (clockwise or anticlockwise). If the wires are swapped, the motor rotates in
the opposite direction.
To control the speed and direction of a DC motor using an Arduino, we need a driver circuit that can
amplify the signals from the Arduino and switch the polarity of the power source. One such driver
circuit is the L298N module, which can control two DC motors simultaneously. The L298N module has
four input pins (IN1, IN2, IN3, IN4) and four output pins (OUT1, OUT2, OUT3, OUT4) for each motor.
It also has two enable pins (ENA and ENB) that can be used to control the speed of each motor using
PWM signals from the Arduino.
Text Code:
void setup()
{
pinMode(6, OUTPUT);
pinMode(7, OUTPUT);
}
void loop()
{
digitalWrite(6, HIGH);
digitalWrite(7, LOW);
delay(20); // Wait for 20 millisecond(s)
digitalWrite(6, LOW);
digitalWrite(7, HIGH);
}
Block Code:
Output: