Introduction to ArduinoAshrant Aryal
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
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
Basics of electric circuits
• Current is measured in Amperes (Amp)
• Voltage is measured in Volts
• Resistance is measured in Ohm
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)
Code Structure
void setup() {
// put your setup code here, to run once:
}
void loop() {
// put your main code here, to run repeatedly:
}
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.
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.
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
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
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?
Let’s combine them together
• Can you turn the LED on when it gets dark?
How could this be used in real world?
Output devices (Actuators)
Last exercise
• Can you modify the code to give an alarm when it is too bright?
Sensors are everywhere
• Your phone has a lot of sensors. Can you name a few?
• What are they used for?
• What about wearable devices?
Sensors in Civil Engineering
• Structural Health Monitoring
• Understanding how people use spaces
• Monitoring pollution
• Monitoring indoor temperatures/lighting
• Energy consumption measurement
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