Presentation is loading. Please wait.

Presentation is loading. Please wait.

ProtoSnap Introduction to Arduino Casey Haskell, Pete Lewis, David Stillman, Jim Lindblom, Pete Dokter, Lindsay Levkoff, Trevor Zylstra.

Similar presentations


Presentation on theme: "ProtoSnap Introduction to Arduino Casey Haskell, Pete Lewis, David Stillman, Jim Lindblom, Pete Dokter, Lindsay Levkoff, Trevor Zylstra."— Presentation transcript:

1 ProtoSnap Introduction to Arduino Casey Haskell, Pete Lewis, David Stillman, Jim Lindblom, Pete Dokter, Lindsay Levkoff, Trevor Zylstra

2 Overview of Class History of Arduino/SFE What is the Protosnap?: Concept, design, hardware Intro to Coding: Arduino software Example Sketches: Digital Output, Digital Input RGB LEDs Analog Input, Analog Output

3 SparkFun Electronics Sharing Ingenuity

4 Arduino Board “Strong Friend” Created in Ivrea, Italy in 2005 by Massimo Banzi & David Cuartielles Open Source Hardware Atmel Processor Coding is accessible (C++, Processing, ModKit and MiniBloq) Team Arduino: (Left to right) David Cuartielles, Massimo Banzi & Gianluca Martino

5 Numbers on the tabs indicate how they are pre- wired to the arduino mini.

6

7

8 Arduino Mini

9 The Arduino Environment

10 The Environment

11 Parts of the Sketch

12 Board Type

13 Serial Port / COM Port

14 Digital Output To Output a Digital signal (On or Off) use this code: digitalWrite ( pinNumber, value ); Where value is HIGH or LOW Where pinNumber is the pin you want effect.

15 Now let's upload “Blink.pde”

16 Declaring Variables Boolean: boolean variableName; Integer: int variableName; Character: char variableName; String: stringName [ ];

17 Assigning Variables Boolean: variableName = true; or variableName = false; Integer: variableName = 32767; or variableName = -32768; Character: variableName = ‘A’; or stringName = “SparkFun”;

18 Now let's add variables to “Blink.pde” (and for fun, let's try changing the delay time)

19 Digital Input Useful when reading a button. *The protosnap has a button pre-wired to pin 7. Add this to your setup:pinMode ( 7, INPUT ); Use this in your loop: digitalRead ( 7 ); Digital Input values are HIGH or LOW

20 Button Schematic

21 Internal Pullup Resistors Add this to your setup: digitalWrite ( 7, HIGH ); This means... your button will read HIGH when it is not pushed and LOW when it is pushed

22 If Statements if ( this is true ) { do this; }

23 If if ( this is true ) { do this; }

24 Conditional if ( this is true ) { do this; }

25 Action if ( this is true ) { do this; }

26 Else else { do this; }

27 Now let's upload “Button.pde”

28 RGB LEDs are different... To turn these LEDs on... digitalWrite(3, LOW);

29 Analog Input Useful to read a sensor that is not simply ON/OFF. (i.e. something like brightness, direction or speed) *The protosnap has a light sensor wired to Pin A0. Use this in your loop: analogRead ( A0 ); Analog Input varies from 0 to 1023 on an Arduino

30 Before we use analogRead(), let's learn about Serial Communication. This will be very useful to understand analogRead(); It will allow us to stream the values from the light sensor and watch the data change in real time.

31 Serial in Setup

32 Serial Communication: Serial Setup void setup ( ) { pinMode ( 5, OUTPUT ); pinMode ( 6, OUTPUT ); pinMode ( 7, OUTPUT ); Serial.begin ( 9600 ) ; } In this case the number 9600 is the baudrate at which the computer and Arduino communicate

33 Serial Monitor

34 Serial Communication: Sending a Message void loop ( ) { //read the value from the sensor: sensorValue = analogRead (sensorPin); Serial.println(sensorValue); if(sensorValue < 90){ digitalWrite(5, LOW); } //code continues after this

35 Serial Communication

36 Now let's upload “Light_data_stream.pde”

37 Now let's do something with the light values! Using “if statements” we can turn on different RGB LEDs when there is different amounts of light in the room. Let's upload AnalogInput_Multi_Threshold.pde

38 Analog Output Output is always Digital but… To output a signal that pretends to be Analog use this code: analogWrite ( pinNumber, value ); Where value is a number 0 - 255 Where pinNumber is the pin you want to effect.

39 Analog Output Output is always Digital Using a Digital signal that pretends to be an Analog signal is called Pulse Width Modulation Use Pulse Width Modulation, or P.W.M., for anything that requires a signal between HIGH and LOW * like setting an LEDs brightness P.W.M. is available on Arduino pins # 3, 5, 6, 9, 10, and 11

40 Analog Output Output is always Digital, even when it’s P.W.M. For P.W.M. the Arduino pin turns on then off very fast P.W.M. Signal @ 25%P.W.M. Signal @ 75% P.W.M. Signal rising

41 Now let's upload “Analog_Blink.pde”

42 Basic Repetition for (int count = 0; count<10; count++) { //for action code goes here //this could be anything }

43 Basic Repetition for (int count = 0; count<10; count++) { //for action code goes here }

44 Basic Repetition for (int count = 0; count<10; count++) { //for action code goes here }

45 Basic Repetition for (int count = 0; count<10; count++) { //for action code goes here }

46 Basic Repetition for (int count = 0; count<10; count++) { //for action code goes here }

47 Basic Repetition for (int count = 0; count<10; count++) { //for action code goes here }

48 Basic Repetition for (int count = 0; count<10; count++) { //for action code goes here }

49 Now Let's try “Fading” an LED You can find it here...

50 Note, we need to change the variable “ledPin” to one of the RGB pins (5,6 or 3).

51 Oh, Snap! Personal Projects Dave’s Alarm System Pete’s Guitar Ben’s Project

52 Questions?

53 www.sparkfun.com 6175 Longbow Drive, Suite 200 Boulder, Colorado 80301


Download ppt "ProtoSnap Introduction to Arduino Casey Haskell, Pete Lewis, David Stillman, Jim Lindblom, Pete Dokter, Lindsay Levkoff, Trevor Zylstra."

Similar presentations


Ads by Google