BASIC ARDUINO WORKSHOP Mr. Aldwin and Mr. Bernardo 1
BASIC ARDUINO WORKSHOP Course Goals Introduce Arduino Hardware and Understand Input Software and Output Create simple project 2
Arduino Open-source electronics platform based on easy-to-use hardware and software. Reads inputs like sensor, button, text Create action as output by activating a motor, turning on an light, sending messages. 3
Founders of Arduino Originally started as a research project by Massimo Banzi, David Cuartielles, Tom Igoe, Gianluca Martino, and David Mellis at the Interaction Design Institute of Ivrea Casey Reas and Ben Fry as well as a thesis project by Hernando Barragan about the Wiring board. 4
Sample projects 5
Software www.arduino.cc 6
Installation https://www.arduino.cc/en/main/software 7
PORT www.arduino.cc 8
BUILT-IN EXAMPLES www.arduino.cc 9
Serial Monitor Serial Monitor www.arduino.cc 10
BASIC STRUCTURE 11
Basic Structure 1 2 3 4 5 6 7 void setup(){ void loop(){ 12
Hardware Reset DIGITAL PINS 0-13 PWM PINS ~ USB ANALOG PIN A0-A5 16MHZ Crystal POWER PINS ATMEGA 328 9V www.arduino.cc 13
pinmode void setup(){ USB pinmode(13, OUTPUT); pinmode(7, INPUT); 9V ATMEL 328 www.arduino.cc 14
Software Digital output Digital input Analog output Analog input 0 HIGH or LOW 0 or 5V HIGH/LOW 0 or 5V 5 Volts PWM 0 to 5V 0 1 2 3 4 5 https://www.arduino.cc 15
Software Digital output Digital input HIGH or LOW 0 or 5V HIGH/LOW 0 or 5V digitalwrite(13,high); digitalwrite(13,low); digitalread(12); Analog output Analog input PWM 5 Volts analogwrite(11); 0 0 to 5V analogread(a1); 0 1 2 3 4 5 https://www.arduino.cc 16
DIGITAL OUTPUT digitalwrite() 17
Digital OUTPUT 1 2 3 4 5 6 7 8 9 void setup(){ pinmode(13, OUTPUT); void loop(){ digitalwrite(13,high); delay(1000); digitalwrite(13,low); delay(1000); Resistor 330 ohms 18
Digital OUTPUT-Motor test 1 2 3 4 5 6 7 8 9 void setup(){ pinmode(13, OUTPUT); void loop(){ digitalwrite(13,high); delay(1000); digitalwrite(13,low); delay(1000); Recommended to use motor driver(l293d). This testing is for small 5volts motor only 19
Sign in www.tinkercad 20
Login thru www.tinkercad.com 21
Activity 1 -OUTPUT 1. Login thru 2. www.tinkercad.com 2. Select Circuits Start the project 22
Activity 1 TRAFFIC LIGHT 1. Red for 5 seconds 2. Red blink for 1 second 3. Yellow for 2 seconds 4. Yellow blink for 1 second 5. Green for 5 seconds 6. Green blink for 1 second 7. Yellow for 5 seconds 8. Yellow blink for 1 second 9. Loop 23
DIGITAL INPUT digitalread() 24
1 2 3 4 5 6 7 8 9 void setup(){ Serial.begin(9600); pinmode(2, INPUT); void loop(){ int buttonstate = digitalread(2); Serial.println(buttonState); delay(1000); PULL UP 25
1 2 3 4 5 6 7 8 9 void setup(){ Serial.begin(9600); pinmode(2, INPUT); void loop(){ int buttonstate = digitalread(2); Serial.println(buttonState); delay(1000); PULL DOWN 26
BUILT-IN PULLUP 1 2 3 4 5 6 7 8 9 void setup(){ Serial.begin(9600); pinmode(2, INPUT_PULLUP); void loop(){ int buttonstate = digitalread(2); Serial.println(buttonState); delay(1000); 27
Digital Input, Output, Serial 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 void setup(){ Serial.begin(9600); pinmode(13, OUTPUT); pinmode(2, INPUT); void loop(){ int buttonstate = digitalread(2); Serial.println(buttonState); if (buttonstate == HIGH) { digitalwrite(13,high); if (buttonstate == LOW) { delay(1000); digitalwrite(13,low); delay(1000); 28
digitalread / pull-down 1 2 3 4 5 6 7 8 9 10 11 12 13 void setup(){ pinmode(13, OUTPUT); pinmode(2, INPUT); void loop(){ int buttonstate = digitalread(2); if (buttonstate == HIGH) { digitalwrite(13,high); else { delay(1000); digitalwrite(13,low); delay(1000); 29
Activity 2 -INPUT 1. Press the button to turn on the red LED on pin 13 2. Release the button to turn on the green LED on pin 7 30
ANALOG INPUT/OUTPUT(PWM) analogread() analogwrite() 31
Analog Input, Output, Serial 1 void setup(){ 2 Serial.begin(9600); 3 pinmode(11, OUTPUT); 4 pinmode(a0, INPUT); 5 6 void loop(){ 7 int input1= analogread(a0); 8 Serial.println(input1); 9 analogwrite(11,input1/4); 10 LED Dimmer 32
Analog Input, Output, Serial 1 void setup(){ 2 Serial.begin(9600); 3 pinmode(11, OUTPUT); 4 pinmode(a0, INPUT); 5 6 void loop(){ 7 int input1= analogread(a0); 8 Serial.println(input1); 9 analogwrite(11,input1/4); 10 33
Serial INPUT void setup() { Serial.begin(9600); pinmode(13,output); void loop() { String msg=""; if (Serial.available()>0){ while (Serial.available()>0){ msg=msg+char(serial.read()); delay(250); Serial.println(msg); if (msg=="1234"){ digitalwrite(13,high); if (msg=="43210"){ digitalwrite(13,low); 34
THANK YOU 35
ARDUINO WORKSHOP ACTIVITY 1 Step 1. Open www.tinkercad.com Step 5. Select resistor and LED Step 8. Write the program Step 2. Select social providers Write the program here Step 6. Select Arduino and complete the circuit DIGITAL INPUT AND OUTPUT PROGRAM Step 9. Select Start simulation Step 3. Sign in using social provider Step 10. Observe the circuit if the output is correct To edit the code, press stop the simulation Step 4. Select Circuits then Create new Circiut Step 7. Select Code to start the program
ARDUINO WORKSHOP ACTIVITY 2 Step 1. Open www.tinkercad.com Step 5. Select resistor and LED Step 8. Write the program Write the program here Step 2. Select social providers Step 6. Select Arduino and complete the circuit Step 9. Select Start simulation Step 3. Sign in using social provider Step 10. Observe the circuit if the output is correct To edit the code, press stop the simulation Step 4. Select Circuits then Create new Circiut Step 7. Select Code to start the program 1. Press the button to turn on the red LED on pin 2. Release the button to turn on the green LED on pin 7 3. Display the button status in the serial monitor
ARDUINO QUICK REFERENCE www.arduino.cc Arduino is an open-source electronics platform based on easy-to-use hardware and software. Arduino boards are able to read inputs like sensor, button, text and create action as output by activating a motor, turning on an light, sending messages. TINKERCAD.COM- ARDUINO AND ELECTRONIC SIMULATOR www.tinkercad.com Built your project and test different electronic components including Arduino uno using Autodesk online simulator LEARN MORE USING EXAMPLE www.arduino.cc/en/tutorial/builtinexamples www.arduino.cc/en/main/software The open-source Arduino Software (IDE) makes it easy to write code and upload it to the board. It runs on Windows, Mac OS X, and Linux. The environment is written in Java and based on Processing and other open-source software. //this program blink LED at pin 13 void setup(){ pinmode(13,output); void loop(){ digitalwrite(13,high); //LED on delay(1000); //delay 1 second digitalwrite(13,low); //LED off HARDWARE DIGITAL INPUT digitalread(11); read whether it receive HIGH or LOW ANALOG INPUT analogread(a0) ; read voltage from 0-5 volts (A0-A5) ANALOG OUTPUT analogwrite(10, 0-255); give pwm signal (pwm 3,5,6,9,10,11 pins) Pulse Width Modulation or PWM, is a technique for getting analog results with digital means. Digital control is used to create a square wave, a signal switched between on and off. This on-off pattern can simulate voltages in Volts) between full on (5 and off (0 Volts) by changing the portion of the time the signal spends on versus the time that the signal spends off. Serial.println(analogRead(A0)); SERIAL MONITOR EXAMPLE www.arduino.cc/en/main/products //Program will read input and display to serial void setup(){ pinmode(10,input); Serial.begin(9600); //baud rate speed void loop(){ int button1=digitalread(10); Serial.println(button1); read analog pin A0 and display to serial DIGITAL OUTPUT PROGRAM //program to blink LED at pin 13 void setup(){ pinmode(13,output); void loop(){ digitalwrite(13,high); //LED on delay(1000); //delay 1 second digitalwrite(13,low); //LED off DIGITAL INPUT AND OUTPUT PROGRAM // program that reads input and turn on the LED void setup(){ pinmode(10,input_pullup); pinmode(13,output); void loop(){ int button1=digitalread(10); if (button1==1) { // button is pressed digitalwrite(13,high); //LED on else if (button1==0) { // button is not pressed digitalwrite(13,low); //LED off ANALOG INPUT AND OUTPUT (PWM) PROGRAM //LED dimmer or motor speed control void setup(){ pinmode(a1,input); pinmode(9,output); //pwm pin Serial.begin(9600); void loop(){ int button1=analogread(a1); Serial.println(button1); analogwrite(9,button1/4);