Presentation is loading. Please wait.

Presentation is loading. Please wait.

Arduino UMBC IEEE Sekar Kulandaivel

Similar presentations


Presentation on theme: "Arduino UMBC IEEE Sekar Kulandaivel "— Presentation transcript:

1 Arduino Microcontroller Workshop UMBC Institute of Electrical and Electronics Engineers
Arduino UMBC IEEE Sekar Kulandaivel Week 2: Arduino Programming with Piezo Technical Skills Series Presentation April 8th – 9th, 2014

2 Topics to Cover Arduino Coding Basics & Functions Analog & Digital Signals Piezoelectric Sensors Pulse Width Modulation

3 Color 1st Digit 2nd Digit Multiplier
4th band is Tolerance. L R Color 1st Digit 2nd Digit Multiplier Black 100 Brown 1 101 Red 2 102 Orange 3 103 Yellow 4 104 Green 5 105 Blue 6 106 Violet 7 107 Gray 8 108 White 9 109

4 330Ω 3 x = 10kΩ 1 x = 2kΩ 2 x = 1MΩ 1 x =

5 Made with Fritzing.org

6 Important Functions int val, time; void setup() { … } void loop() { … } Serial.begin(9600); Serial.print(“Hello”); Serial.println(“Hi”); delay(1000); pinMode(8, INPUT); pinMode(9, OUTPUT); val = digitalRead(8); digitalWrite(9, out); val = analogRead(A0); analogWrite(9, out); time = millis(); map(var, testLow, testHigh, mapLow, mapHigh); tone(8, pitch, time);

7 const int sensorPin = 8; int sensorValue; void setup() { Serial
const int sensorPin = 8; int sensorValue; void setup() { Serial.begin(9600); pinMode(sensorPin, INPUT); } void loop() { sensorValue = digitalRead(sensorPin); Serial.println(sensorValue); delay(25);

8 const int sensorPin = 8; const int outputPin = 9; int sensorValue; void setup() { Serial.begin(9600); pinMode(sensorPin, INPUT); pinMode(outputPin, OUTPUT); } void loop() { sensorValue = digitalRead(sensorPin); Serial.println(sensorValue); if (sensorValue == HIGH) { digitalWrite(outputPin, HIGH); delay(500); digitalWrite(outputPin, LOW); delay(25);

9 const int sensorPin = A0; const int outputPin = 9; int sensorValue; void setup() { Serial.begin(9600); pinMode(sensorPin, INPUT); pinMode(outputPin, OUTPUT); } void loop() { sensorValue = analogRead(sensorPin); Serial.println(sensorValue); analogWrite(outputPin, sensorValue); delay(25);

10 const int sensorPin = A1; const int outputPin = 9; int sensorValue; int low = 300; int high = 450; int range[2] = {0, 255}; void setup() { Serial.begin(9600); pinMode(sensorPin, INPUT); pinMode(outputPin, OUTPUT); } void loop() { sensorValue = analogRead(sensorPin); Serial.println(sensorValue); sensorValue = map(sensorValue, low, high, range[0], range[1]); analogWrite(outputPin, sensorValue); delay(25);

11 const int sensorPin = A1; const int outputPin = 11; int wait = 25; int sensorValue, pitch; int range[2] = {1023, 0}; int minTone = 500; int maxTone = 1500; void setup() { Serial.begin(9600); pinMode(sensorPin, INPUT); pinMode(outputPin, OUTPUT); while (millis() < 3000) { sensorValue = analogRead(sensorPin); if (sensorValue < range[0]) { range[0] = sensorValue; } if (sensorValue > range[1]) { range[1] = sensorValue; }

12 void loop() { sensorValue = analogRead(sensorPin); Serial
void loop() { sensorValue = analogRead(sensorPin); Serial.println(sensorValue); pitch = map(sensorValue, range[0], range[1], minTone, maxTone); tone(outputPin, pitch, wait); delay(wait); }

13 Challenge Requirements: Sense a knock using the piezoelectric sensor.
Flash LED once for a soft knock. Flash LED twice for a loud knock. Analog Notes: Remove photoresistor and potentiometer circuits from your board. Knock on the breadboard or tap the piezo for the best results. Utilize previous code as a guide for your project.


Download ppt "Arduino UMBC IEEE Sekar Kulandaivel "

Similar presentations


Ads by Google