If you like electronics and programming, you’ve probably already taken your first steps on the Arduino platform. Today it is one of the most important tools for everyone to carry out the development of electronic projects that enable some form of exercise. For this purpose, several tools are available for the user to facilitate the application.
To do this, Arduino users can turn to the control structures to learn programming, with the aim of making operations more flexible while learning how to use each of these structures. It is important to remember that there are many of them available today that will help you in the process of learning to program.
In line with all this, we will tell you a little more about the governance structure and the best projects of this type that you can currently find and that will allow you to be more agile in your work on this platform. To do this, follow in detail everything we will teach you below.
What are the control structures in the Arduino programming and what are they used for?
In the case of the Arduino control structures, they function as programming languages, making it almost impossible not to use these controls when programming Arduino. And the fact that these control structures make it possible to change the order in which program declarations are executed.
Thanks to these instruments, the following aspects can be achieved:
- Depending on the value of the variable, one of the two record groups is executed.
- Depending on the condition, one or the other proposal will be implemented.
- It is able to execute a group of declarations as long as the condition (Do – While) is met.
- Executes the declaration group until the condition (Do-Until) is fulfilled.
- Executes the declaration group the specified number of times (For-Next).
In the case of programming languages, modern languages have similar control structures. It can be said that the differences in the control structures of the different languages are their syntax, so each language has its own syntax to express the structure. This allows you to make your Arduino projects much more flexible while learning to use the language management structures.
Don’t forget that you need to have a minimum knowledge of the C language in order to write the code for your programs. For example, Arduino uses the C programming language to make sketches. Some constructions are specific to the Arduino language, such as writing I/O pins. Such structures allow you to become active, especially under certain conditions.
Therefore, the control structure of the language Arduino C includes the following elements:
- if
- when…
- for
- Junction box
- Goodbye.
- …until…
- Recreation
- keep on
- Back to
- Website
They are all referred to as decision-making structures and are of crucial importance, the most important of which are explained here:
- when… This statement is used to verify that a certain condition is met. It is normally used to check whether an analog value is found above a certain number and to execute a series of operators in parentheses if it is true and the condition is not met, the program will not execute the operation within the key.
- Unless… …or..: This structure is done in response to the idea, if it doesn’t match, to do something else if you want to test the digital input and do one thing if the input was high, or do something else if the input was low.
- On: This function allows you to repeat pronunciations en bloc between your settings. The ascent/descent counter is therefore mainly used to increase/decrease and complete the cycle. It is mainly used in combination with matrices to work with data/contact collectors on the Arduino for scaffolding.
- Housing: The goal is to control the program flow by specifying the code to execute in the program according to certain variables. Consequently, the switch declaration compares the value of the variable with the values declared in the case declarations.
- Goodbye: This is the While loop, which is executed until the expression in parentheses at the beginning of the loop is executed. In this case, the test variable must change in order to leave the loop. All this can be changed by changing the expression in the loop code and by changing the value on the sensor input.
- For the time being: It works in the same way as the while loop, but unlike the state tested at the end of the loop, the loop is always run at least once.
- Break: It is used in do instructions, which allows you to close the loop in a different way than indicated in the loop.
- Go ahead: It is used in do so, because, while statements skip other statements made in brackets and proceed to the next execution of the loop to check the conditional expression.
- Go ahead: Moves the program flow to a marked program item.
A list of simple projects with control structures that you can do yourself to learn how to program.
Right now you can find different types of Arduino projects with control structures that you can make yourself comfortable to start learning and programming with this platform. So here we will show you some projects you can consider if you like programming and electronics.
To do this, follow in detail everything we will teach you below:
Threshold alarm
You must first do this from the sketch, which you must adjust to simulate sending an alarm message through the serial port instead of the LED lighting up when the threshold is crossed.prints each time an alarm occurs and the threshold is exceeded, but this happens only the first time the alarm is exceeded, not continuously. Now, if the threshold is lower than the reminder message, in the same way, only for the first time and not continuously.
Wiring diagram
Here you have to execute the sketch and check its function. You must then add the alarm and recovery text when the value is below or above the limit. If it has already been established that the text is being sent continuously, consider modifying the sketch so that it is not sent until the first cancellation, or returning to normal practice. Moreover, you can use digital writing once instead of always using it.
Block diagram
Visualino solution
Here you should see a graphical representation in the serial plotter of what is happening.
It depends on the colour shown, in this case each colour means the following:
- Blue: Potentiometer reading.
- Green: Fears.
If you select Print Value, you can see that printing only occurs when an alarm occurs and that the alarm is reset when the threshold is exceeded, but not continuously.
Hysteresis
It consists of the possibility to control the action of the program when you are just on the threshold where you will have constant alarms and recoveries. To solve this problem it is important to add hysteresis.
Block diagram
Visualino solution
Has a behavioural change with an average threshold of 400 and a hysteresis of 50. This way you can see how the threshold changes when you go from the alarm state to the reset state and vice versa.
Hysteresis for temperature sensors
This is the same example as above, but with and without the TMP36 temperature sensor with and without hysteresis.
Wiring diagram
Perform the same example with the DHT11 temperature and humidity sensor.
Solution
To solve this problem, click on the following links if necessary:
- DHT11 : Please enter this link.
- TMP36 : Visit this link.
If you have any questions, leave them in the comments. We will contact you as soon as possible and that will certainly be a great help to more members of the community. Thank you so much!
Maybe you are also interested in :
Related Tags: