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

Arduino2

Uploaded by

Vinod KS
Copyright
© © All Rights Reserved
Available Formats
Download as PPTX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
4 views

Arduino2

Uploaded by

Vinod KS
Copyright
© © All Rights Reserved
Available Formats
Download as PPTX, PDF, TXT or read online on Scribd
You are on page 1/ 27

ARDUINO -

INTRODUCTION
WHAT IS ARDUINO?

• Development board
• Programmable micro processor (Microcontroller)
• (Digital) Electronics
• Open source
• Read inputs, control outputs!
WHAT CAN YOU DO WITH ARDUINO?

• Read inputs • And turn it into an output


• A finger on a button • Turning on a LED
• Light on a sensor • Activating a motor
• Temperature in a room • Text on a display
• Data over communication bus • Calculating / Processing
• Or a Twitter message • Publishing something online
• More! • More!
THE SHORT ARDUINO PROJECT FOR TODAY!

• Turn a potentiometer to a certain position (Input)


• Can become anything other analog input… (sensor) Another
time!
• More in’s and out’s… Another time!

• Make the servo turn to a certain position (Output)


• With Arduino!
AGENDA

Theory: Hands-on:
1. What is a potentiometer? 5. Wiring on the breadboard!
2. What is a servomotor? 6. Programming the Arduino!
3. Signalling a servomotor 7. Testing!
4. How should the program work?
THEORY
1. What is a potentiometer?
2. What is a servomotor?
3. Signalling a servomotor
4. How should the program work?
1. WHAT IS A POTENTIOMETER?

• It’s a resistor!
(Acts like a normal transistor between pins 1 and 3)
• With a variable resistance by turning the ‘wiper’.
(Connected to pin 2)
• Position can be read as a variable analog voltage.
(If used with one of the analog input pins)
1. WHAT IS A POTENTIOMETER?

• Reading with Arduino’s ‘analogRead’ function.


• Reads value of somewhere between 0 and 5V.
• Returns an integer value between 0 and 1023.
• Yields a resolution between readings of:
5 volts / 1024,
or: 0.0049 volts (4.9 mV).
2. WHAT IS A SERVOMOTOR?

• It’s a motor!
• Not a typical DC motor (that’s either ON or OFF, at a
certain speed)
• Not a stepper motor (That turns a step for each pulse)

• It’s a motor that turns to a certain position.


• Controlled by modulating the on-time of a signal.
• So the width of a pulse controls the position of the
servo. Three wires to connect:
1. Power (Red)
• Typically operating range is between 0° and 180°,
2. Signal
where 90° is default.
(Yellow/Orange)
3. Ground (Black/Brown)
3. SIGNALLING A SERVO MOTOR

• PPM stands for Pulse-Position


Modulation.
• Time frame for a servo PPM signal
is typically 20ms. (50Hz Signal)
• On-time determines position.
(See image on the right)
3. SIGNALLING A SERVO MOTOR:
COMMON MISCONCEPTION

• Signal is often referred to as ‘Pulse-


Width Modulation’ by manufacturers
(Because it is).
• Causes the misconception that
Arduino’s PWM may be used to drive
the servo.
• Don’t use Arduino’s PWM (analogWrite),
because the PWM frequency of this
signal is 490Hz, not 50Hz.
• (This is why the Servo library exists!)
4. WHAT SHOULD THE PROGRAM DO?

1. Setup and initialize (standard step in


Arduino programming)
2. Read the analog voltage value of the
potentiometer.
3. Translate the read value, into a position
for the servo motor.
4. Signal the servo motor to go to that
position.
5. Wait for the servo motor to position itself
there.
6. Do it all again, starting from step 2.
(Loop)
HANDS ON!
5. Wiring on the breadboard!
6. Programming the Arduino!
7. Testing!
5. WIRING THE ARDUINO!
6. PROGRAMMING

• Start Arduino IDE


• Make a new sketch
• Go to: File  New
6. PROGRAMMING

• Select the right board


• Go to: Tools  Board 
Arduino/Genuino Uno

• Select the right port


• Go to: Tools  Port  (Your com
port)
6. PROGRAMMING

Will be using the servo library.


• Include the servo library by:
• Going to:
‘Sketch’,
‘Include Library’,
‘Servo’.
6. PROGRAMMING

Will be using the servo library.


• Or include the servo library by:
• Typing the following instruction:
#include <Servo.h>
• Insert it above the function:
void setup() {
6. PROGRAMMING

Using servo and variables:


• Make an object for your servo
• Make variables for:
The pin used by the pot-meter,
The pin used by the servo,
For storing the read value in.
• Insert it above the function:
void setup() {
6. PROGRAMMING

Setting up the servo:


• Typing the following instruction in
between the { and } of ‘void
setup()’:
myservo.attach(servoPin);
6. PROGRAMMING

Reading the analog value of the


potentio meter:
• By using Arduino’s ‘analogRead’
function for your pin.
• Storing the read value in your
variable ‘val’.
6. PROGRAMMING

Calculating the position with respect


to a 0 to 180 degrees scale.
• By using Arduino’s ‘map’ function.
(Conversion table function)
• Storing the new translated value
in ‘val’.
6. PROGRAMMING

Signalling the servo to the


calculated position
• By using the write function from
the servo library.
• Using the calculated value ‘val’.
6. PROGRAMMING

Almost done!
• Add a delay in which the servo has
time to move from position A to
position B! (15 miliseconds)
3. TESTING: TIME TO UPLOAD
3. TESTING

• NO NEED TO SAVE!!
• DOES IT WORK!?
• IF (YES)
Yay! You made your first Arduino Project!
• IF (NO)
No problem, let us help you!
QUESTIONS?

You might also like