Coding

Writing code. Features and syntax of the programming language

Arduino sketch keywords can be divided in three main category types: structures, values (variables and constants), and functions. A complete list of sketch keywords can be found at  https://www.arduino.cc/en/Reference/HomePage and test on

https://create.arduino.cc/editor .

The first time you run the Arduino IDE software, or when you create a new sketch, you will be presented with a beginning shell of a sketch in the Text Editor section of the IDE. The following is an explanation of the keywords used in this beginning shell.

The void keyword is used only in function declarations. It indicates that the function is expected to return no information.

The setup() function is used to initialize variables, pin modes, start using libraries, etc. The setup() function will only run once, after each power up or reset of the Arduino board.

Note: The curly braces ({}) after the setup() function delimits the beginning and ending of the setup() function. All code contained within these braces will be executed only once.

The loop() function is the main section of a sketch and loops consecutively, allowing your program to change and respond.

Comments are lines in the program that are used to inform someone viewing the code. Comments are ignored by the Arduino board. Comments come in two forms: Single line and Multiple line. A Single line comment is designated by two forward slashes (//). Everything from the two slashes to the end of the line is considered part of the comment and ignored when the sketch is compiled. Multiple line comments start with a forward slash and an asterisk (/*) and end with an asterisk and forward slash (*/). All text between those delimiters is considered part of the comment. The comment can span many lines.

Note: Using the multiline comment delimiters to comment out a section of code can be useful for troubleshooting.

 

Testing

When your prototype circuit has been built and your code has been written and saved, click the first icon on the toolbar to verify your code. The IDE will compile your code and check for syntax errors. Review any messages that you receive in the Console area of the IDE, shown in Figure 1.

To test the code, click the second icon on the toolbar to upload your sketch to the Arduino board. Every time you make a change to your sketch, you will need to compile and upload the new version to the Arduino board again. After a sketch is uploaded to the Arduino board it will remain there until you change it, even if you reset or power off the Arduino.

Sensors

Sensors are devices that detect an event from the physical environment and respond with electrical or optical signals as output. There are sensors that measure light, moisture, motion, pressure, temperature, or other environmental properties. The figure identifies four of the sensors that are included in the SparkFun Inventor’s Kit (SIK).

Lab. Use Tincercad for different examples.

How to work with electronic circuits. Simulations of operation of various circuits and operation of sensors with Arduino

https://www.tinkercad.com/

Examples:



Last modified: Wednesday, 14 July 2021, 7:57 PM