1 / 19

Lab 1: Arduino Basics

Lab 1: Arduino Basics. Topics: Arduino Fundamentals, First Circuit. What is Arduino?. “Open-source prototyping platform based on easy to use HW and SW.” Inexpensive Cross-platform Simple programming environment (IDE) Open-source SW and HW. Making Stuffs Using Arduino.

sdailey
Download Presentation

Lab 1: Arduino Basics

An Image/Link below is provided (as is) to download presentation Download Policy: Content on the Website is provided to you AS IS for your information and personal use and may not be sold / licensed / shared on other websites without getting consent from its author. Content is provided to you AS IS for your information and personal use only. Download presentation by click this link. While downloading, if for some reason you are not able to download a presentation, the publisher may have deleted the file from their server. During download, if you can't get a presentation, the file might be deleted by the publisher.

E N D

Presentation Transcript


  1. Lab 1: Arduino Basics Topics: Arduino Fundamentals, First Circuit

  2. What is Arduino? • “Open-source prototyping platform based on easy to use HW and SW.” • Inexpensive • Cross-platform • Simple programming environment (IDE) • Open-source SW and HW

  3. Making Stuffs Using Arduino • You can connect sensors and actuators, and program your Arduino to control them. Sensors (input) Actuators (output)

  4. Arduino Uno Anatomy http://arduinoarts.com/tag/anatomy/

  5. Know Your Tools LED Resistor Bread Board Push Button Switch (all images are from Google image search)

  6. Program Structure • setup() – executed once at the beginning. • loop() – it’s an infinite loop.

  7. “Hello World” voidsetup() { Serial.begin(9600); // setup serial } voidloop() { Serial.println(“Hello World”);//prints to Serial console } • Setup and Use Serial

  8. Arduino Language Reference • Almost the same as C with some new things: • setup() and loop() • Constants: HIGH, LOW, INPUT, OUTPUT • Digital/Analog input/output functions • Library methods for – character, bits, interrupts, memory read/write, and communication. • https://www.arduino.cc/en/Reference/HomePage

  9. Digital Read and Write • Digital IO: HIGH or LOW Output Input

  10. Digital Read and Write intledPin = 13; // LED connected to digital pin 13 intinPin = 7; // pushbutton connected to digital pin 7 intval = 0; // variable to store the read value voidsetup() { pinMode(inPin, INPUT); // sets digital pin 7 as input pinMode(ledPin, OUTPUT); // sets digital pin 13 as output } voidloop() { val = digitalRead(inPin); // read the input pin (button) digitalWrite(ledPin, val); // sets the LED to the value } • Digital IO: HIGH or LOW

  11. Analog I/O • Many sensors and actuators are analog. LED Output Digital pins with a “~” prefix can output simulated analog values. It’s called PWM mode. Input Temperature Sensor

  12. Analog Read • Arduino UNO has a 10-bit analog-to-digital converter, so input voltage mapped to [0, 1023] intanalogPin = 3; // potentiometer middle terminal connected to analog pin 3 outside leads to ground and +5V intval = 0; // variable to store the value read voidsetup() { Serial.begin(9600); // setup serial } voidloop() { val = analogRead(analogPin); // read the input pin Serial.println(val); // debug value }

  13. Analog Write (PWM) • Analog effect with digital means. • Must be [0, 255], and it will mean “duty cycle”. pinMode(9, OUTPUT); int X = 100; analogWrite(9, X); An Arduino (having 5V as its VCC) will write (5.0 / 255) * 100 = 1.96V

  14. Memory • Optimizing SRAM use: • Use a connected smartphone/computer to move data out for calculation. • Use smaller data types (byte if you don’t need an int.) • Use Flash memory (PROGMEM keyword) • Use EEPROM (use EEPROM library)

  15. Variety of Arduino Boards

  16. Expanding Arduino with ‘Shields’ Arduino + GPS Shield Arduino + Joy Stick Shield Arduino + Xbee Shield

  17. Today’s Lab: “Traffic Light” • The circuit is similar to project #2 of Arduino Projects Book but the behavior (code) is different. • https://www.arduino.cc/en/ArduinoStarterKit/Prj02

  18. Behavior of the “Traffic Light” Logic to Implement: • Initially only Green light stays ON. • When Green is ON and the button is pressed: • Green stays ON for 2 seconds and then goes OFF. • Yellow turns ON for and stays 2 seconds and then goes OFF. • Red turn ON and stays like this forever (or, until the next click). • When Red is ON and the button is pressed: • Red goes OFF immediately. • Green turns ON and stays like this forever (or, until next click)

  19. References (study these) • https://www.arduino.cc/en/Guide/Introduction • https://www.arduino.cc/en/Tutorial/Foundations • https://www.arduino.cc/en/Guide/BoardAnatomy • https://www.arduino.cc/en/Tutorial/DigitalPins • https://www.arduino.cc/en/Tutorial/AnalogInputPins • https://www.arduino.cc/en/Tutorial/PWM • https://www.arduino.cc/en/Tutorial/Memory • https://www.arduino.cc/en/Reference/PinMode • https://www.arduino.cc/en/Reference/DigitalWrite • https://www.arduino.cc/en/Reference/DigitalRead • https://www.arduino.cc/en/Reference/AnalogRead • https://www.arduino.cc/en/Reference/AnalogWrite • https://www.arduino.cc/en/ArduinoStarterKit/Prj02

More Related