【+10 Arduino Projects with Control Structures】List ▷ 2022

If you like electronics and programming surely you have already taken your first steps in being today one of the most important tools in everyone to carry out the that allow some kind of physical activity. This is how, for this, users can count on different tools that will facilitate their use.

For it arduino users can count on the control structures to learn to programall this with the purpose of make work more flexible while learning to use each of these structures. It is important to take into account that currently you can find a large number of them that will help you in the process of learning by programming.

According to all this, here we are going to teach you a little more about what the control structure Y what are the best projects of this type that you can currently find and thus be able to begin to make your work more flexible on this platform. To do this, follow in detail everything that we are going to teach you below.

What are control structures in Arduino programming and what are they for?

In the case of arduino structures of control They work in a very similar way to programming languages, which is why when programming Arduino it is practically impossible not to use these controls. And it is that said Control structures allow you to modify the flow of execution of the instructions. of a program.

Thanks to these tools, the following aspects can be achieved:

  • Depending on the value of a variablewill execute one group or another of statements.
  • In accordance with the conditionone group or another of statements will be executed.
  • It is capable of executing a statement group as long as a condition is met (Do–While)
  • Executes a statement group until a condition is met (Do-Until)
  • Executes a group statement a specified number of times (For-Next).

In the case of the modern presents similar control structures. It can be said that what varies between the control structures of different languages ​​is their syntax, so each language has own syntax to express the structure. Therefore, you can begin to do each of your Arduino projects much more flexible when learning to use the language control structures.

See also  【 Using Finder on MacOS 】 Step by Step Guide ▷ 2022

Keep in mind that in order to write code for your programs, you need at least a minimum knowledge of the C language. This is how Arduino uses a C programming language for what is the compilation of the sketches. Some of the constructions are particular to the Arduino language such as the writing of the I/O pins. In the case of these structures, they will allow you to take actions based mainly on certain conditions.

That is why the control structure of the Arduino C language includes the following:

  • if
  • if…else
  • for
  • switch case
  • while
  • do…while
  • break
  • continue
  • return
  • goto

All of this is known as the decision structure and they are key to functioning. This is how we explain the most important of them here:

  • if: It is a statement that is used to test if a certain condition has been achieved. It is normally used to test if an analog value is found by above a certain number and execute a series of statements that are written inside braces if truein the case that it is false and the condition is not fulfilled, then the program will not execute the operation that is inside the brace.
  • If…else: This structure is executed in response to the idea “If this doesn’t work, do the other” if you want to test a digital input and do one thing if the input went high or do something else if the input went low.
  • For: This is used to repeat block statements between its options. Therefore, an increment/decrement counter is used mostly to increment/decrement and terminate the loop, mostly this for statement is used in combinations with matrices to operate on data/pin collections on Arduino.
  • .case: Its purpose is to control the flow of the program by specifying in the program the code that should be executed based on certain variables. Agree with this, the switch statement is compared to the value of a variable over the values ​​specified in the case statements.
  • While: It is a While type loop that has a continuous execution as long as the expression placed between parentheses in the head of the loop is fulfilled. In this case the test variable must change to exit the loop. This entire situation may change at the expense of an expression within the loop code or also by the change of a value in an einput from a sensor.
  • .while: It works the same way as the while loop, but unlike that the condition is tested at the end of the loop, so the loop will always be executed at least once.
  • Break: It is used in the instructions do, for, while so it allows you to exit the loop in a different way than the one indicated in the loop.
  • Continue: It is used in the instructions do, for, while to skip the rest of the instructions that are between braces and go to the next execution of the loop checking like this the conditional expression.
  • Got: Transfers the program flow to a point in the program that is labeled.
See also  【 Earn Money as an Influencer 】 Step by Step Guide ▷ 2022

List of simple projects with control structures that you can do yourself to learn programming

Today you can find several types of Arduino projects with control structures that you can do yourself at home to start learn and program through this platform. That is why here we are going to show you some projects that you can take into account if you like programming and electronics.

To do this, follow in detail everything that we are going to teach you below:

alarm threshold

To start you must do it from the sketch, which you must modify so that instead of light a led when it exceeds the threshold value, simulate sending an alarm message through the Serial.printLn every time there is an alarm and the threshold value is exceeded, but this will only happen when it is exceeded the first time and not continuously. Now when the threshold value is below a trigger is generated. recovery messagein the same way only when it goes down for the first time and not continuously.

connection diagram

Here you must run the sketch and check it works. After this you must add an alarm and recovery text for when the value is below or exceeds the threshold. Once it is verified that the text is sent continuously, you should think about how to modify the sketch so that it is only sent when it is passed for the first time or when it has returned to its normal state for the first time. This also allows you to use the digitalwrite once instead of having to do it all the time.

See also  【BLOCK Web Page in Chrome】Step by Step Guide ▷ 2022

Flowchart

visual solution

Here you must see in the serial plotter the graphic representation of what is happening.

This will vary depending on the color shown, in this case each color means the following:

  • Blue: potentiometer reading.
  • Green: alarm status.

By selecting the area of “Print Values” you can see that it is only printed by alarm display and alarm recoveredwhen the threshold is passed, but not continuously.

Hysteresis

It consists of being able to check the effect of the program when you are just at the threshold where you will have continuous alarms and recoveries. In order to solve this it is important to add hysteresis.

Flowchart

visual solution

Presents a change in behavior with a median threshold of 400 and a hysteresis of 50. In this way you can see how the threshold changes when going from an alarm state to recovered and vice versa.

Hysteresis with temperature probes

It is the same example above but this time with the TMP36 temperature probe with and without hysteresis.

connection diagram

Perform this same example with temperature probe and the moisture DHT11.

Solution

For the solution it will be necessary to access the following links as the case may be:

  • DHT11: To do this, go to this.
  • TMP36: To do this, access this
Loading Facebook Comments ...
Loading Disqus Comments ...