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

Ardunio Programming and Tinkercad

Uploaded by

bodepuvedavyas
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)
26 views

Ardunio Programming and Tinkercad

Uploaded by

bodepuvedavyas
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/ 92

How to Write a code in

ARDUINO IDE
INDEX OF CONTENTS

• Demonstration of setup()
• Demonstration of loop()
• Demonstration of pinMode()
• Demonstration of digitalWrite()
• Demonstration of digitalRead()
• Demonstration of analogWrite()
• Demonstration of analogRead()
Basic Syntaxes

• Setup:
– First and one-time Execution
– Configure Arduino

Syntax:
void setup()
{
………………………….
………………………….
}
Contd…

• Loop:
– After setup() executes
– Infinite Loop

Syntax:
void loop()
{
……………………………….
……………………………….
}
Contd…
• pinMode():
– Intimating Arduino about the peripheral
– Two Arguments, No Return Variable

Syntax:
pinMode(pin, status);
pin: Pin Number
status: INPUT or OUTPUT
Evaluating pinMode()
• Analog Peripheral connected at Pin A2, and it is O/P
– pinMode(A2, OUTPUT);
• Digital Peripheral connected at Pin 3, and it is O/P
– pinMode(3, OUTPUT);
• Analog Peripheral connected at Pin A1, and it is I/P
– pinMode(A1, INPUT);
• Digital Peripheral connected at Pin 0, and it is I/P
– pinMode(0, INPUT);
Note: pinMode() should be written in
setup() as it is configuration bit
GPIO BLOCK
• Input: Analog / Digital
• Output: Analog / Digital

• Read: Input
• Write: Output
digitalWrite()
• Connected Peripheral: Digital
• Status: Output
• Number of Arguments: 2
• Number of Return Variables: 0

Syntax:
digitalWrite(pin, data);
pin: To which pin, you need to write
data: What you need to write (HIGH/LOW)
analogWrite()
• Connected Peripheral: Analog
• Status: Output
• Number of Arguments: 2
• Number of Return Variables: 0

Syntax:
analogWrite(pin, data);
pin: To which pin, you need to write
data: What you need to write (0 to 1023)
digitalRead()
• Connected Peripheral: Digital
• Status: Input
• Number of Arguments: 1
• Number of Return Variables: 1

Syntax:
bit n;
n=digitalRead(pin);
pin: From which pin, you need to read
n value may be 0 or 1
analogRead()
• Connected Peripheral: Analog
• Status: Input
• Number of Arguments: 1
• Number of Return Variables: 1

Syntax:
int n;
n=analogRead(pin);
pin: From which pin, you need to read
n value lies in between 0 to 1023
Arduino
Simulator
• The Arduino simulator is a virtual portrayal of
the circuits of Arduino in the real world.
• We can create many projects using a simulator
without the need for any hardware.
• The Simulator helps beginner and professional
designers to learn, program, and create their
projects without wasting time on collecting
hardware equipment's.
Types of Simulator
There are various simulators available. Some are
available for free, while some require a license to
access the simulators.
Some types of simulators are listed below:
• Autodesk Tinkercad
• Emulator Arduino Simulator
• Autodesk Eagle
• Proteus Simulator
• Virtronics Arduino Simulator
• ArduinoSim
• Here, we are using the Autodesk
Tinkercad Simulator.
1. Open the official website of tinkercad.
URL: https://www.tinkercad.com/
2. Click on the ‘LOG IN' option, if you have an
account in Autodesk. Otherwise, click on the ‘SIGN
UP' option if you don't have an account.
Now, a window will appear, as shown below:
Click on “ + New “ Option on the right to start
designing the Arduino circuit
or
Click on option – “create your first Circuits design”
We are now ready to start with the Autodesk
Tinkercad.
We can start creating our projects.
A window will appear.
We need to drag and drop the desired components
in the project screen. It is shown below:
•Click on the drop list of components and select the 'All' option.
The drop list will appear as:

Click on the drop list of components and select the


'All' option.
The drop list will appear as:
Select the 'Text'
instead of block
view, as shown
below:
It also displays the error in the code, if any.

Click on 'Start Simulation' to upload the


code on the board.
Serial Monitor
The serial monitor is present on the bottom of
the coding screen.
It will look like the below image:

INDEX OF CONTENTS
Interfacing LED and Blinking an LED –
Digital Output
• Interfacing Switch or Button – Digital Input
• Interfacing LED – Analog Output
• Interfacing LDR – Analog Input
LED PROGRAMS
Interface LED Cathode to a digital Pin

• Program – 1: GLOW LED


