arduino for beginners
play

ARDUINO FOR BEGINNERS Smitha Pisupati and Sushma Rao Apr 26 2015 - PowerPoint PPT Presentation

ARDUINO FOR BEGINNERS Smitha Pisupati and Sushma Rao Apr 26 2015 What is Arduino An open source electronics platform Easy to use HW and SW Make interactive projects No electronics background required The HW Arduino


  1. ARDUINO FOR BEGINNERS Smitha Pisupati and Sushma Rao Apr 26 2015

  2. What is Arduino ¨ An open source electronics platform ¨ Easy to use HW and SW ¨ Make interactive projects ¨ No electronics background required

  3. The HW – Arduino UNO

  4. The Hardware

  5. The Software Download: http://arduino.cc/en/Main/Software

  6. Blink an LED

  7. Blink an LED ¨ Connect the Arduino to the PC/Mac ¨ Open the Blink example File -> Examples -> 01.Basics -> Blink ¨ Upload!

  8. Let’s look at the code

  9. Hey Arduino, Run this part when you power up! Hey Arduino, Run this part over and over, forever!

  10. Set Pin 13 to output Set Pin 13 to HIGH Wait 1 second Set Pin 13 to LOW Wait 1 second

  11. Connect an External LED Digital Output

  12. Breadboard Connections in the breadboard Breadboard Internals http://www.crifan.com/arduino_and_bread_board/

  13. External LED

  14. What makes the LED glow?

  15. Electricity!

  16. Electricity!

  17. Resistor ¨ Limits amount of charge flowing through the circuit ¨ Has a “resistance” ¨ Higher the resistance, lower the amount of charge flow

  18. Schematic ¨ Circuit diagram ¨ Uses symbols for electronic components

  19. Control the Blink Rate Analog Sensor

  20. Meet the Potentiometer ¨ A.K.A The Pot ¨ Variable resistor

  21. How does it work? ¨ Voltage divider ¨ Voltage at A0 is a fraction of 5V DC

  22. Adding a potentiometer

  23. Changes to Blink code ¨ In the loop function, add the following line: int delayVal = analogRead(A0); ¨ Change delay(1000) to the following: delay(delayVal); // delayVal will be a number between 0 and 1023.

  24. Adding serial debug

  25. Add Serial Debug ¨ Add the following line to the setup() function Serial. Serial.begin(9600); ¨ Add the following line to the loop() function Serial.println(delayVal);

  26. Serial Monitor More details at http://www.arduino.cc/en/Reference/Serial ¨

  27. Ultrasonic Distance Sensor Digital Sensor

  28. Ultrasonic distance sensor ¨ 4 pins ¤ VCC ¤ GND ¤ Trigger ¤ Echo

  29. Reading Values from the Sensor Add the following at the top of the file ¨ unsigned long distanceInCm = 0; Add the following lines of code in the setup() function ¨ pinMode (trigger, OUTPUT); pinMode(echo, INPUT); Add the following in the loop() function ¨ // Hold trigger pin high for 10 microseconds digitalWrite(trigger, HIGH); delayMicroseconds(10); digitalWrite(trigger, LOW); // Get the width of the pulse with pulseIn count = pulseIn(echo, HIGH); // get distance in cm. Divide by 148 for inches distanceInCm = count / 58;

  30. Glowing the LED ¨ Add the following at the top of the file int ledPin = 13; ¨ Add the following lines of code in the setup() function pinMode(ledPin, OUTPUT); ¨ Add the following in the loop() function if(distanceInCm < 10) { digitalWrite(ledPin, HIGH); } else { digitalWrite(ledPin, LOW); }

  31. Finally… ¨ Add the following at the end of the loop count = 0; // add a delay for stable behaviour delay(200);

  32. Building the Theremin

  33. Let’s Code It

  34. Repeat the LED code 6 more times ¨ Add the following at the top of the file int ledPin1 = 13; int ledPin2 = 12; int ledPin3 = 11; …

  35. Repeat the LED code 6 more times ¨ Add the following lines of code in the setup() function pinMode(ledPin1, OUTPUT); pinMode(ledPin2, OUTPUT); pinMode(ledPin3, OUTPUT); …

  36. Repeat the LED code 6 more times ¨ Add the following in the loop() function if(distanceInCm < 10) { digitalWrite(ledPin1, HIGH); digitalWrite(ledPin2, HIGH); digitalWrite(ledPin3, HIGH); … } else { digitalWrite(ledPin1, LOW); digitalWrite(ledPin2, LOW); digitalWrite(ledPin3, LOW); … }

  37. Test It! ¨ Upload and check that this works…

  38. Adding an else-if if(distanceInCm < 10) { digitalWrite(ledPin1, HIGH); … } else if (distanceInCm < 12) { digitalWrite(ledPin1, HIGH); digitalWrite(ledPin2, LOW); digitalWrite(ledPin3, LOW); … } else { digitalWrite(ledPin1, LOW); … }

  39. Notes to play ¨ link to source ¨ Copy the top part of the file that looks like this: #define NOTE_B0 31 #define NOTE_C1 33 #define NOTE_CS1 35 #define NOTE_D1 37 #define NOTE_DS1 39 #define NOTE_E1 41 #define NOTE_F1 44 #define NOTE_FS1 46 #define NOTE_G1 49

  40. Adding the tone ¨ Connect the Piezo buzzer at pin 5 ¨ Add this line to the top of the file int piezo = 5; ¨ Add this to the setup() function pinMode(piezo, OUTPUT); ¨ Add this to the loop() function // To play the tone tone(piezo,<NOTE>); // to stop the tone noTone(piezo);

  41. Make Music!

  42. References ¨ http://www.arduino.cc/en/Reference/Tone ¨ http://www.arduino.cc/en/Tutorial/HomePage

Download Presentation
Download Policy: The content available on the website is offered to you 'AS IS' for your personal information and use only. It cannot be commercialized, licensed, or distributed on other websites without prior consent from the author. To download a presentation, simply click this link. If you encounter any difficulties during the download process, it's possible that the publisher has removed the file from their server.

Recommend


More recommend