experiment : programing a microcontroller ... · •arduino directly can provide only 40ma of...
TRANSCRIPT
Parikshit Saha IIT Kanpur
EXPERIMENT : Programing a microcontroller
- Microcontroller : basic programing
- Sensor interfacing
- Motor control : DC Motor, DC servo, etc.
- Encoder interfacing
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.
Parikshit Saha IIT Kanpur
Arduino Pin Diagram
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
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)
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
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. > }
Parikshit Saha IIT Kanpur
LED blink Arduino Demo
Parikshit Saha IIT Kanpur
Two colour LED glow – Arduino Demo
Parikshit Saha IIT Kanpur
Hall Sensor Interfacing
Parikshit Saha IIT Kanpur
Motor Interfacing with Arduino
By Parikshit Saha
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’
Parikshit Saha IIT Kanpur
Output voltage is averaged from on vs. off time
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.
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.
Parikshit Saha IIT Kanpur
DC Motor Interfacing (contd.)
• fhgfation
Parikshit Saha IIT Kanpur
Encoder ON-OFF Demo
• fhgfation
Parikshit Saha IIT Kanpur
Encoder Counter Demo
• fhgfation
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
Parikshit Saha IIT Kanpur
Servo Motor Interfacing (from library function)
Parikshit Saha IIT Kanpur
Servo Motor Interfacing (building from scratch)
Parikshit Saha IIT Kanpur
DC Motor with Encoder
Parikshit Saha IIT Kanpur
Encoder ON-OFF Demo
• fhgfation
Parikshit Saha IIT Kanpur
Encoder Counter Demo
• fhgfation