• Program – 2: BLINK LED
Light Emitting Diode (LED)
• It is a semiconductor device that emits light when an electric current flows
through it.
• When current passes through an LED, the electrons recombine with holes
emitting light in the process.
• LEDs allow the current to flow in the forward direction and blocks the current
in the reverse direction.
LED Symbol
• The LED symbol is the standard
symbol for a diode, with the addition
of two small arrows denoting the
emission of light.

Simple LED Circuit


• The circuit consists of an LED, a
voltage supply and a resistor to
regulate the current and voltage.
How does an LED work?
• LEDs work on the principle
of Electroluminescence.
• On passing a current through
the diode, minority charge
carriers and majority charge
carriers recombine at the
junction.
• On recombination, energy is
released in the form of
photons.
• As the forward voltage
increases, the intensity of the
light increases and reaches a
maximum.
HARDWARE CIRCUITRY
Circuit Analysis
• When ARDUINO pin is HIGH:
– LED will be ON [ANODE POT > CATHODE POT]

• When ARDUINO pin is LOW:


– LED will be OFF [ANODE POT<CATHODE POT]
Program for LED:
void setup()
{
pinMode(pin,OUTPUT);
}

void loop()
{
digitalWrite(pin,HIGH); // LED ON
}
Program for Blinking an LED:

#define pin 7 void loop()


{
void setup() // LED on
{ digitalWrite(pin,HIGH);
pinMode(pin,OUTPUT); delay(1000);
}
// LED off
digitalWrite(pin,LOW);
delay(1000);
}
Interfacing Analog LED
HARDWARE CIRCUITRY
Circuit Analysis
• Connect LED at Pin A2
• Vary the value from 0 to 255

• Demonstration of Analog Output


• Brightness of LED will be varied
Analog LED Programs
• Connect LED at Pin A2

• Program – 1 : Fade LED


RGB Blinking LED

• RGB LEDs consist of three LEDs: Red, Green and Blue.


• These three colored LEDs are capable of producing any color.
• Tri-color LEDs with red, green, and blue emitters, in general using a
four-wire connection with one common lead (anode or cathode).
INTERFACING SWITCH
OR BUTTON WITH LED
Push Button Switch

• Push Buttons are normally-open tactile switches.


• Push buttons allow us to power the circuit or make any particular connection
only when we press the button.
• Simply, it makes the circuit connected when pressed and breaks when released.
• A push button is also used for triggering of the SCR by gate terminal.
HARDWARE CIRCUITRY
SWITCH PROGRAMS
• Interface Switch to Pin 2
• Interface LED to Pin 7

• Program – 1: Switch LED


Program for interfacing button with LED:

#define led 7 void loop()


#define button 2 {
s = digitalRead(button);
int s; if(s == 1)
{
void setup() digitalWrite(led,LOW);
{ }
pinMode(led,OUTPUT); else if(s == 0)
pinMode(button,INPUT); {
} digitalWrite(led,HIGH);
}
}
Buzzer
• An audio signaling device like a beeper or
buzzer may be Electromechanical or
Piezoelectric or Mechanical Type.
• The main function of this is to convert the signal
from Audio To Sound.
• Generally, it is powered through DC voltage and
used in timers, alarm devices, printers, alarms,
computers, etc.
• Based on the various designs, it can generate
different sounds like alarm, music, bell & siren.
Specifications
The specifications of the buzzer include the following.

• Color is black
• The frequency range is 3,300Hz
• Operating Temperature ranges from – 20° C to +60°C
• Operating voltage ranges from 3V to 24V DC
• The sound pressure level is 85dBA or 10cm
• The supply current is below 15mA
Types of Buzzer
A buzzer is available in different types which include the following.

1. Piezoelectric
2. Electromagnetic
3. Mechanical
4. Electromechanical
5. Magnetic
Working Principle

➢ The working principle of a buzzer depends on


the theory that, once the voltage is given across
a piezoelectric material, then a pressure
difference is produced.
➢ A piezo type includes piezo crystals among two
conductors.
➢ Once a potential disparity is given across these
crystals, then they thrust one conductor & drag
the additional conductor through their internal
property.
➢ So this continuous action will produce a sharp
sound signal.
Sensors and Actuators
Sensor
• Sensor is a device used for the conversion of physical events or
characteristics into the electrical signals.
• This is a hardware device that takes the input from environment
and gives to the system by converting it.
• For example, a thermometer takes the temperature as physical
characteristic and then converts it into electrical signals for the
system.
Actuator
• Actuator is a device that converts the electrical signals into the
physical events or characteristics.
• It takes the input from the system and gives output to the
environment.
• For example, motors and heaters are some of the commonly used
actuators.
Head-to-head comparison between Sensors and Actuators
Features Sensors Actuators

