Physics 120/220 Microcontrollers Extras Prof. Anyes Taffard
Introduction 2 There are an infinite amount of applications for the Arduino. Lots of interfaces that can be controlled with it. Extension boards (aka shield) that can be used to get more pins and/or work with specific interfaces Lots of libraries and examples Ultimately, the code must be yours and adapted to your application If you plan to use Arduino for your project, here are few (not exhaustive) considerations: Will there will be enough pin of the appropriate type (analog/digital) to drive your interface(s)? If not, consider using a shift register Always document which pins on the device is connected to which pins on the Arduino Some libraries may disable some pin feature (eg PWM on some pins) Some interface only plug to certain pins (eg Bluetooth) Whatever interface you wish to use, you must download the datasheet and understand how it works Would you need an independent power source? (eg: battery pack, solar panel) Would you have enough current to drive the load? Use transistor or relay with a protecting diode to increase current output from Arduino Recall: common ground, 10X rule, voltage dividers
Reference voltage An analog voltage on an Arduino analog pin (A0àA5) is converted to a 10-bit integer (0 to 1023) using a successive ADC 5V/1024 = 4.9mV If your max voltage is eg 2V, you can increase the precision by changing the reference voltage (5V) to 2V: 2V/1024 = 1.9mV 3 1. Use Arduino external AREF pin: connect the new reference voltage to AREF and match its GND to the Arduino GND ü ü ü You can then use a voltage divider on the 5V PS to get the reference voltage You can also add a low value Cap between AREF & GND to reduce noise, and prevent unstable analog reading In void setup(), you ll need to add analogreference(external) 2. Use Arduino internal 1.1V reference analogreference(internal)
Displays 4 7 segments LED (or LED matrix) 7 LED segments all connected to a common cathode (anode) Always check datasheet to get the pin assignment eg for HDSP-313E: Connect pin 3 & 8 to -5V via a 220 res Test each segment by connecting them to +5V LED labeled A to G and DP for decimal point eg: display 7: turn on A, B & C Use a shift register (eg 74HC595) with outputs Q0àQ7 Drive shift register using Arduino For 7: Set Q0, Q1 & Q2 to HIGH ie send 1110000
Displays Liquid crystal display Use datasheet & see https://www.arduino.cc/en/reference/liquidcrystal 5
Servo 6 Little motor that can be controlled to rotate to a specific angular position When selecting a Servo, consider: Speed: time it takes to rotate (second/degrees) Rotation range: 0-180 o or 0-360 o Current the servo draws (may need external PS) Torque: Greater the torque, the heavier the object it can rotate On boards other than the Mega, use of the library disables analogwrite() (PWM) functionality on pins 9 and 10, whether or not there is a Servo on those pins.
Driving motor(s) Some considerations: Operating voltage (3V-12V) Current w/o load Current the motor uses to spin freely Stall current ie nothing connected to the motor s shaft Amount of current used by motor when tries to rotate but can t because of the load on the motor Speed at the operating voltage (RPM) You can use a Darlington Transistor (eg TIP120) that can pass up to 5A at 60V You ll need a separate PS (eg battery). Can also be used to power the Arduino. Motor speed can be controlled via PWM However, cannot control motor direction with this setup 7
Driving motor(s) 8 Alternatively, if you need to drive multiple motors, you can use a motor driving board (eg L298N). The dual H-Bridge allows to drive current in either polarities Can handle higher current draw Easily interface with Arduino Speed via PMW (use Arduino digital ~) If your motor wires are not color coded, you ll need to figure out the forward/backward direction Motor A is control by ENA, IN1 IN2 Motor B is control by ENB, IN3 IN4 ENA IN1 IN2 Description 0 N/A N/A Motor off 1 0 0 Motor is stopped (brake) 1 0 1 Motor is on & goes backwards 1 1 0 Motor is on & goes forwards 1 1 1 Motor is stopped (brake) http://geekonfire.com/wiki/index.php?title=dual_h-bridge_motor_driver Connect L298N pins to the Arduino digital pins. Alternatively, ENA and ENB have jumper caps. By removing these, and connecting ENA/ENB to analog pins, you can use PWM to control speed int speed = 255/2; digitalwrite(en1,1); digitalwrite(en2,0); analogwrite(ena, speed);
Infrared receiver/transmitter 9 Controlling an Arduino with an infrared remote control is made easy with the library provided: To add a library to your sketch: SketchàInclude libraryàirremote Use the Serial port to figure out the code transmitted for each key. Downside of infrared is the range and potential to miss receiving/transmitting packets if not aligned between Rx/Tx
Bluetooth 10 Using a Bluetooth with Arduino is again relatively easy thanks to the library: #include <SoftwareSerial.h> Note: Compatibility between BT and device (eg phone, tablet) The communication is done on via Serial port Arduino serial communication via USB is done on Rx=0 & Tx=1 pins So you if you need to debug with Serial.print(), make sure to define 2 separate ports, using different pins Unplug the BT to upload code to Arduino. Otherwise get error: avrdude: stk500_getsync()
BACKUP 11