Serial Monitor

The Serial Monitor is a separate pop-up window that acts as a separate terminal that communicates by receiving and sending Serial Data. This allows you to output information that you can use while designing your project and code. Information that can be outputted are measurements, constraints, pulse width modulation, input states, output states, and sensor details. This information is important to refer to as you are designing and working on your project and code to find out what ranges or states the Arduino is reading from your inputs and collect information on the output states. This will allow you to isolate and mitigate any problems between the software and hardware. 

Reading Inputs

The serial monitor will allow you to see all of the ranges the Arduino reads that your sensors project from their inputs. A good way to do this is to create a variable for each input you have and assign it to a pin. Depending on what kind of sensor it is, you should keep in mind if you need to set it as an analog or digital pin and when building the circuit, be sure to plug the sensor into the correct pin. 

When using blocks in TinkerCAD you will need to use the block "print to serial monitor" and you will have to choose whether you want the print out to be followed with or without a newline. Keep in mind that the new line is referring to after the print out. Depending on your intentions, you may want to set up the serial monitor like the example to the right. In this example we have two digital inputs, the button and proximity sensor, and two analog inputs, the potentiometer and flex sensor. 

To create lines like you see above, use the "print to serial monitor" block and type in a label without a new line, then use another "print to serial monitor" block underneath it with the variable input. This way you will have an line that looks like:

"Label:" Variable Reading

Repeat this as you need in your code. You can also insert these commands anywhere into your other codes to get information on all the inputs and outputs of your code.

Button State on Serial Monitor

As we know from the Digital Inputs page, Switches will not work on the TinkerCAD Arduino Simulation. That said, we can be thoughtful with the code end of Arduino and use a button to create whatever state we need. Since switches will not work as inputs on Arduino in TinkerCAD, a good place to start would be to simulate a permanent push button with the supplied TinkerCAD momentary push button. To do this, we will need to have it so every time the button is pressed we can change the state of the button to OFF (0) or On (1). We can do this by counting each time the button is pressed by changing a variable by 1. It is good practice to put a wait command inside this IF Statement because if you press the button for too long, it will trigger another change otherwise.

Once your Button vairable is counting, you will have to trigger it so that it outputs an ON (1) or OFF (0) state. You can do this by creating an IF-ELSE Statement when If the condition is met the state is OFF and if the condition is not met, the state is ON. You can add a Print to Serial Monitor line to this to check if this condition is working as well. 

In other coding software, you could set your condition to be if Button = Odd/Even but that is not an option on TinkerCAD. To do this, the condition you will have to use is "Modulo" or "%." Modulo will output a remainder of a number that can or cannot be equally divided by another number. In the case above, it is the count of the Button Variable can or cannot be equally divided by 2. If it can, there is no remainder, if it cannot the remainder will be some odd number higher than 1.

Modulus congruence occurs when two numbers have the same remainder after the same divisor. So for example: 24 modulo 10 and 34 modulo 10 give the same answer: 4. Therefore, 24 and 34 are congruent modulo 10.

Another operation you may need on a Serial Monitor or another project would be to just count button clicks. We covered this above as well, but in this case, once your button clicks hit a specific number, you may want to reset your variable back to zero. In this case, the code would look like what is shown below. You would use this series of operations any time you need a finite amount of operations each time you click a button.