Definition It is a device that detects changes or events in the It is a machine component that moves and controls
environment and transmits that data to another mechanisms.
electronic system.

Basic It converts the physical properties of their It converts the system's electrical signals into
environment into electrical signals for the various physical characteristics for their
system. environments.

Type of Output Electrical signals are generated via sensors. It generates energy in the form of heat or motion.

Source of Input It receives input from the environment. It receives input from the system's output
conditioning unit.

Placement These are placed at a system's input port. These are placed at a system's output port.

Output Generation It produces output for the input conditioning unit It produces output for their environment.
of a system.
Examples Sensors include biosensors, motion sensors, Actuators include electric motors, comb drives,
image sensors, and chemical sensors. stepper motors, and hydraulic cylinders.
Sensors And Actuators in IIoT
• Sensors and actuators are vital pieces of connected technology within
the Industrial Internet of Things (IIoT).
• They are designed to collect and analyze vast amounts of data to help
find ways to streamline operations and improve productivity.
• IIoT systems rely heavily on sensors and actuators to operate.
• Sensors are used to monitor processes and equipment to provide data on
how the systems are functioning.
• Actuators are used within IIoT systems to perform certain mundane or
routine actions on equipment to improve process efficiencies.
• One of the best examples of how sensors and actuators can work
together within IIoT systems is robotic arms in manufacturing plants.
LM35 - Temperature Sensor
LM35 - Temperature Sensor
➢ The LM35 is a low-power, low-cost, high-precision temperature sensor designed
and manufactured by Texas instruments.
➢ This IC provides a voltage output that is linearly proportional to the change in
temperature.
➢ The LM35 sensor is moderately precise and its robust construction makes it
suitable for various environmental conditions. Additionally, you don't need any
external component to calibrate this circuit and it has a typical accuracy of
±0.5°C at room temperature and ±1°C over a full −55°C to +155°C temperature
range. It has an operating voltage of 4V to 30V and consumes 60-uA current
while it's in working state, this also makes it perfect for battery-powered
applications.
➢ There are two disadvantages of this sensor. The first big disadvantage of this
sensor is that it cannot measure negative temperature, for that you have to bias it
with a dual polarity supply. If your project requires negative temperature
measurements, you can opt for a LM36 sensor. The second disadvantage of this
sensor is that it's very sensitive to noise because it outputs data in analog format.
Interfacing LDR
LDR or Light Dependent Resistor or
Photo Resistor or Photocell or
Photoconductor
➢ It is a one type of resistor whose resistance varies
depending on the amount of light falling on its surface.
➢ When the light falls on the resistor, then the resistance
changes.
➢ These resistors are often used in many circuits where it
is required to sense the presence of light.
➢ These resistors have a variety of functions and
resistance.
➢ A typical light dependent resistor has a resistance in the
darkness of 1MOhm, and in the brightness a resistance
of a couple of KOhm
HARDWARE CIRCUITRY
LDR Programs
• Connect LED at Pin A2
• Connect LDR at Pin A0

• Program – 1 : Fade LED according to LDR


Interfacing L293D
ELECTRICAL MOTORS
• Electrical Motor.
• Types of Electrical Motor.
– DC Gear Motor
– DC Stepper Motor
– DC Servo Motor
• Each motor can drive 3 actions.
– Clockwise
– Anti Clockwise
– Stop
WHAT IS L293D?
• Drive Electrical Motors
• Current Amplifier
• The IC works on the
principle of Half H-Bridge

• EN1, EN2: Controls


• 1A, 2A, 3A, 4A: Inputs
• 1Y, 2Y, 3Y, 4Y: Outputs
LCD 16 X 2
Features of LCD16x2
The features of this LCD mainly include the following.
• The operating voltage of this LCD is 4.7V-5.3V
• It includes two rows where each row can produce
16-characters.
• The utilization of current is 1mA with no backlight
• Every character can be built with a 5×8 pixel box
• The alphanumeric LCDs alphabets & numbers
• Is display can work on two modes like 4-bit & 8-bit
• These are obtainable in Blue & Green Backlight
• It displays a few custom generated characters
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 state of these pins (high or low) is the bits that you're writing to a register when you write, or
the values when you read.
• There are also a display contrast 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 or 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 Liquid Crystal 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.
• A potentiometer, informally a pot, is a three-terminal resistor with a sliding or rotating contact that forms an adjustable
voltage divider. If only two terminals are used, one end and the wiper, it acts as a variable resistor.
Registers of LCD
• A 16×2 LCD has two registers like data register and command
register. The RS (register select) is mainly used to change from one
register to another. When the register set is ‘0’, then it is known as
command register. Similarly, when the register set is ‘1’, then it is
known as data register.
Command Register
• The main function of the command register is to store the instructions
of command which are given to the display. So that predefined tasks
can be performed such as clearing the display, initializing, set the
cursor place, and display control. Here commands processing can
occur within the register.
Data Register
• The main function of the data register is to store the information
which is to be exhibited on the LCD screen. Here, the ASCII value of
the character is the information which is to be exhibited on the screen
of LCD. Whenever we send the information to LCD, it transmits to
the data register, and then the process will be starting there. When
register set =1, then the data register will be selected.
Servo Motor
Servo Motor
• It is defined as an electric motor that
allows for precise control of angular or
linear position, speed, and torque.
• It consists of a suitable motor coupled to
a sensor for position feedback and a
controller that regulates the motor’s
movement according to a desired set
point.
• Servo motors are widely used in
industrial applications such as robotics,
CNC machinery, and automated
manufacturing, where high accuracy, fast
response, and smooth motion are
required.
A servo motor consists of three main components:

