M5 L10: Tinkercad Programming

Cards (24)

  • Tinkercad allows users to program circuits using graphical programming or by using blocks. This will help new programmers to create their own programs easier since they don’t need to put more attention on the syntax. The code is divided into 6 categories: output, input, notation, control, math and variables
  • Lesson 10.1 Output
    • Output is used when the user wanted to display an output via a component outside the Arduino. Examples of these are turning on an LED, playing a sound in a buzzer, controlling a servo motor, displaying text via LCD, etc.
  • Lesson 10.1 Output
    • Built-in LED
    • digitalWrite
    • analogWrite
    • Rotate Servo Motor
    • Controlling the Piezo Buzzer
    • Serial Monitor
  • Lesson 10.1 Output
    • Built-in LED = This code block is used to turn on/off the Arduino’s built-in LED. Setting the built-in LED to HIGH means that the pin will be connected to either 5V or 3.3V turning on the LED. While if the built-in LED was set to LOW, it will sink the current meaning that the LED will be turned off. This code block will translate to digitalWrite(LED_BUILTIN, value);.
  • Lesson 10.1 Output
    • digitalWrite = You can also do the same logic in all Arduino pins: 0-13 for digital pins and A0-A5 for analog pins. For example, if there is an LED (not the built-in LED) connected to pin 9, you can turn it on by setting the pin 9 to HIGH. This code block will translate to digitalWrite(pin, value);.
  • Lesson 10.1 Output
    • analogWrite = Digital pins 3, 5, 6, 9, 10, and 11 in Arduino Uno have tilde (~) near their labels. This means that although they are digital pins, they are also capable of the analogWrite() function. What is the difference between digital and analog? Analog signals can take on a number of values, unlike a digital signal which has only two values: HIGH and LOW or 0 and 1. This code block is used in controlling PWM pins. This can be used in controlling the brightness of an LED or a DC motor. This code block will translate to analogWrite(pin, value);.
  • Lesson 10.1 Output
    • Rotate Servo Motor = This code block is used to rotate a servo motor by a certain value of degrees. This is mostly used to rotate objects such as wheels for robots with wheels, moving robotic arms, hands, or legs of a robot, and also moving sensors.
  • Lesson 10.1 Output
    • Controlling the Piezo Buzzer = You can use a buzzer (piezo buzzer) to play a sound at different frequencies. The code blocks below are used to control the buzzer to play a sound given a certain frequency and duration and to turn it off. These code blocks translate to tone(pin, frequency, duration) and noTone(pin)
  • Lesson 10.1 Output
    • Serial Monitor = There are times where the programmer needs to display the value of a certain variable so that s/he can observe its changes. This is mostly done when calibating sensors. Printing it to a serial monitor will be a big help to check if the logic is correct in the program. Most of the time, the hello world text is replaced by the variable created. This will be discussed further in this lesson. This code block will translate to Serial.print(data).
  • Lesson 10.2 Input
    • Input is used when the user wanted to read or accept a data from a component and let the Arduino process that data. Examples of these are reading a value from a photoresistor, detecting the distance of an object from the ultrasonic sensor, checking if a button was pushed, reading the value being read by the temperature sensor, reading data from an RFID card, etc.
  • Lesson 10.2 Input
    • digitalRead and analogRead
    • Read Ultrasonic Distance Sensor
    • Read Temperature Sensor
  • Lesson 10.2 Input
    • digitalRead and analogRead = These code blocks are used to read the value from a specified digital/analog pin. This is the opposite of digitalWrite and analogWrite function. These code blocks translates to digitalRead(pin); and analogRead(pin) respectively. These two are mostly used when reading values from input components or sensors.
  • Lesson 10.2 Input
    • Read Ultrasonic Distance Sensor = This code block is specifically used to measure the distance of an object from an ultrasonic distance sensor. This code block is a little bit complicated when read using textual programming. But, thanks to graphical programming, it is easier for programmers to understand what’s going on.
  • Lesson 10.2 Input
    • Read Temperature Sensor = This code block is used to determine the temperature detected by a temperature sensor. The user needs to choose which analog pin the temperature sensor is connected and also if s/he wants to display the temperature in Celsius or Fahrenheit.
  • Lesson 10.3 Notation
    Notations are used to write comments. We already know the importance of comments in a program. It is very useful especially to those who are new to programming. You can choose to use the title block comment which will create a multi-line comment at the beginning of your program or the comment button which will create a single-line comment where you can use multiple times.
  • Lesson 10.4 Control
    Controls are used to control the flow of your program. Examples of this are setting delays, loops, and conditional statements.
    • Delay/Pause
    • Conditional Statements
  • Lesson 10.4 Control
    • Delay/Pause = Delays are crucial elements in Arduino programming. It is the one responsible for pausing the program for an amount of time. You can pause your program using seconds or milliseconds. Indicate the amount of pause you’re going to set by changing the numerical value of the block
  • Lesson 10.4 Control
    • Conditional Statements = This code block is used to create an if statement. The programmer needs to put the condition in the hexagon shape using the blocks in Math category. It will be discussed later in this module. If the value of the condition is true, it will execute what is inside the code block.
  • Lesson 10.4 Control
    The photo on the right is also used to create a decision statement. But this time, it is used to create an if-else statement. The difference of an if-else code block to an if code block is it allows two possible paths for your program: true an false
  • Lesson 10.5 Math
    Math category is used to create logical and mathematical statements in your program. Examples of this are arithmetic operations, relational statements, logical statements, picking random numbers from a range of values, using built-in mathematical functions in programming such as absolute value, square root, sine, cosine, tangent, etc., and setting a HIGH or LOW value.
  • Lesson 10.5 Math
    • Relational Statement = The code block on the right is used to be partnered with the conditional statement code block discussed in the previous lesson. It can be used in a conditional statement or a loop. You can select from the six relational operators available and then input the values you want to check the condition. This code block will return a Boolean value, either true or false.
  • Lesson 10.5 Math
    • Logical Statement = This code block will let you create logical expressions wherein you combine two different conditional statements and perform operations.
  • Lesson 10.5 Math
    • Negation = Another type of logical statement is using the NOT operator. It basically negates the value inside the hexagon shape.
  • Lesson 10.5 Math
    • HIGH or LOW = This code block is used to set the value of a certain statement into HIGH or Low.