An Introduction to Arduino an Introduction to Arduino PDF GUIDE
Total Page:16
File Type:pdf, Size:1020Kb
An Introduction to Arduino An Introduction to Arduino PDF GUIDE: http://antoinettejcitizen.com/files/AICCM_Arduino.pdf Michelle Woulahan Antoinette J. Citizen Creative media facilitator at City of Melbounre Electronic media artist Events listing: http://bit.do/techEvents Website: antoinettejcitizen.com Microcontrollers A microcontroller is a very small computer on a single integrated circuit (IC). All computers have several things in common: • CPU (central processing unit) that executes programs. • RAM (random-access memory) where it can store variables. • Input and output devices for interaction. Desktop computers are “general purpose computers” that can run any of thousands of programs. Microcontrollers are “special purpose computers.” Microcontrollers do one thing well. Microcontrollers are often embedded onto a single printed circuit board. This board provides all of the circuitry necessary for a useful control task. The intention is that the board is immediately useful to an application developer, without them needing to spend time and effort in developing the controller hardware. BASIC Stamp Microcontroller: • Microchip Technology PIC • Parallax SX processor. mbed Microcontroller: • ARM Cortex IOIO OTG Microcontroller: • Microchip Technology PIC Arduino Microcontroller: Atmel AVR microcontroller • ATmega8 • ATmega168 • ATmega328 • ATmega1280 • ATmega2560 Arduino Single board microcontrollers like the Arduino are able to read inputs - light on a sensor, a finger on a button, or a Twitter message - and turn it into an output - activating a motor, turning on an LED, publishing something online. Arduino is an open-source prototyping platform based on easy-to-use hardware and software. Examples: http://www.creativeapplications.net/category/arduino-2/ There are lots of different types of Arduino boards. UNO is currently the most common and easily the best documented and best supported of the Arduinos. Micro- Input System Clock Digital Analog Flash Item Controller Voltage Voltage Speed I/O Inputs PWM Space Arduino Uno - R3 ATmega328 7-12V 5V 16MHz 14 6 6 32Kb Arduino Leonardo ATmega32U4 7-12V 5V 16MHz 20* 12 7 32Kb Arduino Pro ATmega328 3.35 -12V 3.3V 8MHz 14 6 6 32Kb 5V Arduino Yun ATmega32u4 5V 5V 16MHz 20 12 7 32Kb Atheros AR9331 3.3V 16MB Arduino Mega ATmega2560 7-12V 5V 16MHz 54 16 14 256Kb Arduino Pro Mini ATmega328 5 - 12V 5V 16MHz 14 8 6 32Kb Arduino Fio ATmega328P 3.35 -12V 3.3V 8MHz 14 8 6 32Kb LilyPad ATmega32U4 3.8V-5V 3.3V 8MHz 9 4 4 32Kb Arduino-compatible DF Robot Freetronics ArduPhone Barebones Cheapduino Lillypad Single-board Computers Single board computers like the Raspberry Pi use application processors rather than microcontrollers. These boards operated more like most computers you would normally use - you can plug in a display, keyboard and mouse, and run an operating system and applications. Beagle board Raspberry Pi 3 • AM335x 1GHz ARM® Cortex-A8 • 1.2GHz 64-bit quad-core ARMv8 CPU • 512MB DDR3 RAM • 1GB RAM • 4GB 8-bit eMMC on-board flash storage • Micro SD card slot • 3D graphics accelerator • VideoCore IV 3D graphics core • 1 USB host • 4 USB ports • 2x 46 pin headers • 40 GPIO pins • Mini HDMI port • Full HDMI port • Ethernet port • Ethernet port • NEON floating-point accelerator • Combined 3.5mm audio jack and • 2x PRU 32-bit microcontrollers Connectivity composite video • Camera interface • Display interface • 802.11n Wireless LAN • Bluetooth 4.1 Arduino uno: board layout Sidekick components • Breadboard x 1 • Photo resistor x 1 • Green LED x 5 • Diode x 1 • Red LED x 5 • Buzzer x 1 • RGB Common Anode LED x 1 • Button x 5 • Ceramic Capacitor(10nF x 10+100nF x 10) • Switch x 5 • Aluminum capacitor(100uF x 5) • Mini Servo x 1 • Resistor(330R x 10+1k x 10+10k x 10) • Potentiometer with knob x 1 • Tilt switch x 1 • Breadboard jumper wire x 25 (5x long, 20 x • Thermistor x 1 short) Breadboards A breadboard is a solderless device for temporary prototype with electronics and test circuit designs. Electronic components can be interconnected by inserting their leads or terminals into the holes and then making connections through wires where appropriate. The breadboard has strips of metal underneath the board and connect the holes on the top of the board. The metal strips are laid out as shown below. Rows of the same number in colums A-E and rows in columns F-J are connected. Power rail often used for positive and negative(GND) voltage First sketch: Blink 330 OHM Resistor Negative Positive (longer leg) (orange, orange, brown) • Open sketch: File > Examples > Basic > Blink • Create an “int” variable called LED, set it to the corresponding arduino digital pin number. • Change LED_BUILTIN to LED int LED = 7; void setup() { pinMode(LED, OUTPUT); } void loop() { digitalWrite(LED, HIGH); delay(1000); digitalWrite(LED, LOW); delay(1000); } Now try changing the delay number to make LED blink faster or slower. Resistor colour code arduino intergrated development enviroment (ide) 1. Verify: Compiles and approves your code. It will catch errors in syntax (like missing semicolons or parentheses). 2. Upload: Sends your code to the 101 board. 3. New: This buttons opens up a new code window tab. 4. Open: This button will let you open up an existing sketch. 5. Save: This saves the currently active sketch. 6. Serial Monitor: This will open a window that displays any serial information your 101 board is transmitting. It is very useful for debugging. 7. Sketch Name: This shows the name of the sketch you are currently working on. 8. Code Area: This is the area where you compose the code for your sketch. 9. Message Area: This is where the IDE tells you if there were any errors in your code. 10. Text Console: The text console shows complete error messages. When debugging, the text console is very useful. 11. Board and Serial Port: Shows you what board and the serial port selections. Select Your Board: Arduino/Genuino UNO Before we can start jumping into the experiments, there are a few adjustments we need to make. This step is required to tell the Arduino IDE which of the many Arduino boards we have. Go up to the Tools menu. Then hover over Board and make sure Arduino/Genuino UNO is selected. Select a Serial Port Next up we need to tell the Arduino IDE to which of our computer’s serial ports the 101 is connected. Again,, go up to Tools, hover over Port, and select your 101’s serial port. This will have Arduino 101 next to the port number in parentheses. Window Users: This is likely to be COM3 or higher (COM1 and COM2 are usually reserved for hardware serial ports). If there are multiple COM ports available, the UNO is likely the highest numbered port in the list. To be certain, you can also disconnect your UNO and reopen the menu; the entry that disappears should be the UNO. Reconnect the board and select that serial port. Mac Users: Select the serial device of the UNO from the Tools, then hover over Port. On the Mac, this should be something with /dev/tty.usbmodem or /dev/tty.usbserial in it. Multiple BlinKs We will edit the previous sketch to add two more LED variables. Add two new int for the two int LED = 9; added LEDs. int LED2 = 10; int LED3 = 11; void setup() { pinMode(LED, OUTPUT); Add pinMode for the two pinMode(LED2, OUTPUT); added LEDs. pinMode(LED3, OUTPUT); } void loop() { digitalWrite(LED, HIGH); digitalWrite(LED2, HIGH); digitalWrite(LED3, HIGH); Add digitalwrite HIGH and LOW sequence for all LEDs delay(1000); digitalWrite(LED, LOW); digitalWrite(LED2, LOW); digitalWrite(LED3, LOW); delay(1000); } fade We use anaologWrite(pin number,0-255) rather than digitalWrite(pin number,HIGH/LOW) in order to change the brightness of the LED. 0 being off and 255 being the brightess. AnalogWrite only works with PWM pins - on the Arduino UNO PWM are pins 3,5,6,9,10,11. Learn more about PWM here - https://www.arduino.cc/en/Tutorial/PWM Make sure you connect to a PWM pin! • Open sketch: File > Examples > Basic > Fade int led = 9; // the PWM pin the LED is attached to int brightness = 0; // how bright the LED is int fadeAmount = 5; // how many points to fade the LED by void setup() { pinMode(led, OUTPUT); } void loop() { analogWrite(led, brightness); // set the brightness of pin 9: brightness = brightness + fadeAmount; if (brightness <= 0 || brightness >= 255) { fadeAmount = -fadeAmount; } delay(30); } button input • Open sketch: File > Examples > Digital > Button const int buttonPin = 2; // the number of the pushbutton pin const int ledPin = 13; // the number of the LED pin // variables will change: int buttonState = 0; // variable for reading the pushbutton status void setup() { // initialize the LED pin as an output: pinMode(ledPin, OUTPUT); // initialize the pushbutton pin as an input: pinMode(buttonPin, INPUT); } void loop() { buttonState = digitalRead(buttonPin); // read the state of the pushbutton value: // check if the pushbutton is pressed. // if it is, the buttonState is HIGH: if (buttonState == HIGH) { // turn LED on: digitalWrite(ledPin, HIGH); } else { // turn LED off: digitalWrite(ledPin, LOW); } } SHields Shields are boards that can be plugged on top of the Arduino PCB extending its capabilities. Ethernet Shield GPS shield Audio Shield Motor Shield Proto Shield Library Manager Libraries are a collection of code that makes it easy for you to connect to a sensor, display, module, etc. For example, the built-in LiquidCrystal library makes it easy to talk to character LCD displays. There are hundreds of additional libraries available on the Internet for download. To install a new library into your Arduino IDE you can use the Library Manager (available from IDE version 1.6.2). Open the IDE and click to the “Sketch” menu and then Include Library > Manage Libraries.