24
EXPERIMENT : Programing a microcontroller - Microcontroller : basic programing - Sensor interfacing - Motor control : DC Motor, DC servo, etc. - Encoder interfacing

EXPERIMENT : Programing a microcontroller ... · •Arduino directly can provide only 40mA of current within an max of 5V output which is insufficient to rotate the motor. So we need

  • Upload
    others

  • View
    4

  • Download
    0

Embed Size (px)

Citation preview

Page 1: EXPERIMENT : Programing a microcontroller ... · •Arduino directly can provide only 40mA of current within an max of 5V output which is insufficient to rotate the motor. So we need

Parikshit Saha IIT Kanpur

EXPERIMENT : Programing a microcontroller

- Microcontroller : basic programing

- Sensor interfacing

- Motor control : DC Motor, DC servo, etc.

- Encoder interfacing

Page 2: EXPERIMENT : Programing a microcontroller ... · •Arduino directly can provide only 40mA of current within an max of 5V output which is insufficient to rotate the motor. So we need

Parikshit Saha IIT Kanpur

What is Arduino ? • Arduino is an open-source hardware which consists of ATMEL

microcontroller (ATmega 16/32) based programmable circuit board

and a easy to use Software IDE (Integrated Development

Environment) that runs on a computer.

Page 3: EXPERIMENT : Programing a microcontroller ... · •Arduino directly can provide only 40mA of current within an max of 5V output which is insufficient to rotate the motor. So we need

Parikshit Saha IIT Kanpur

Arduino Pin Diagram

Page 4: EXPERIMENT : Programing a microcontroller ... · •Arduino directly can provide only 40mA of current within an max of 5V output which is insufficient to rotate the motor. So we need

Parikshit Saha IIT Kanpur

Programing details: Port Pin Data Directionality

• Input

• When you want to take information from the external world (sensors) into the MCU

• Output

• When you want to change the state of something outside the MCU (turn a motor on or off, etc.)

• Pins default to input direction on power-up or reset

• Your program can set or change the directionality of a pin at any time

Page 5: EXPERIMENT : Programing a microcontroller ... · •Arduino directly can provide only 40mA of current within an max of 5V output which is insufficient to rotate the motor. So we need

Parikshit Saha IIT Kanpur

Pin Voltages

• Microcontrollers are fundamentally digital devices

• Information is ‘coded’ in two discrete states:

• HIGH or LOW (logic: 1 or 0)

• Voltages

• TTL • 5 V (for HIGH)

• 0 V (for LOW)

• 3.3 V CMOS

• 3.3 V (for HIGH)

• 0 V (for LOW)

Page 6: EXPERIMENT : Programing a microcontroller ... · •Arduino directly can provide only 40mA of current within an max of 5V output which is insufficient to rotate the motor. So we need

Parikshit Saha IIT Kanpur

Digital I/0 Syntax pinMode(pin, mode)

Sets pin to either INPUT or OUTPUT

digitalRead(pin) Reads HIGH or LOW from a pin

digitalWrite(pin, value) Writes HIGH or LOW to a pin (1 or 0)

analogRead(Pin)

analogWrite(Pin, Value), Value is between 0 to 255

Page 7: EXPERIMENT : Programing a microcontroller ... · •Arduino directly can provide only 40mA of current within an max of 5V output which is insufficient to rotate the motor. So we need

Parikshit Saha IIT Kanpur

Arduino Basic Coding Structure

<define global variables and include header files here> void setup() {

< executed only once>

< define input/output mode for digital pins > } void loop() {

<infinite loop>

<things like input from sensors, sending output etc. > }

Page 8: EXPERIMENT : Programing a microcontroller ... · •Arduino directly can provide only 40mA of current within an max of 5V output which is insufficient to rotate the motor. So we need

Parikshit Saha IIT Kanpur

LED blink Arduino Demo

Page 9: EXPERIMENT : Programing a microcontroller ... · •Arduino directly can provide only 40mA of current within an max of 5V output which is insufficient to rotate the motor. So we need

Parikshit Saha IIT Kanpur

Two colour LED glow – Arduino Demo

Page 10: EXPERIMENT : Programing a microcontroller ... · •Arduino directly can provide only 40mA of current within an max of 5V output which is insufficient to rotate the motor. So we need

Parikshit Saha IIT Kanpur

Hall Sensor Interfacing

Page 11: EXPERIMENT : Programing a microcontroller ... · •Arduino directly can provide only 40mA of current within an max of 5V output which is insufficient to rotate the motor. So we need

Parikshit Saha IIT Kanpur

Motor Interfacing with Arduino

By Parikshit Saha

Page 12: EXPERIMENT : Programing a microcontroller ... · •Arduino directly can provide only 40mA of current within an max of 5V output which is insufficient to rotate the motor. So we need

