Download presentation
Presentation is loading. Please wait.
Published byMoses Sanders Modified over 6 years ago
1
3.0 ARDUINO WORKSHOP PRESENTATION FOR STUDENTS IN 4º DEGREE OF COMPULSORY SECONDARY EDUCATION 3.0
2
WHAT IS ARDUINO? 3.0 Arduino is mainly a free hardware CONTROL SYSTEM.
It’s made up of: A printed circuit board fitted out with electronic components connected with availability of: Analog Input and Outputs and Digital Input and Outputs . A software development environment 3.0
3
WHAT IS ARDUINO? The idea is to use Arduino as a programmable device to be capable to acquire data from sensors and to emit, as a consequence, signals to the actuators Actuator 1 Sensor 1 Actuator 2 Sensor 2 Sensor 3 Actuator n Sensor n 3.0
4
Note that each terminal has a specific function
Arduino connections Digital outputs Digital inputs Observe the Arduino different connections and how they are distributed. Note that each terminal has a specific function USB Connector Power Supply connector (6-12 V) Supply pins Analog inputs 3.0
5
The interface development environment
To make Arduino knowing how to carry out a task, a program must be written YOU WOULD HAVE TO DOWNLOAD AND SET UP IN THE COMPUTER THE ARDUINO INTERFACE DEVELOPMENT ENVIRONMENT IDE To program Arduino, it’s neccesary to download from Arduino web page the interface development environment (IDE), available for Windows, MAC and LINUX operating systems. 3.0
6
The interface development environment
1. Connect Arduino board to USB port in the computer and load in IDE the provided example BLINK 2. CONNECT THE LED ANODE TO PIN 13 AND THE CATHODE TO GROUND (GND) 3. Observe how the LED diode starts blinking. Now, fin in the program the function DELAY and modify the numerical value. You will realize the LED blinking faster and slower depending on the assigned value. 3.0
7
Connecting hardware To connect the devices and parts of a circuit, you will have to use a general purpose printed circuit board or a prototype board (Protoboard). OBSERVE THIS EXAMPLE Scheme of an electric circuit to control the switch on of a LED diode, according to the light level detected by a LDR sensor. INPUT CIRCUIT OUTPUT CIRCUIT ARDUINO 3.0
8
And connect them according the following scheme:
Connecting hardware You would have to get one 10K resistor, one 470 ohm resistor, a LED diode and a LDR sensor And connect them according the following scheme: INPUT CIRCUIT OUTPUT CIRCUIT ARDUINO Vcc Output signal Input signal GND 3.0
9
Connecting hardware Make the wiring list 3.0
Observe the wiring connections to Arduino Make the wiring list Make a list of wires connected between components and Arduino pins INPUT CIRCUIT OUTPUT CIRCUIT 3.0
10
WRITING SOFTWARE Write the following code and notice the expressions used in each line. Try to understand the program. // Light detection system // Using a LDR as an input sensor // and a LED connected to a digital output int LED = 11; // LED is in pin 11 int LDR = A0; //Sensor in the input A0 int LDR_val = 0; //Variable to store the read value int UMBRAL = 500; // Threshold to 500 void setup() { pinMode(LED, OUTPUT); // Define LED pin as an output } void loop() LDR_val = analogRead(LDR); // Read the light level if (LDR_val >= UMBRAL) // Checking if its low level digitalWrite(LED, LOW); // if Low then the LED switches off else if (LDR_val < UMBRAL) // If level is high... digitalWrite(LED, HIGH); // LED turns on // Light detection system // Using a LDR as an input sensor // and a LED connected to a digital output int LED = 11; // LED is in pin 11 int LDR = A0; //Sensor in the input A0 int LDR_val = 0; //Variable to store the read value int UMBRAL = 500; // Threshold to 500 void setup() { pinMode(LED, OUTPUT); // Define LED pin as an output } void loop() LDR_val = analogRead(LDR); // Read the light level if (LDR_val >= UMBRAL) // Checking if its low level digitalWrite(LED, LOW); // if Low then the LED switches off else if (LDR_val < UMBRAL) // If level is high... digitalWrite(LED, HIGH); // LED turns on 3.0
11
Understanding software
Assigning numerical values to constant expressions (LED, LDR, LDR_val and UMBRAL) // Light detection system // Using a LDR as an input sensor // and a LED connected to a digital output int LED = 11; // LED is in pin 11 int LDR = A0; //Sensor in the input A0 int LDR_val = 0; //Variable to store the read value int UMBRAL = 500; // Threshold to 500 void setup() { pinMode(LED, OUTPUT); // Define LED pin as an output } void loop() LDR_val = analogRead(LDR); // Read the light level if (LDR_val >= UMBRAL) // Checking if its low level digitalWrite(LED, LOW); // if Low then the LED switches off else if (LDR_val < UMBRAL) // If level is high... digitalWrite(LED, HIGH); // LED turns on Function Setup = Preparing the program. This function runs only once and is used to configure pinMode Function Loop = it includes the code to be continuously running (reading board inputs, outputs, etc.) 3.0
12
The types of data in Arduino
Arduino allows handling the following types of data: BYTE It stores an 8 bits numerical value, in a range of 0 to 255 INT It stores an integer value in a range a 32,767 to -32,768. . LONG Long Integer value stored in 32 bits in a range of 2,147,483,647 to -2,147,483,648. FLOAT Floating-point type stored in 32 bits with a range of E+38 to E+38. Arrays: This is a set of values to be accesed with a number of index ( the first value of the index is 0). Observe this example of use: Definition int myArray[5]; // it declares an array of 6 integers Assignament of the fourth component myArray[3] = 10; Definition and assignment of several values int myArray[] = {value0, value1, value2...} Recovering the fourth component and assigning to variable x x = myArray[3] 3.0
13
Functions with the inputs and outputs in Arduino
Function pinMode(pin, mode) It’s used in the función setup() to determine a pin behaviour as an INPUT or as an OUTPUT. Arduino’s pins work by default as INPUTS. This means that it’s not neccesary to declare the behaviour of pins as INPUTS when the function pinMode() is being used. For instance, the expression pinMode(11, OUTPUT); configures pin number 11 as an output. 3.0
14
Functions with the inputs and outputs in Arduino
Function digitalRead(pin) It returns the value of a specific digital pin. It returns a (HIGH) or a (LOW) value. The pin can be specified with a variable or a constant (0-13). For example in the expression V = digitalRead (Pin); the digital value of the variable Pin is moved to the variable V. Function digitalWrite(pin, value) A HIGH level state or a LOW level state is written in the position PIN. The state will be written in the position VALUE. Instead of a constant number, a variable can be specified. For instance, to achieve a HIGH logic level state to appear in pin 11 the expression digitalWrite(11, HIGH); will be used. 3.0
15
Functions with the inputs and outputs in Arduino
Function analogRead(pin) By means of analogRead, a pin analog value is read with a resolution of 10 bits (210 combinations means 1024 different values). This functions is only applicable in analog pins (pin 0 to 5). The resulting value is an integer from 0 to Analog pins, as a difference with digital ones, do no need to be declared as INPUT or OUTPUT. Function analogWrite(pin, value) An analog value is written. This function is active for pins 3, 5, 6, 9, 10, 11. For instance, the expression analogWrite(3, v); indicates that “v” value will be written in the analog 3 pin. A value between 0 and 255 can be specificied (what corresponds to a 8 bits resolution). The analog range is from 0 volts to 5 volts. As a consequence, a value 0 generates 0 volts while a value 255 generates 5 volts. For values in this range, the pin alternates rapidly between 0 V and 5 V, the higher the value, the longer the HIGH logic level state is established. For example, a value of 64 will be LOW three quarters of the duration of the period, establishing as HIGH only a quarter. The value 128 will be at LOW half of the time and HIGH the other half. A value of 192 will be LOW one quarters and HIGH three quarters of the period. 3.0
16
Functions with the inputs and outputs in Arduino
Time and mathematical functions Function delay(ms) It makes a pause in the program of a duration specified in the parameter ms between 1 and 1000 milliseconds.. Function millis() It returns a value with the time in milliseconds that Arduino is executing the current program. After 9 hours, the counter is reset. Function min(x,y) It returns the minimal value from x and y. Function max(x,y) It returns the maximal value from x and y. 3.0
17
Functions with the inputs and outputs in Arduino
Random functions Function random(max) it turns a random value between 0 and the specified max valuedevuelve un valor aleatorio entre 0 y el número max Función random(min, max) devuelve un valor aleatorio entre los valores min y max Función randomSeed(seed) It specifies a initial value (seed) as the starting point for the function ramdom() to provide a value. This value has to be really ramdom and by that, function millis() or even analogRead() could be used in case of reading electric noise from an analog input. 3.0
18
Conditional syntaxis The used syntaxis to define a condition is almost universal for all types of programming languages. The structure proposes a logic challenge with two possible answer (YES = TRUE) or (NO=FALSE) Challenge or question NO YES Action B Action A 3.0
19
ARE YOU READY TO ANSWER SOME RECOGNITION QUESTIONS?
Conditional syntaxis Observe this algorithmic graph and the following text and look at the Arduino code ARE YOU READY TO ANSWER SOME RECOGNITION QUESTIONS? Challenge or question NO if (LDR_val >= UMBRAL) // Check is the level is LOW { digitalWrite(LED, LOW); // If LOW, LED turn off } else if (LDR_val < UMBRAL) // If level is HIGH .. digitalWrite(LED, HIGH); // LED will turn on YES Action B Action A 3.0
20
What is the challenge or question in this code?
Conditional syntaxis Observe this algorithmic graph and the following text and look at the Arduino code What is the challenge or question in this code? Challenge or question NO if (LDR_val >= UMBRAL) // Check is the level is LOW { digitalWrite(LED, LOW); // If LOW, LED turn off } else if (LDR_val < UMBRAL) // If level is HIGH .. digitalWrite(LED, HIGH); // LED will turn on YES Action B Action A 3.0
21
What is the challenge or question in this code?
Conditional syntaxis Observe this algorithmic graph and the following text and look at the Arduino code What is the challenge or question in this code? Challenge or question NO if (LDR_val >= UMBRAL) // Check is the level is LOW { digitalWrite(LED, LOW); // If LOW, LED turn off } else if (LDR_val < UMBRAL) // If level is HIGH .. digitalWrite(LED, HIGH); // LED will turn on YES Action B Action A 3.0
22
What does it happens if the challenge is TRUE?
Conditional syntaxis Observe this algorithmic graph and the following text and look at the Arduino code What does it happens if the challenge is TRUE? Challenge or question NO if (LDR_val >= UMBRAL) // Check is the level is LOW { digitalWrite(LED, LOW); // If LOW, LED turn off } else if (LDR_val < UMBRAL) // If level is HIGH .. digitalWrite(LED, HIGH); // LED will turn on YES Action B Action A 3.0
23
What does it happens if the challenge is TRUE?
Conditional syntaxis Observe this algorithmic graph and the following text and look at the Arduino code What does it happens if the challenge is TRUE? Challenge or question NO if (LDR_val >= UMBRAL) // Check is the level is LOW { digitalWrite(LED, LOW); // If LOW, LED turn off } else if (LDR_val < UMBRAL) // If level is HIGH .. digitalWrite(LED, HIGH); // LED will turn on YES Action B Action A 3.0
24
What is the opposite case of the challenge?
Conditional syntaxis Observe this algorithmic graph and the following text and look at the Arduino code What is the opposite case of the challenge? Challenge or question NO if (LDR_val >= UMBRAL) // Check is the level is LOW { digitalWrite(LED, LOW); // If LOW, LED turn off } else if (LDR_val < UMBRAL) // If level is HIGH .. digitalWrite(LED, HIGH); // LED will turn on YES Action B Action A 3.0
25
What is the opposite case of the challenge?
Conditional syntaxis Observe this algorithmic graph and the following text and look at the Arduino code What is the opposite case of the challenge? Challenge or question NO if (LDR_val >= UMBRAL) // Check is the level is LOW { digitalWrite(LED, LOW); // If LOW, LED turn off } else if (LDR_val < UMBRAL) // If level is HIGH .. digitalWrite(LED, HIGH); // LED will turn on YES Action B Action A 3.0
26
What does it happen if the challenge is FALSE?
Conditional syntaxis Observe this algorithmic graph and the following text and look at the Arduino code What does it happen if the challenge is FALSE? Challenge or question NO if (LDR_val >= UMBRAL) // Check is the level is LOW { digitalWrite(LED, LOW); // If LOW, LED turn off } else if (LDR_val < UMBRAL) // If level is HIGH .. digitalWrite(LED, HIGH); // LED will turn on YES Action B Action A 3.0
27
What does it happen if the challenge is FALSE?
Conditional syntaxis Observe this algorithmic graph and the following text and look at the Arduino code What does it happen if the challenge is FALSE? Challenge or question NO if (LDR_val >= UMBRAL) // Check is the level is LOW { digitalWrite(LED, LOW); // If LOW, LED turn off } else if (LDR_val < UMBRAL) // If level is HIGH .. digitalWrite(LED, HIGH); // LED will turn on YES Action B Action A 3.0
28
Review the assembly and the program code and explain how this example works
Software Hardware int ledPin= 13; // pin 13 is called LED int inPin= 5; // pin 5 is called inPin (it’s the pushbutton) int val= 0; // variable ro read the pin status void setup() { pinMode(ledPin, OUTPUT);// declare LED as an OUTPUT pinMode(inPin, INPUT); // declare pushbutton as an INPUT } void loop(){ val= digitalRead(inPin);// read the input value if(val== HIGH) {// check if the read value is “1” (pressed pushbutton) digitalWrite(ledPin, LOW);// turns LED OFF } else{ digitalWrite(ledPin, LOW);// LED blinking delay(200); // makes a delay digitalWrite(ledPin, HIGH); //turns LED ON delay(200); } 3.0
29
Review the assembly and the program code and explain how this example works
Software Hardware int ledPin= 13; // pin 13 is called LED int inPin= 5; // pin 5 is called inPin (it’s the pushbutton) int val= 0; // variable ro read the pin status void setup() { pinMode(ledPin, OUTPUT);// declare LED as an OUTPUT pinMode(inPin, INPUT); // declare pushbutton as an INPUT } void loop(){ val= digitalRead(inPin);// read the input value if(val== HIGH) {// check if the read value is “1” (pressed pushbutton) digitalWrite(ledPin, LOW);// turns LED OFF } else{ digitalWrite(ledPin, LOW);// LED blinking delay(200); // makes a delay digitalWrite(ledPin, HIGH); //turns LED ON delay(200); } THE ANSWER IS: When pushbutton is pressed ( Input 5 to LOW value) OUTPUT 13 is intermitently ON and OFF. This makes Arduino to behave as an alarm when somebody is pressing the pussbutton, emitting a blinking signal in the visual actuator (LED). 3.0
30
3.0 ARDUINO WORKSHOP Now, experiment in class and practice with other assemblies.. Start up now to use your Arduino board to develop your innovation!!!
Similar presentations
© 2025 SlidePlayer.com. Inc.
All rights reserved.