1 / 40

Using Arduino

Using Arduino. Material taken from Todbot blog Bionic Arduino. What is the Arduino. Arduino Duemilanove. 13 digital input/output pins Including 6 with PWM for analog output 6 analog input pins USB connection For serial I/O and uploading board ATmega168 or ATmega328 processor

viveka
Download Presentation

Using Arduino

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. Using Arduino Material taken from Todbot blog Bionic Arduino

  2. What is the Arduino

  3. Arduino Duemilanove • 13 digital input/output pins • Including 6 with PWM for analog output • 6 analog input pins • USB connection • For serial I/O and uploading board • ATmega168 or ATmega328 processor • 16k or 32k for program, 1k or 2k for data • Arduinobootloader • ~ $30 • More Info

  4. Other Arduino Boards • Arduino Mega • Lots of I/O pins and lots (128k) of program space • ~ $65 • LilyPad • For wearable applications • ~ $20 • Boarduino • Fits within a breadboard • ~ $20, but must be soldered!

  5. Activity 1 • Start the Arduino IDE from the terminal window with the command: arduino • Make sure to connect the PC to the Arduino using the USB cable. • Designate the connection port and processor type. • Try out the “blink” example • Select: File > Examples > Digital > Blink

  6. Connect the USB Cable

  7. Select Connection and Type atmega328

  8. Arduino IDE

  9. Status Messages

  10. Activity 1 Modified---Add an External LED to pin 13 • File > Examples > Digital > Blink • LED’s have polarity • Negative indicated by flat side of the housing and a short leg www.instructables.com

  11. Terminology

  12. Arduino Control • Very much like Processing/Java • if, then, while, switch • Functions, expressions • setup() • Runs once at beginning (or reset) • loop() • Runs continuously • Like draw()

  13. Arduino Digital I/O • 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 • Electronic stuff you can ignore • Output pins can provide 40 mA of current • Writing HIGH to an input pin installs a 20KΩ pullup

  14. Arduino Timing • delay(ms) • Pauses for a few milliseconds • delayMicroseconds(us) • Pauses for a few microseconds

  15. Circuits

  16. Breadboard Fundamentals There are ten holes that form the rows. These are divided into two sets of five holes. All holes in each set of five are connected Connect this column to GND (0 volts) Connect this column to 5V All holes in each of the four long columns are connected internally. Use these to route power and ground. Connect this column to GND (0 volts) Connect this column to 5V

  17. Activity 2 • File > Examples > Digital > Melody • Speakers have polarity. Positive indicated by small + or dot on piezoelectric speaker.

  18. Activity 2 • Get a breadboard and a piezoelectric speaker • Assemble as shown Image credit: Tod Kurt • Try out the built-in “melody” example • Select: File > Examples > Digital > toneMelody • Try this version of Melody.pde

  19. Digital? Analog? Digital has two values: on and off Analog has many (infinite) values Computers don’t really do analog, they quantize Remember the 6 analog input pins---here’s how they work Image credit: Tod Kurt

  20. Analog to Digital Number of states or “bins” is the resolution Arduino resolution is 10-bits (1024 values) 5/1024 = 4.8 mV smallest voltage change you can measure Image credit: Eoin Brazil

  21. Analog Output Computers can’t output analog voltages Only digital voltages (0 volts or 5 volts) Simulating an analog signal with Pulse Width Modulation (PWM) Can’t directly supply 2.5V, but can pulse the output on and off really fast to produce the same effect---the same effective voltage.

  22. Analog Output Vary the effective voltage by modulating the width of the high pulse Image credit: Tod Kurt

  23. Activity 3 Image credit: Tod Kurt • Select: File > Examples > Analog > Fading • Hardware Needed: • Resistor (in 220-500 Ohm range) • Breadboard • LED • Wire • Assemble as shown (MOVE the piezo speaker to pin 7)

  24. PWM is Everywhere Lamp dimmers, motor, speed control, power supplies, noise making, etc. Now on to analog input using sensors---DON’T DISASSEMBLE your breadboards

  25. Sensing the Dark: Photoresistors a.k.a. a photocell or light-dependent resistor It is a variable resistor Brighter light => lower resistance Create a voltage divider to use the photoresistor Image credit: Tod Kurt

  26. Activity 4 Image credit: Tod Kurt • Hardware Needed: • Resistor (approx. 10k Ohm) • Breadboard • Photoresistor • Wire • Assemble as shown

  27. A Theremin Create a theremin using the photoresistor A spooky sound machine Works by measuring your body’s electric field We’ll use light to control the tone produced We’ll also control the brightness of the LED using the photoresistor. Verify your breadboard configuration!

  28. Theremin Breadboard Configuration Hardware Needed: Resistors, Breadboard, Wire, Photoresistor, Piezo speaker, LED

  29. The Theremin Program Load and run the TherminAndLED program

  30. Sensors There are many analog sensors that could be used in place of the photoresistor Check out our “theremin” demos created using other sensors Image credit: Tod Kurt

  31. Arduino Program Processing Program Serial (TTL) Communication Your Computer Arduino Board Communication Between the Arduino and Your Computer

  32. Processing • Includes libraries supporting serial communication, video capture, audio processing… • VERY IMPORTANT: enter the following command in the terminal window to update the serial library: ~brock/bin/serialfix • Start Processing from the terminal window

  33. Activity 5 Image credit: Tod Kurt • Hardware Needed: • Resistor (10k Ohm) • Breadboard • Photoresistor • Wire • Don’t reassemble - this is the same schematic as Activity 4.

  34. Activity 5 Open SimpleWrite.pdeinto the Arduino IDE. Open SimpleRead.pde into Processing.

  35. Serial Communication in Arduino

  36. Serial Communication in Processing

  37. Clarifications • SimpleWrite spends the first second sampling the photocell readings and setting limits. • The Arduino program restarts when the Processing program starts. • If the Processing program begins behaving badly, try pressing the restart button on the Arduino.

  38. Project 2 • Project 2

More Related