Parikshit Saha IIT Kanpur

Analog Out (PWM) Concept

• No facility exists on most microcontrollers to directly output an analog voltage (i.e., a voltage that varies continuously over the range of 0 to 5V) • Use Pulse Width Modulation (PWM) to approximate

• Digital outputs are capable of 0V or 5V

• Over a fraction (ton) of a time period tcycle, keep pin at 5V, the rest of the time, at 0V

• Average voltage is proportional to ton/tcycle, called the ‘Duty Cycle’

Page 13: EXPERIMENT : Programing a microcontroller ... · •Arduino directly can provide only 40mA of current within an max of 5V output which is insufficient to rotate the motor. So we need

Parikshit Saha IIT Kanpur

Output voltage is averaged from on vs. off time

Page 14: EXPERIMENT : Programing a microcontroller ... · •Arduino directly can provide only 40mA of current within an max of 5V output which is insufficient to rotate the motor. So we need

Parikshit Saha IIT Kanpur

PWM – Pulsewidth Modulation

• Square wave with fixed (high) frequency, but variable ON time..

• Fraction of time period signal is high varies between 0 and 1. Expressed in percentage, called duty cycle.

• Dedicated PWM pins on Arduino boards. Voltage obtained on PWM pin is duty cycle/100 * 5 V, when analog signal sent to the pin is duty cycle/100 * 255.

Page 15: EXPERIMENT : Programing a microcontroller ... · •Arduino directly can provide only 40mA of current within an max of 5V output which is insufficient to rotate the motor. So we need

Parikshit Saha IIT Kanpur

DC Motor Interfacing

• Dc Motor have two terminals vcc & gnd

• Arduino directly can provide only 40mA of current within an max of 5V output which is insufficient to rotate the motor. So we need a specific type of circuit known as Motor Driver to drive the motor.

• Some Dc Motor also has a higher V-I requirement based on torque of operation. (600mA, 4.5V to 36V)

• H-bridge circuit is used.

• Different types of H-bridge circuits are L293, L293D, L298

• Some Advanced level H-bridge circuits are VNH2SP30, VNH5019 have the higher voltage- current motor driving capabilities.

Page 16: EXPERIMENT : Programing a microcontroller ... · •Arduino directly can provide only 40mA of current within an max of 5V output which is insufficient to rotate the motor. So we need

Parikshit Saha IIT Kanpur

DC Motor Interfacing (contd.)

• fhgfation

Page 17: EXPERIMENT : Programing a microcontroller ... · •Arduino directly can provide only 40mA of current within an max of 5V output which is insufficient to rotate the motor. So we need

Parikshit Saha IIT Kanpur

Encoder ON-OFF Demo

• fhgfation

Page 18: EXPERIMENT : Programing a microcontroller ... · •Arduino directly can provide only 40mA of current within an max of 5V output which is insufficient to rotate the motor. So we need

Parikshit Saha IIT Kanpur

Encoder Counter Demo

• fhgfation

Page 19: EXPERIMENT : Programing a microcontroller ... · •Arduino directly can provide only 40mA of current within an max of 5V output which is insufficient to rotate the motor. So we need

Parikshit Saha IIT Kanpur

What is Servo Motor?

• 3 Wire terminals vcc, gnd & signal

• In signal terminal we feed angle of rotation in degree while using directly ‘servo.h’ Arduino library

• Internally Dc Motor + Potentiometer

Page 20: EXPERIMENT : Programing a microcontroller ... · •Arduino directly can provide only 40mA of current within an max of 5V output which is insufficient to rotate the motor. So we need

Parikshit Saha IIT Kanpur

Servo Motor Interfacing (from library function)

Page 21: EXPERIMENT : Programing a microcontroller ... · •Arduino directly can provide only 40mA of current within an max of 5V output which is insufficient to rotate the motor. So we need

Parikshit Saha IIT Kanpur

Servo Motor Interfacing (building from scratch)

Page 22: EXPERIMENT : Programing a microcontroller ... · •Arduino directly can provide only 40mA of current within an max of 5V output which is insufficient to rotate the motor. So we need

Parikshit Saha IIT Kanpur

DC Motor with Encoder

Page 23: EXPERIMENT : Programing a microcontroller ... · •Arduino directly can provide only 40mA of current within an max of 5V output which is insufficient to rotate the motor. So we need

Parikshit Saha IIT Kanpur

Encoder ON-OFF Demo

• fhgfation

Page 24: EXPERIMENT : Programing a microcontroller ... · •Arduino directly can provide only 40mA of current within an max of 5V output which is insufficient to rotate the motor. So we need

Parikshit Saha IIT Kanpur

Encoder Counter Demo

• fhgfation