Introduction to Arduino - University of Southern...
Transcript of Introduction to Arduino - University of Southern...
![Page 1: Introduction to Arduino - University of Southern Californiaviterbik12.usc.edu/.../07/Introduction-to-Arduino.pdf · What is the Arduino? • Arduino is an open source platform that](https://reader033.fdocuments.us/reader033/viewer/2022042316/5f05976d7e708231d413b8ec/html5/thumbnails/1.jpg)
Introduction to ArduinoAshrant Aryal
![Page 2: Introduction to Arduino - University of Southern Californiaviterbik12.usc.edu/.../07/Introduction-to-Arduino.pdf · What is the Arduino? • Arduino is an open source platform that](https://reader033.fdocuments.us/reader033/viewer/2022042316/5f05976d7e708231d413b8ec/html5/thumbnails/2.jpg)
Download and Setup
• Download the Arduino IDE and install it
• Choose the latest version for windows or mac.
• Link: https://www.arduino.cc/en/Main/Software
![Page 3: Introduction to Arduino - University of Southern Californiaviterbik12.usc.edu/.../07/Introduction-to-Arduino.pdf · What is the Arduino? • Arduino is an open source platform that](https://reader033.fdocuments.us/reader033/viewer/2022042316/5f05976d7e708231d413b8ec/html5/thumbnails/3.jpg)
What is the Arduino?
• Arduino is an open source platform that lets you program a microcontroller.
• Arduino IDE is used to program the Arduino.
• You can use it to read and write different digital input/output.
• Most common application is to read sensor values and do something with it
![Page 4: Introduction to Arduino - University of Southern Californiaviterbik12.usc.edu/.../07/Introduction-to-Arduino.pdf · What is the Arduino? • Arduino is an open source platform that](https://reader033.fdocuments.us/reader033/viewer/2022042316/5f05976d7e708231d413b8ec/html5/thumbnails/4.jpg)
Basics of electric circuits
• Current is measured in Amperes (Amp)
• Voltage is measured in Volts
• Resistance is measured in Ohm
![Page 5: Introduction to Arduino - University of Southern Californiaviterbik12.usc.edu/.../07/Introduction-to-Arduino.pdf · What is the Arduino? • Arduino is an open source platform that](https://reader033.fdocuments.us/reader033/viewer/2022042316/5f05976d7e708231d413b8ec/html5/thumbnails/5.jpg)
What are sensors?• A sensor is a device that detects and
responds to some type of input from the physical environment
• The specific input could be light, heat, motion, moisture, pressure and many more
• A sensor converts the environmental measurements into a signal that can be read using the Arduino
• In many sensors, the resistance changes based on the environment and we use the Arduino to measure potential difference (Voltage)
![Page 6: Introduction to Arduino - University of Southern Californiaviterbik12.usc.edu/.../07/Introduction-to-Arduino.pdf · What is the Arduino? • Arduino is an open source platform that](https://reader033.fdocuments.us/reader033/viewer/2022042316/5f05976d7e708231d413b8ec/html5/thumbnails/6.jpg)
Code Structure
void setup() {
// put your setup code here, to run once:
}
void loop() {
// put your main code here, to run repeatedly:
}
![Page 7: Introduction to Arduino - University of Southern Californiaviterbik12.usc.edu/.../07/Introduction-to-Arduino.pdf · What is the Arduino? • Arduino is an open source platform that](https://reader033.fdocuments.us/reader033/viewer/2022042316/5f05976d7e708231d413b8ec/html5/thumbnails/7.jpg)
Standard Functions
• Serial.begin(baud_rate):This function begins serial communication between the microcontroller and the arduino.
• Serial.print():This function prints the value in its argument on the serial monitor of the arduino IDE.
• delay(time): This function provides delay of given time (in milliseconds) during execution of the code.
![Page 8: Introduction to Arduino - University of Southern Californiaviterbik12.usc.edu/.../07/Introduction-to-Arduino.pdf · What is the Arduino? • Arduino is an open source platform that](https://reader033.fdocuments.us/reader033/viewer/2022042316/5f05976d7e708231d413b8ec/html5/thumbnails/8.jpg)
Standard Functions
• PinMode(pin_number, INPUT/OUTPUT) : This function declares a given pin to be input or output pin.
• digitalWrite(pin_number,0/1/HIGH/LOW):This function produces a digital signal of either HIGH(5V) or LOW(0V) on the given pin.
• analogWrite(pin_number, value):This function produces an analog signal varying between 0 to 5V on the given pin.
• analogRead(pin_number):This function reads the voltage on the given pin and outputs its value as an integer ranging from 0 to 1023.
• digitalRead(pin_number):This function reads the voltage on the given pin and outputs its value as either 0 or 1.
![Page 9: Introduction to Arduino - University of Southern Californiaviterbik12.usc.edu/.../07/Introduction-to-Arduino.pdf · What is the Arduino? • Arduino is an open source platform that](https://reader033.fdocuments.us/reader033/viewer/2022042316/5f05976d7e708231d413b8ec/html5/thumbnails/9.jpg)
Safety tips
• Never touch the heating element of the soldering
iron.
• Hold wires to be heated with tweezers or clamps.
• Keep the cleaning sponge wet during use.
• Always return the soldering iron to its stand when
not in use.
• Never put it down on the workbench.
• Turn unit off and unplug when not in use
![Page 10: Introduction to Arduino - University of Southern Californiaviterbik12.usc.edu/.../07/Introduction-to-Arduino.pdf · What is the Arduino? • Arduino is an open source platform that](https://reader033.fdocuments.us/reader033/viewer/2022042316/5f05976d7e708231d413b8ec/html5/thumbnails/10.jpg)
Blinking LED example
• Connect –ve terminal to GND
• Add resistor between +ve and 13
• Connect +ve terminal to 13
• Load the code called Blink_LED.ino
• Flat edge is –ve, long leg is +ve
![Page 11: Introduction to Arduino - University of Southern Californiaviterbik12.usc.edu/.../07/Introduction-to-Arduino.pdf · What is the Arduino? • Arduino is an open source platform that](https://reader033.fdocuments.us/reader033/viewer/2022042316/5f05976d7e708231d413b8ec/html5/thumbnails/11.jpg)
Connecting to light intensity sensor
• Connect GND to GND, +5 to 5V
• Connect V0 of the sensor to A0 of Arduino
• Load the code called AmbiLight.ino
• Open serial monitor
• What happens when you cover the sensor with your hand?
• What if you use a flashlight on the sensor?
![Page 12: Introduction to Arduino - University of Southern Californiaviterbik12.usc.edu/.../07/Introduction-to-Arduino.pdf · What is the Arduino? • Arduino is an open source platform that](https://reader033.fdocuments.us/reader033/viewer/2022042316/5f05976d7e708231d413b8ec/html5/thumbnails/12.jpg)
Let’s combine them together
• Can you turn the LED on when it gets dark?
![Page 13: Introduction to Arduino - University of Southern Californiaviterbik12.usc.edu/.../07/Introduction-to-Arduino.pdf · What is the Arduino? • Arduino is an open source platform that](https://reader033.fdocuments.us/reader033/viewer/2022042316/5f05976d7e708231d413b8ec/html5/thumbnails/13.jpg)
How could this be used in real world?
![Page 14: Introduction to Arduino - University of Southern Californiaviterbik12.usc.edu/.../07/Introduction-to-Arduino.pdf · What is the Arduino? • Arduino is an open source platform that](https://reader033.fdocuments.us/reader033/viewer/2022042316/5f05976d7e708231d413b8ec/html5/thumbnails/14.jpg)
Output devices (Actuators)
![Page 15: Introduction to Arduino - University of Southern Californiaviterbik12.usc.edu/.../07/Introduction-to-Arduino.pdf · What is the Arduino? • Arduino is an open source platform that](https://reader033.fdocuments.us/reader033/viewer/2022042316/5f05976d7e708231d413b8ec/html5/thumbnails/15.jpg)
Last exercise
• Can you modify the code to give an alarm when it is too bright?
![Page 16: Introduction to Arduino - University of Southern Californiaviterbik12.usc.edu/.../07/Introduction-to-Arduino.pdf · What is the Arduino? • Arduino is an open source platform that](https://reader033.fdocuments.us/reader033/viewer/2022042316/5f05976d7e708231d413b8ec/html5/thumbnails/16.jpg)
Sensors are everywhere
• Your phone has a lot of sensors. Can you name a few?
• What are they used for?
• What about wearable devices?
![Page 17: Introduction to Arduino - University of Southern Californiaviterbik12.usc.edu/.../07/Introduction-to-Arduino.pdf · What is the Arduino? • Arduino is an open source platform that](https://reader033.fdocuments.us/reader033/viewer/2022042316/5f05976d7e708231d413b8ec/html5/thumbnails/17.jpg)
Sensors in Civil Engineering
• Structural Health Monitoring
• Understanding how people use spaces
• Monitoring pollution
• Monitoring indoor temperatures/lighting
• Energy consumption measurement
![Page 18: Introduction to Arduino - University of Southern Californiaviterbik12.usc.edu/.../07/Introduction-to-Arduino.pdf · What is the Arduino? • Arduino is an open source platform that](https://reader033.fdocuments.us/reader033/viewer/2022042316/5f05976d7e708231d413b8ec/html5/thumbnails/18.jpg)
Useful Resources
• For purchasing sensors/ useful tutorials - www.adafruit.com
• Tutorial Series for Arduino – Jeremy Blum -https://www.youtube.com/watch?v=fCxzA9_kg6s&list=PLA567CE235D39FA84
• Cool Project ideas – Arduino Project Hub -https://create.arduino.cc/projecthub
• Just google – you will find plenty more