• A motor: This can be either a DC Motor or an AC motor depending on


the power source and the application requirements. The motor provides the
mechanical power to rotate or move the output shaft.

• A sensor: This can be either a Potentiometer, an encoder, a resolver, or


another device that measures the position, speed, or torque of the output shaft
and sends feedback signals to the controller.

• A controller: This can be either an analog or a digital circuit that


compares the feedback signals from the sensor with the desired setpoint signals
from an external source (such as a computer or a joystick) and generates control
signals to adjust the motor’s voltage or current accordingly.
How Does a Servo Motor Work?
The basic working principle of a servo motor
involves the controller receiving two types of input
signals:
• A setpoint signal: This is an analog or digital
signal that represents the desired position, speed,
or torque of the output shaft.
• A feedback signal: This is an analog or digital
signal that represents the actual position, speed, or
torque of the output shaft measured by the sensor.
How to Control a Servo Motor?
Generally, there are two types of control signals that can be used to
control a servo motor: analog and digital.
• Analog control signals are continuous voltage or current signals
that vary proportionally to the desired setpoint. They are typically
used for simple or low-cost servo systems that do not require high
accuracy or resolution. For example, a potentiometer can be used
to generate an analog control signal for a hobby servo motor.
• Digital control signals are discrete pulses or bits that represent
the desired setpoint in a coded form. They are typically used for
complex or high-performance servo systems that require high
accuracy, resolution, or communication. For example, a pulse-
width modulation (PWM) signal can be used to generate a digital
control signal for a brushless DC servo motor.
Ultrasonic Sensor - HC-SR04

FEATURES
Power Supply :+5V DC
OF HC-SR04
• Quiescent Current : <2mA
• Working Current: 15mA
• Effectual Angle: <15°
• Ranging Distance : 2cm – 400 cm/1″ – 13ft
• Resolution : 0.3 cm
• Measuring Angle: 30 degree
• Trigger Input Pulse width: 10uS
• Dimension: 45mm x 20mm x 15mm
WHAT IS ULTRASONIC SENSOR
?
• An Ultrasonic sensor is a device that can measure
the distance to an object by using sound waves.
• It measures distance by sending out a sound wave
at a specific frequency and listening for that sound
wave to bounce back.
• By recording the elapsed time between the sound
wave being generated and the sound wave
bouncing back, it is possible to calculate the
distance between the sonar sensor and the object.
WHAT IS HC-
• SR04
On the front ?cylinders - Transducers.
are two metal
• Transducers convert mechanical forces into electrical signals.
• In the ultrasonic range finder, there is a transmitting transducer and receiving
transducer.
• The transmitting transducer converts an electrical signal into the ultrasonic pulse,
and the receiving transducer converts the reflected ultrasonic pulse back into an
electrical signal.
• If you look at the back of the range finder, you will see an IC behind the
transmitting transducer labelled MAX3232.
• This is the IC that controls the transmitting transducer.
• Behind the receiving transducer is an IC labelled LM324.
• This is a quad Op-Amp that amplifies the signal generated by the receiving
transducer into a signal that’s strong enough to transmit.
TIMING DIAGRAM

• To start measurement, Trig of SR04


must receive a pulse of high (5V) for at
least 10us, this will initiate the sensor
will transmit out 8 cycle of ultrasonic
burst at 40kHz and wait for the reflected
ultrasonic burst.
• When the sensor detected ultrasonic
from receiver, it will set the Echo pin to
high (5V) and delay for a period (width)
which proportion to distance.
• To obtain the distance, measure the
width (Ton) of Echo pin.
From
K Pranay Navyakranth
IoT Trainer
From
K Pranay Navyakranth
IoT Trainer

You might also like