For our next project we will make a stop light. It's simple and fun to do.
For that we need:
-Arduino One.
-A Protoboard.
-A red LED 3mm.
-A yellow LED 3mm.
- A green LED 3mm.
Three 220Ω resistors.
-stranded To connect everything.
Once we have everything, we do our assembly according to the following scheme.
Use digital pins 2 (red), 4 (yellow) and 7 (green). When connecting LEDs, you must keep in mind that have polarity, so you have to put them to work well. In LEDs the short leg, or the side that is oblate, is the negative and will be connected to ground (GND on the plate) through a resistance. The long leg, or rounded side is positive and will be connected to the corresponding pin Arduino.
Once assembled, we will open our Arduino IDE and write the program.
//** Definitions **//
int red = 2; // Define the value of the pin for the red LED
int yellow = 4; // Define the value of the pin for the yellow LED
int green = 7; // Define the value of the pin for the green LED
** // ** // Program
void setup ()
{
pinMode (green, OUTPUT); // Declare the green pin output
pinMode (yellow, OUTPUT); // declare the output pin yellow
pinMode (red, OUTPUT); // Declare red pin output
}
void loop ()
{
digitalWrite (green, HIGH); // Turn on the red light
delay (2000); // Waited two seconds
digitalWrite (green, LOW); // Turn off the red LED
delay (500); // We expect second half
digitalWrite (yellow, HIGH); // Light the yellow LED
delay (2000); // Waited two seconds
digitalWrite (yellow, LOW); // Turn off the yellow LED
delay (500); // We expect second half
digitalWrite (red, HIGH); // Turn on the green LED
delay (2000); // Waited two seconds
digitalWrite (red, LOW); // Turn off the green LED
delay (500); // We expect second half
}
With the ruling int we are declaring an integer numeric variable, so that it can use later in our code.
The delay command causes the program to stop a certain time. This will define, in milliseconds, within parentheses.
The pinMode and digitalWrite functions will be explained in the next post, outings, with detail.
I hope ye fun with this post and start out to get him the bug to the Arduino world.
https://www.dropbox.com/s/4smz48bakilepqd/Semforo_con_Arduino_Prctica_para_secundaria%28bajaryoutube.com%29.mp4?dl=0
Health and Republic.
A new project.
jueves, 14 de abril de 2016
Arduino digital entries.
The material we need is:
-Arduino Uno or similar.
- A PC with the Arduino environment correctly installed and configured.
-A plate breadboard, an LED.
-A button.
-Two resistances of 330 ohms.
-Some cables protobard.
Often electronics need to know if a light is on or off, if someone pressed a button or if a door has been left open or closed.
This type of signals ON / OFF, YES / NO, TRUE / FALSE, 0/1 are called digital, and we can handle them with pins 0 to 13 and therefore speak Arduino digital pins.
Many of the sensors and actuators we see in the real world are digital.
Arduino digital pins can be used as all or nothing outputs to turn on an LED. In the same way we can read values, all or nothing from the outside world.
In this session we will see that Arduino digital pins can be used for both input and output. Let's read a button or external button and let an LED on or off depending on the button is pressed or not.
We mount a circuit with an LED and connected resistance to digital pin 10 Arduino, as we saw in the previous and also one second circuuito with S1 button connected to pin 6 with a resitencia as shown in the following diagram sessions.
While we do not press S1 Arduino pin 6 it is connected to 5V through resistor R3 forcing a high voltage reading (HIGH). Instead when we press S1 close the circuit Ground pin 6 to thus read low, LOW voltage. In both cases we have a defined voltage value.
If we did not put the resistor R3, pressing S1 would read correctly LOW on pin 6. But when you stop pressing S1 pin 6 would be in a floating state, which is neither HIGH nor LOW but undetermined. As this is unacceptable in digital circuits we force a high reading with R3.
And here is the outline for breadboard circuit:
Let's start doing a program that makes the LED lights up when you press the button and turns off when you let go. To do this we will ask to configure the Arduino digital pin 10 (D10) as an output to drive the LED, and digital pin 6 (D6) as input to read the button.
Usually in simple programs simply put the pin number in the instructions. But as the program is complicated this tends to cause more difficult bugs.
So it is customary to define variables with pin numbers we use, so we can modify them playing in one place (and not having to search through the program). Let's write this a little more elegantly:
int LED = 10;
int button = 6;
void setup ()
{
pinMode (LED, OUTPUT); // LED output
pinMode (button, INPUT); // Button as input
}
We saw enough to turn the use digitalWrite (LED, HIGH) LED. To read a button you can do something similar: digitalRead (button). Let's see how it could be our loop
void loop()
{
int valor = digitalRead(boton) ; // We read the value of Button in value
digitalWrite( LED, valor) ;
}
How could we do otherwise, the LED is turned on and off by pressing else? It would suffice to write LED opposite of what we read on the button.
There is an operator that does that exactly the negation operator "! ". If given value x is HIGH, then! X is LOW and vice versa.
In fact these operations are so frequent that C ++ incorporates a type called bool or Boolean TRUE only accepts two values (true) and FALSE and are fully equivalent to 1/0, and HIGH / LOW
This new program would be something like this:
void loop ()
{
int value = digitalRead (button); // Read the value of Button in value
digitalWrite (LED, value!); // Write value LED
}
We have defined as a bool value, because we can use the value of high voltage and low value TRUE and FALSE.
If the button is not pressed the D6 read TRUE and therefore will LED to FALSE. Otherwise it will turn on the LED.
In fact we could write a curious variant of blinking LED using the negation operator:
void loop ()
{
bool = digitalRead (LED);
digitalWrite (LED, value!);
delay (1000);
}
The first line reads the status LED and invests in the second line, then write this in LED. And while we beat a record, we can write the blinking led in only two lines:
void loop ()
{
digitalWrite (LED, digitalRead (LED)!);
delay (1000);
}
(The instructions within parentheses are executed before those outside of them. So the digitalRead runs before the digitaWrite.)
-Arduino Uno or similar.
- A PC with the Arduino environment correctly installed and configured.
-A plate breadboard, an LED.
-A button.
-Two resistances of 330 ohms.
-Some cables protobard.
Often electronics need to know if a light is on or off, if someone pressed a button or if a door has been left open or closed.
This type of signals ON / OFF, YES / NO, TRUE / FALSE, 0/1 are called digital, and we can handle them with pins 0 to 13 and therefore speak Arduino digital pins.
Many of the sensors and actuators we see in the real world are digital.
Arduino digital pins can be used as all or nothing outputs to turn on an LED. In the same way we can read values, all or nothing from the outside world.
In this session we will see that Arduino digital pins can be used for both input and output. Let's read a button or external button and let an LED on or off depending on the button is pressed or not.
We mount a circuit with an LED and connected resistance to digital pin 10 Arduino, as we saw in the previous and also one second circuuito with S1 button connected to pin 6 with a resitencia as shown in the following diagram sessions.
While we do not press S1 Arduino pin 6 it is connected to 5V through resistor R3 forcing a high voltage reading (HIGH). Instead when we press S1 close the circuit Ground pin 6 to thus read low, LOW voltage. In both cases we have a defined voltage value.
If we did not put the resistor R3, pressing S1 would read correctly LOW on pin 6. But when you stop pressing S1 pin 6 would be in a floating state, which is neither HIGH nor LOW but undetermined. As this is unacceptable in digital circuits we force a high reading with R3.
And here is the outline for breadboard circuit:
Let's start doing a program that makes the LED lights up when you press the button and turns off when you let go. To do this we will ask to configure the Arduino digital pin 10 (D10) as an output to drive the LED, and digital pin 6 (D6) as input to read the button.
Usually in simple programs simply put the pin number in the instructions. But as the program is complicated this tends to cause more difficult bugs.
So it is customary to define variables with pin numbers we use, so we can modify them playing in one place (and not having to search through the program). Let's write this a little more elegantly:
int LED = 10;
int button = 6;
void setup ()
{
pinMode (LED, OUTPUT); // LED output
pinMode (button, INPUT); // Button as input
}
We saw enough to turn the use digitalWrite (LED, HIGH) LED. To read a button you can do something similar: digitalRead (button). Let's see how it could be our loop
void loop()
{
int valor = digitalRead(boton) ; // We read the value of Button in value
digitalWrite( LED, valor) ;
}
How could we do otherwise, the LED is turned on and off by pressing else? It would suffice to write LED opposite of what we read on the button.
There is an operator that does that exactly the negation operator "! ". If given value x is HIGH, then! X is LOW and vice versa.
In fact these operations are so frequent that C ++ incorporates a type called bool or Boolean TRUE only accepts two values (true) and FALSE and are fully equivalent to 1/0, and HIGH / LOW
This new program would be something like this:
void loop ()
{
int value = digitalRead (button); // Read the value of Button in value
digitalWrite (LED, value!); // Write value LED
}
We have defined as a bool value, because we can use the value of high voltage and low value TRUE and FALSE.
If the button is not pressed the D6 read TRUE and therefore will LED to FALSE. Otherwise it will turn on the LED.
In fact we could write a curious variant of blinking LED using the negation operator:
void loop ()
{
bool = digitalRead (LED);
digitalWrite (LED, value!);
delay (1000);
}
The first line reads the status LED and invests in the second line, then write this in LED. And while we beat a record, we can write the blinking led in only two lines:
void loop ()
{
digitalWrite (LED, digitalRead (LED)!);
delay (1000);
}
(The instructions within parentheses are executed before those outside of them. So the digitalRead runs before the digitaWrite.)
martes, 12 de abril de 2016
Circuit with multiple LEDs.
For this circuit need:
- Arduino Uno or similar. This session accepts any other model Arduino.Un PC with the Arduino environment correctly installed and configured.
- A breadboard.
- 8 LEDs.
- A 330 ohms resistor.
- Some cables Protoboard.
If we wanted to ride a circuit that have 8 LEDs and in which the light is shifted from one another, one possibility would be repeated several times the same sequences of instructions already know.
For example if we connect various LEDs for different digital pins Arduino, we should declare our function setup () could be:
void setup ()
{
// Initialize the digital pins as an output
pinMode (13, OUTPUT);
pinMode (12, OUTPUT);
pinMode (11, OUTPUT);
..............................
pinMode (6, OUTPUT);
}
And turn our loop () should be repeated as often as LEDs have the game on and off each of the LEDs in sequence from the pin 13 to 6.
This solution is what could be described as brute force, but not very elegant, is laborious and probably would commit more than one error in writing it, because people tend to make mistakes doing boring repetitive tasks.
Instead computers are not bored and C ++ also offers a convenient way to indicate that you repeat something a set number of times. For this medium is the instruction that can be used in combination with a variable.
A variable is a container that can take multiple values, in our case will accept all values between 6 and 13.
C ++ requires us to declare the type of the variables before use. In our case we use the integer type int is written to indicate that this variable is numeric and integer, without decimals.
We will see that there are other types of variables. We will return to this issue in future sessions.
For example, to initialize in our setup () pins from 13 to 6 as outputs (required by our Arduino) could use the for statement as follows:
void setup ()
{
int i = 0; // Initialize the variable i as an integer
for (i = 6; i <14; i ++)
pinMode (i, OUTPUT);
}
Although the syntax seems complicated at first, you get used quickly. The important thing here is that for needs 3 parameters separated by a semicolon character.
These parameters are, in this order:
A variable that anger taking values according to a certain rule, and to which we assign an initial value. In this case: i = 6.
The cycle continues as long as this condition is met. In our case while i is less than 14, that is until 13: i <14
As you change the variable at each iteration. In our case i ++ it is C ++ ask to increase the variable i by one, at the end of each iteration.
With the same criteria we could write the loop (function) and Download:
void loop ()
{
int i = 0; // Initialize the variable i as an integer
for (i = 6; i <14; i ++)
{
digitalWrite (i, HIGH);
delay (500);
digitalWrite (i, LOW);
delay (500);
}
}
In session 3 code was very similar except that wrote the value 13 for the only pin that had a connected LED. Here we assign the pin with a variable i, which is taking the values of 6 to 13 for the pin.
The circuit diagram is very similar to the Session 3, except for the fact that we place on the breadboard 8 LEDs.
The only novelty is that since the function of the resistance is to limit the intensity of the current flowing through the circuit, and since all diodes have common ground, just a single resistor between this point and Ground.
When our program to lift the corresponding pin HIGH value, the associated LED lighting up circuit is closed.
Below are a connection scheme circuit in a breadboard.
This setup allows us to play with lights and lends itself to several different programs to achieve different effects.
For example, with the previous program 4.1, the effect is not exactly fantastic car because when we just iterate for, the program starts again from the beginning, which causes light to jump from pin 6 to pin 13.
So Could we make light bounce? Think about a bit.
Of course yes, it would suffice to use two for loops, similar to the following Download:
void loop () // Prog_4_2
{
for (int i = 6; i <14; i ++) // we define the variable i on the fly
{
digitalWrite (i, HIGH);
delay (500);
digitalWrite (i, LOW);
delay (500);
}
for (int i = 12; i> 6; i--) // define the variable i on the fly
{
digitalWrite (i, HIGH);
delay (500);
digitalWrite (i, LOW);
delay (500);
}
}
Another serious variant, make a ripple effect in which the lights go up leaving pre lit LEDs until the maximum and now shutting down the upper LEDs. We recommend trying to solve the problem as a challenge, before seeking a solution.
- Arduino Uno or similar. This session accepts any other model Arduino.Un PC with the Arduino environment correctly installed and configured.
- A breadboard.
- 8 LEDs.
- A 330 ohms resistor.
- Some cables Protoboard.
If we wanted to ride a circuit that have 8 LEDs and in which the light is shifted from one another, one possibility would be repeated several times the same sequences of instructions already know.
For example if we connect various LEDs for different digital pins Arduino, we should declare our function setup () could be:
void setup ()
{
// Initialize the digital pins as an output
pinMode (13, OUTPUT);
pinMode (12, OUTPUT);
pinMode (11, OUTPUT);
..............................
pinMode (6, OUTPUT);
}
And turn our loop () should be repeated as often as LEDs have the game on and off each of the LEDs in sequence from the pin 13 to 6.
This solution is what could be described as brute force, but not very elegant, is laborious and probably would commit more than one error in writing it, because people tend to make mistakes doing boring repetitive tasks.
Instead computers are not bored and C ++ also offers a convenient way to indicate that you repeat something a set number of times. For this medium is the instruction that can be used in combination with a variable.
A variable is a container that can take multiple values, in our case will accept all values between 6 and 13.
C ++ requires us to declare the type of the variables before use. In our case we use the integer type int is written to indicate that this variable is numeric and integer, without decimals.
We will see that there are other types of variables. We will return to this issue in future sessions.
For example, to initialize in our setup () pins from 13 to 6 as outputs (required by our Arduino) could use the for statement as follows:
void setup ()
{
int i = 0; // Initialize the variable i as an integer
for (i = 6; i <14; i ++)
pinMode (i, OUTPUT);
}
Although the syntax seems complicated at first, you get used quickly. The important thing here is that for needs 3 parameters separated by a semicolon character.
These parameters are, in this order:
A variable that anger taking values according to a certain rule, and to which we assign an initial value. In this case: i = 6.
The cycle continues as long as this condition is met. In our case while i is less than 14, that is until 13: i <14
As you change the variable at each iteration. In our case i ++ it is C ++ ask to increase the variable i by one, at the end of each iteration.
With the same criteria we could write the loop (function) and Download:
void loop ()
{
int i = 0; // Initialize the variable i as an integer
for (i = 6; i <14; i ++)
{
digitalWrite (i, HIGH);
delay (500);
digitalWrite (i, LOW);
delay (500);
}
}
In session 3 code was very similar except that wrote the value 13 for the only pin that had a connected LED. Here we assign the pin with a variable i, which is taking the values of 6 to 13 for the pin.
The circuit diagram is very similar to the Session 3, except for the fact that we place on the breadboard 8 LEDs.
The only novelty is that since the function of the resistance is to limit the intensity of the current flowing through the circuit, and since all diodes have common ground, just a single resistor between this point and Ground.
When our program to lift the corresponding pin HIGH value, the associated LED lighting up circuit is closed.
Below are a connection scheme circuit in a breadboard.
This setup allows us to play with lights and lends itself to several different programs to achieve different effects.
For example, with the previous program 4.1, the effect is not exactly fantastic car because when we just iterate for, the program starts again from the beginning, which causes light to jump from pin 6 to pin 13.
So Could we make light bounce? Think about a bit.
Of course yes, it would suffice to use two for loops, similar to the following Download:
void loop () // Prog_4_2
{
for (int i = 6; i <14; i ++) // we define the variable i on the fly
{
digitalWrite (i, HIGH);
delay (500);
digitalWrite (i, LOW);
delay (500);
}
for (int i = 12; i> 6; i--) // define the variable i on the fly
{
digitalWrite (i, HIGH);
delay (500);
digitalWrite (i, LOW);
delay (500);
}
}
Another serious variant, make a ripple effect in which the lights go up leaving pre lit LEDs until the maximum and now shutting down the upper LEDs. We recommend trying to solve the problem as a challenge, before seeking a solution.
Our first circuit.
For our first circuit with Arduino need:
-Arduino One or similar. This session accepts any other model of Arduino.
-A PC with the Arduino environment correctly installed and configured.
-A Protoboard.
-A Diode LED.
-A 330 Ohm resistor.
-Some Breadboard wires.
In the previous blog program the pin 13 connected to our Arduino LED. Today we will duplicate this circuit in the outside riding him from the start with discrete components. Its electronic scheme would be:
We left the command LED that is light emitter and therefore has little arrows to indicate these projections (Light Emitting Diode). The resistance is represented by the second symbol indicating a name and value R1 330Ω. In turn we left the letters GND to indicate that is the negative. Finally right + 5V symbol indicates the end of positive voltage.
It is important to understand electronic schemes because they allow quickly understand any circuit. Worth spending a little effort because they are the language of electronics.
Once understood the electrical circuit diagram, see the connection in the Protoboard:
This scheme follows a pattern of marking the cables to positive in red and those who go to GND in black. We highly recommend this rule is followed in practice because it helps identify potential problems and avoid mistakes.
The keys to successfully mount the circuit are:
- Connect the Arduino pin 13 to the red line of the breadboard: Positive.
- Connect the Arduino GND to the blue line Protoboard: Ground.
- We use the positive rail (the pins of the red line) to connect to the resistance.
- The other end of the resistor is connected to the positive LED because they are in the same Breadboarding vertically (and this connects electrically).
- Note that the positive LED is clearly marked longest by a small angle near the base.
- A LED almost no resistance itself, so additional resistance to limit the current flow must always be used, and avoid burning. (A resistance between 220 and 3300 Ω is usually adequate).
- The circuit is closed with a wire from the negative rail LED to GND.
- When our program use a value of HIGH (5V) on pin 1.3 will allow the current flow through the LED lighting circuit. With LOW simply be off the circuit without tension.
We can now dump the program that we did in session 2 (or simply load the Blink example), following the procedure we defined there, and see how this time, besides their LED Arduino, our outdoor LED flashes following the same ignition cycle and off.
https://www.dropbox.com/s/zwyh0896stsq9gy/Arduino_pin_13_to_LED_10s_test%28bajaryoutube.com%29.mp4?dl=0
-Arduino One or similar. This session accepts any other model of Arduino.
-A PC with the Arduino environment correctly installed and configured.
-A Protoboard.
-A Diode LED.
-A 330 Ohm resistor.
-Some Breadboard wires.
In the previous blog program the pin 13 connected to our Arduino LED. Today we will duplicate this circuit in the outside riding him from the start with discrete components. Its electronic scheme would be:
We left the command LED that is light emitter and therefore has little arrows to indicate these projections (Light Emitting Diode). The resistance is represented by the second symbol indicating a name and value R1 330Ω. In turn we left the letters GND to indicate that is the negative. Finally right + 5V symbol indicates the end of positive voltage.
It is important to understand electronic schemes because they allow quickly understand any circuit. Worth spending a little effort because they are the language of electronics.
Once understood the electrical circuit diagram, see the connection in the Protoboard:
This scheme follows a pattern of marking the cables to positive in red and those who go to GND in black. We highly recommend this rule is followed in practice because it helps identify potential problems and avoid mistakes.
The keys to successfully mount the circuit are:
- Connect the Arduino pin 13 to the red line of the breadboard: Positive.
- Connect the Arduino GND to the blue line Protoboard: Ground.
- We use the positive rail (the pins of the red line) to connect to the resistance.
- The other end of the resistor is connected to the positive LED because they are in the same Breadboarding vertically (and this connects electrically).
- Note that the positive LED is clearly marked longest by a small angle near the base.
- A LED almost no resistance itself, so additional resistance to limit the current flow must always be used, and avoid burning. (A resistance between 220 and 3300 Ω is usually adequate).
- The circuit is closed with a wire from the negative rail LED to GND.
- When our program use a value of HIGH (5V) on pin 1.3 will allow the current flow through the LED lighting circuit. With LOW simply be off the circuit without tension.
We can now dump the program that we did in session 2 (or simply load the Blink example), following the procedure we defined there, and see how this time, besides their LED Arduino, our outdoor LED flashes following the same ignition cycle and off.
https://www.dropbox.com/s/zwyh0896stsq9gy/Arduino_pin_13_to_LED_10s_test%28bajaryoutube.com%29.mp4?dl=0
jueves, 7 de abril de 2016
Our first program.
The world seems bound Arduino, the first program we do is the blinking LED, and is well because it illustrates some interesting ideas about its possibilities:
-The ability to interact with the outside world. Something quite unusual for those who are accustomed to traditional computing, where computing power has grown dramatically, but it is still impossible (or nearly so), influence the outside world.
-The Simplicity of the work environment. In contrast to a traditional system editor / compiler / linker.
Arduino can interact in different ways with the world around him, we start by digital pins that can be used as:
-Entrance fees: To read digital information from the outside world.
-Outflows: To activate a signal to the outside world.
Arduino has 14 pins that can be used in this way, numbered 0 to 13.
Arduino will ask you activate your pin as digital output 13 and then will light and will quench this signal which will cause the LED is connected serial turns on or off the pace we mark.
To tell the system we want to use the digital output pin 13 as we use the command:
pinMode (13, OUTPUT);
The first parameter indicates the pin to use and "OUTPUT" is for use as an output, and the value "INPUT" could also be used to indicate that we will read this pin.
These definitions will be made only once at the beginning, in the setup (function). Ours will, with a single statement declaring that we will use pin 13 as a digital output:
void setup ()
{
// Initialize the digital pin as an output
pinMode (13, OUTPUT);
}
It is important to note that despite being a single instruction, we have defined the block this function by opening and closing keys.
Note that the statement ends in ";". C ++ requires instructions end with a semicolon to delimit the order. If omitted fail.
To turn the LED use the command:
digitalWrite (13, HIGH);
And another similar instruction ordering it to turn it off:
digitalWrite (13, LOW);
13 shows the pin to use and HIGH, LOW indicate the value we want to put on that output, which correspond to Arduino 5V and 0V for LOW HIGH.
If the loop function () we write these two followed instructions, Arduino change these values so fast that not perceive changes, so we need to stop him a bit so we can perceive the change.
To make this delay of, say, a second, we use:
delay (1000); // Delay (n) "freezes" Arduino n milliseconds
Therefore to schedule a light that turns on and off, we would have to generate a sequence of commands (as in a recipe and kitchen) to do:
-Inform Arduino that we will use the pin13 to write values (in Setup).
-Turn on the LED: Put high (5V) on said pin.
-Wait a second.
-Off the LED: Set low (0V) on said pin.
-Return to wait a second.
If we omitted this second delay, extinguish the light and would start meeting the order to relight. Not appreciate that he had off. (I hope not believe me. Check it out for).
UNO Arduino processor is very slow from the electronic point of view, but is capable of switching the light (switch from on to off and back on again) about 15,000 times per second.
void setup()
{
pinMode( 13 , OUTPUT); // We use the output pin 13
}
void loop()
{
digitalWrite(13 , HIGH); // Turn on the LED
delay(1000); // Wait one second
digitalWrite(13 , LOW); // Turn off the LED
delay(1000); // Wait another second
}
Note the bleeding lines to highlight code blocks. This is considered good practice and I would highly recommend, because much easier to understand the program.
When Eurpoean (and creadme, you are going to go wrong) bleeding help, and much, to view the program.
There are only two types of programmers. Those who make mistakes and to be wrong.
We only need already, check for errors and to do this click the icon in yellow.
If all goes well, (if there are no errors in red) we can compile and dump the next arrow, Otherwise (and believe me you will frequently) should be reviewed for possible errors and correct them. We will return to this in the future.
The yellow arrow in our program the Arduino capsized and can see that the light flashes pin 13 with a delay of one second between on and off.
* Tip: If we change the values of the delay, modify the rate of blinking.
* Note: This will not work with any other Pin Arduino UNO, because only 13 has an LED connected.
-The ability to interact with the outside world. Something quite unusual for those who are accustomed to traditional computing, where computing power has grown dramatically, but it is still impossible (or nearly so), influence the outside world.
-The Simplicity of the work environment. In contrast to a traditional system editor / compiler / linker.
Arduino can interact in different ways with the world around him, we start by digital pins that can be used as:
-Entrance fees: To read digital information from the outside world.
-Outflows: To activate a signal to the outside world.
Arduino has 14 pins that can be used in this way, numbered 0 to 13.
Arduino will ask you activate your pin as digital output 13 and then will light and will quench this signal which will cause the LED is connected serial turns on or off the pace we mark.
To tell the system we want to use the digital output pin 13 as we use the command:
pinMode (13, OUTPUT);
The first parameter indicates the pin to use and "OUTPUT" is for use as an output, and the value "INPUT" could also be used to indicate that we will read this pin.
These definitions will be made only once at the beginning, in the setup (function). Ours will, with a single statement declaring that we will use pin 13 as a digital output:
void setup ()
{
// Initialize the digital pin as an output
pinMode (13, OUTPUT);
}
It is important to note that despite being a single instruction, we have defined the block this function by opening and closing keys.
Note that the statement ends in ";". C ++ requires instructions end with a semicolon to delimit the order. If omitted fail.
To turn the LED use the command:
digitalWrite (13, HIGH);
And another similar instruction ordering it to turn it off:
digitalWrite (13, LOW);
13 shows the pin to use and HIGH, LOW indicate the value we want to put on that output, which correspond to Arduino 5V and 0V for LOW HIGH.
If the loop function () we write these two followed instructions, Arduino change these values so fast that not perceive changes, so we need to stop him a bit so we can perceive the change.
To make this delay of, say, a second, we use:
delay (1000); // Delay (n) "freezes" Arduino n milliseconds
Therefore to schedule a light that turns on and off, we would have to generate a sequence of commands (as in a recipe and kitchen) to do:
-Inform Arduino that we will use the pin13 to write values (in Setup).
-Turn on the LED: Put high (5V) on said pin.
-Wait a second.
-Off the LED: Set low (0V) on said pin.
-Return to wait a second.
If we omitted this second delay, extinguish the light and would start meeting the order to relight. Not appreciate that he had off. (I hope not believe me. Check it out for).
UNO Arduino processor is very slow from the electronic point of view, but is capable of switching the light (switch from on to off and back on again) about 15,000 times per second.
void setup()
{
pinMode( 13 , OUTPUT); // We use the output pin 13
}
void loop()
{
digitalWrite(13 , HIGH); // Turn on the LED
delay(1000); // Wait one second
digitalWrite(13 , LOW); // Turn off the LED
delay(1000); // Wait another second
}
Note the bleeding lines to highlight code blocks. This is considered good practice and I would highly recommend, because much easier to understand the program.
When Eurpoean (and creadme, you are going to go wrong) bleeding help, and much, to view the program.
There are only two types of programmers. Those who make mistakes and to be wrong.
We only need already, check for errors and to do this click the icon in yellow.
If all goes well, (if there are no errors in red) we can compile and dump the next arrow, Otherwise (and believe me you will frequently) should be reviewed for possible errors and correct them. We will return to this in the future.
The yellow arrow in our program the Arduino capsized and can see that the light flashes pin 13 with a delay of one second between on and off.
* Tip: If we change the values of the delay, modify the rate of blinking.
* Note: This will not work with any other Pin Arduino UNO, because only 13 has an LED connected.
martes, 5 de abril de 2016
The basic programing of Arduino.
To start with our first program we need an Arduino Uno board or similar (though this session accepts any other model Arduino), a suitable USB cable to our PC with Arduino and Arduino environment correctly installed and configured. If we have this we can start now.
Arduino is programmed in a variant of C ++, which is a widely used language for its features, though not plain language. C ++, which sets strict rules on how to write these instructions. A program is a set of instructions that are executed in sequence (unless expressly we indicate precise conditions under which this sequence is altered). An internal program checks the syntax of our program is in line with standard C ++, and if there is anything that does not convince you will fail and end checking forcing us to review what we have written. When the tester accepts our program invokes another program that translates what we have written in comprehensible instructions for the processor of our Arduino. This new program is called a compiler. The compiler converts our instructions (source code) in processor instructions (executable code).
A program or Arduino sketch consists of two sections or basic functions:
-Setup: Your instructions are executed only once, when the program starts when you turn Arduino or when you press the reset button. Generally it includes definitions and initializations hence its name.
-Loop: Their instructions are executed in sequence until the end .... And when it ends, start again from the beginning by an endless cycle.
When we open the Arduino IDE (or do [Menu] \ File \ New) he writes and these two functions (copper color):
Note that the beginning of each function is indicated by the key opening "{" and so it corresponds to the symbol keys closing "}".
In fact the set of instructions between an opening and closing braces is called block and is of paramount importance when our Arduino interpreted in one way or another we give instructions.
It is imperative that each opening of a key corresponds with a key lock. In subsequent chapters we expand this concept.
For now highlight the lines that appear within the main blocks:
// Put your setup code here, to run once
// Put your main code here, to run Repeatedly
Anything you write preceded by "//" are comments and are ignored. That is we can leave messages in the code (which would otherwise errors). The compiler will ignore anything between // and the end line.
Arduino is programmed in a variant of C ++, which is a widely used language for its features, though not plain language. C ++, which sets strict rules on how to write these instructions. A program is a set of instructions that are executed in sequence (unless expressly we indicate precise conditions under which this sequence is altered). An internal program checks the syntax of our program is in line with standard C ++, and if there is anything that does not convince you will fail and end checking forcing us to review what we have written. When the tester accepts our program invokes another program that translates what we have written in comprehensible instructions for the processor of our Arduino. This new program is called a compiler. The compiler converts our instructions (source code) in processor instructions (executable code).
A program or Arduino sketch consists of two sections or basic functions:
-Setup: Your instructions are executed only once, when the program starts when you turn Arduino or when you press the reset button. Generally it includes definitions and initializations hence its name.
-Loop: Their instructions are executed in sequence until the end .... And when it ends, start again from the beginning by an endless cycle.
When we open the Arduino IDE (or do [Menu] \ File \ New) he writes and these two functions (copper color):
Note that the beginning of each function is indicated by the key opening "{" and so it corresponds to the symbol keys closing "}".
In fact the set of instructions between an opening and closing braces is called block and is of paramount importance when our Arduino interpreted in one way or another we give instructions.
It is imperative that each opening of a key corresponds with a key lock. In subsequent chapters we expand this concept.
For now highlight the lines that appear within the main blocks:
// Put your setup code here, to run once
// Put your main code here, to run Repeatedly
Anything you write preceded by "//" are comments and are ignored. That is we can leave messages in the code (which would otherwise errors). The compiler will ignore anything between // and the end line.
Introduction to Arduino.
To begin working with Arduino must download and install the Arduino development environment (IDE), and check that it is properly configured. We are going to the download page http://arduino.cc/en/main/software.
And down the latest version of the IDE. That the date of this writing is 1.6.48 beta is stable enough to use under normal conditions.
Choose the appropriate version to our system and be patient because it is a moderately large download. Once completed, Execute the downloaded file, and go answering the installation options. Accept the default installation options is a reasonable option if you are unsure of the questions that makes us. After a few minutes finalize the installation, and the team workspace Arduino icon appears.
Once installed the IDE, we will check that recognizes our Arduino properly and we can schedule it. To do this, Connect your Arduino to your computer via USB. In doing our PC should detect the new USB device and install the appropriate driver. And decompressed with Winrar, and executes the program included. You will install a driver that resolves the problem. Now, we can start the Arduino icon from the desktop and configure Arduino model and confirm the serial port to which it connects. [Menu] \ Tools \ Plate Choose the exact model of our Arduino. [Menu] \ Tools \ Port is necessary to check that we have assigned a port and has the mark. It is important to assign the port and the Arduino model to ensure the proper functioning of the IDE. The check mark should be with the tick. Pressing [Menu] \ File \ Examples \ 01.Basics \ Blink, a series of texts appear in the working environment, to ignore for now. Press the button marked in yellow, will see a green line progress forward.
if you've already done this process you will already start working with Arduino.
And down the latest version of the IDE. That the date of this writing is 1.6.48 beta is stable enough to use under normal conditions.
Choose the appropriate version to our system and be patient because it is a moderately large download. Once completed, Execute the downloaded file, and go answering the installation options. Accept the default installation options is a reasonable option if you are unsure of the questions that makes us. After a few minutes finalize the installation, and the team workspace Arduino icon appears.
Once installed the IDE, we will check that recognizes our Arduino properly and we can schedule it. To do this, Connect your Arduino to your computer via USB. In doing our PC should detect the new USB device and install the appropriate driver. And decompressed with Winrar, and executes the program included. You will install a driver that resolves the problem. Now, we can start the Arduino icon from the desktop and configure Arduino model and confirm the serial port to which it connects. [Menu] \ Tools \ Plate Choose the exact model of our Arduino. [Menu] \ Tools \ Port is necessary to check that we have assigned a port and has the mark. It is important to assign the port and the Arduino model to ensure the proper functioning of the IDE. The check mark should be with the tick. Pressing [Menu] \ File \ Examples \ 01.Basics \ Blink, a series of texts appear in the working environment, to ignore for now. Press the button marked in yellow, will see a green line progress forward.
if you've already done this process you will already start working with Arduino.
Suscribirse a:
Entradas (Atom)