Basic Arduino Projects with TinkerCAD

Bare Minimum

Background Knowledge:

What you'll need:

1 - Arduino UNO

1 - Arduino USB Cable

Creating the bare minimum setup on an Arduino involves setting up the microcontroller to run without any external components except for power. This is useful for testing the basic functionality of the microcontroller and for situations where you have limited resources. 

Plug your Arduino board into your computer using the USB cable.

Launch the Arduino Integrated Development Environment (IDE) on your computer.

Go to Tools > Board and select the appropriate Arduino board you're using (e.g., Arduino Uno, Nano, etc.)

Go to Tools > Processor and select the specific microcontroller model (e.g., ATmega328P for Arduino Uno).

 5. Select the Port:

Go to Tools > Port and select the COM port to which your Arduino is connected.

 6. Choose Programmer (if necessary):

Go to Tools > Programmer and select the appropriate programmer if you're using an external programmer (not needed for most setups).

 7. Write the Sketch:

Write a simple Arduino sketch to test the microcontroller. See this process below.

 8. Upload the Sketch:

If using TinkerCAD, copy and paste the C++ code that you have either written or that was generated from the block coding feature into the Arduino IDE. Click the "Upload" button (right arrow icon) in the Arduino IDE to upload the sketch to the microcontroller.

Bare Minimum Coding

When creating a Bare Minimum Sketch, the absolute least you will need is an "On Start" and "Forever" Control Block on TinkerCAD. In C++, this will translate to the "void setup()" and "void loop()" commands. 

void setup()

{


}


void loop()

{

  delay(10); // Delay a little bit to improve simulation performance

}

Why Create the Bare Minimum Setup

Resource Constraints:

In some projects, you might have limited components or space, and setting up the microcontroller with only power might be necessary.

Testing Microcontroller Functionality:

It's a quick way to verify that the microcontroller itself is working. For example, if you're troubleshooting a project, you can eliminate external components as potential issues. This usually is paired with a command like blinking the onboard LED to have visual confirmation the board and sketch are working. 

Important Note:

While this setup can be useful for certain scenarios, keep in mind that for most practical projects, you'll need additional components like resistors, capacitors, and other sensors or actuators. This bare minimum setup is primarily for testing and debugging the microcontroller itself.

Exercise One: Blink

Background Knowledge:

What you'll need:

1 - 9 Volt Battery

1 - 9 Volt Battery Harness

1 - Breadboard

1 - Arduino UNO

1 - 470 Ohm 1/4 Watt THR

1 - RED 5mm LED

1 - Jumper Wire Set

The "Blink" project is one of the most fundamental and introductory projects in Arduino programming. It involves turning an LED (Light Emitting Diode) on and off using an Arduino microcontroller. By writing a simple program, users learn how to control digital pins, set them as outputs, and use basic functions like digitalWrite() and delay(). This project serves as a starting point for beginners to get familiar with the Arduino IDE, hardware connections, and basic coding concepts, providing a solid foundation for more complex projects in the future.Most Arduinos have an on-board LED you can control. On the UNO, MEGA and ZERO it is attached to digital pin 13. LED_BUILTIN is set to the correct LED pin independent of which board is used.

Follow these steps to build  the circuit:

Writing the Code

On TinkerCAD there are blue output blocks that allow you to set the Arduino pins to outputs for various devices. In this case, you will be setting the output to the built-in LED which is also tied to pin 13 on most Arduinos- because of this, you do not have to also set pin 13 as an output. 

In your Forever Control Loop, place the "set built-in LED" block like a puzzle piece. This block should be set to HIGH which means the full available voltage the Arduino is able to output. Follow that with a wait command with 1 second or 1000 milliseconds. Repeat this process but this time setting your built-in LED to LOW which means zero voltage. 

In TinkerCAD, the C++ code will be automatically generated from the blocks and can be copied and pasted into the Arduino IDE for Upload.

void setup()

{

  pinMode(LED_BUILTIN, OUTPUT);

}


void loop()

{

  digitalWrite(LED_BUILTIN, HIGH);

  delay(1000); // Wait for 1000 millisecond(s)

  digitalWrite(LED_BUILTIN, LOW);

  delay(1000); // Wait for 1000 millisecond(s)

}

Questions: 

Exercise Two: Brightness and Fade (PWM)

Background Knowledge:

What you'll need:

1 - 9 Volt Battery

1 - 9 Volt Battery Harness

1 - Breadboard

1 - Arduino UNO

1 - 470 Ohm 1/4 Watt THR

4 - RED 5mm LED

1 - Jumper Wire Set

What is PWM?

Pulse Width Modulation, or PWM, is a technique for getting analog results with digital means. Digital control is used to create a square wave, a signal switched between on and off. This on-off pattern can simulate voltages in between the full Vcc of the board 5V on the Uno board and off (0 Volts) by changing the portion of the time the signal spends on versus the time that the signal spends off. The duration of "on time" is called the pulse width. To get varying analog values, you change, or modulate, that pulse width. If you repeat this on-off pattern fast enough with an LED for example, the result is as if the signal is a steady voltage between 0 and Vcc controlling the brightness of the LED. In the graphic to the right, the red lines represent a regular time period. This duration or period is the inverse of the PWM frequency. In other words, with Arduino's PWM frequency at about 500Hz, the red lines would measure 2 milliseconds each max. A call to analogWrite() is on a scale of 0 - 255, such that analogWrite(255) requests a 100% duty cycle (always on), and analogWrite(127) is a 50% duty cycle (on half the time) for example.

Steps

In TinkerCAD, setting an output block to a number between 0 and 255 will adjust the output between 0V and 5V. The example below is setting pin 3 to output 255 PWM which is 100% of Arduino's 5V output.

void loop()

{

  analogWrite(3, 255);

  delay(10); // Delay a little bit to improve simulation performance

}

4. Code LED4 so that it cycles through brightness.



void loop()

{

  for (PWM = 0; PWM <= 255; PWM += 1) {

    analogWrite(3, PWM);

    delay(10); // Wait for 10 millisecond(s)

  }

}

In TinkerCAD, cycling up or down power using PWM can be done using the "Count" command and assigning a variable to the count and output.

  5. Measure the Voltage over LED 4 and the Resistor in series with it.


6. Use the Oscilloscope tool in TinkerCAD. Set its Time Per Division to 1 millisecond. Connect negative to ground and positive to the Anode of corresponding LEDs. 

Questions: 

Exercise Three: Serial Monitor and Analog Sensors

Background Knowledge:

What you'll need:

1 - 9 Volt Battery

1 - 9 Volt Battery Harness

1 - Breadboard

1 - Arduino UNO

1 - 10K Potentiometer

1 - Jumper Wire Set

In this introductory lesson, we will learn how to utilize the Serial Monitor in conjunction with a potentiometer, a variable resistor, to read analog sensor values. This exercise serves as a fundamental step in understanding how to interface analog sensors with Arduino and visualize their output in real-time.

Steps

2. Write the Arduino Sketch

int SensorValue = 0;


void setup()

{

  pinMode(A0, INPUT);

  Serial.begin(9600);

}


void loop()

{

  SensorValue = analogRead(A0);

  Serial.println(SensorValue);

  delay(10); // Delay a little bit to improve simulation performance

}

 3. Understand the Code

 4. Upload and Monitor

 5. Experiment and Observe

This introductory lesson provides a foundational understanding of how to use the Serial Monitor to read analog sensor values, laying the groundwork for more complex sensor interfacing and data visualization projects in the future.

Questions: 

Exercise Four: Serial Monitor and Digital Sensors

Background Knowledge:

What you'll need:

1 - 9 Volt Battery

1 - 9 Volt Battery Harness

1 - Breadboard

1 - Arduino UNO

1 - N.O. Button

1 - Jumper Wire Set

In this introductory lesson, we will learn how to employ the Serial Monitor in tandem with a digital input, specifically a button. This exercise will introduce you to the process of reading digital signals and visualizing their state changes in real-time using Arduino.

Steps

Extra Vocabulary! A pull-down resistor holds the logic signal near zero volts (0V) when no other active device is connected. It pulls the input voltage down to the ground to prevent an undefined state at the input.

 2. Write the Arduino Sketch

 3. Understand the Code

 4. Upload and Monitor

 5. Experiment and Observe

This introductory lesson provides a foundational understanding of how to use the Serial Monitor to read digital inputs from a button. This knowledge can be applied to a wide range of projects involving switches, sensors, and other digital components.

Questions: 

Exercise Five: Basic Logic

Background Knowledge:

What you'll need:

1 - 9 Volt Battery

1 - 9 Volt Battery Harness

1 - Breadboard

1 - Arduino UNO

1 - N.O. Button

1 - Jumper Wire Set

In this lesson, we'll explore the basics of logic statements in Arduino programming. We'll create a project where an LED turns on if a button is pressed.

Steps

2. Write the Arduino Sketch

void setup()

{

  pinMode(2, INPUT);

  pinMode(13, OUTPUT);

}

void loop()

{

  if (digitalRead(2) == HIGH) {

    digitalWrite(13, HIGH);

  } else {

    digitalWrite(13, LOW);

  }

  delay(10); // Delay a little bit to improve simulation performance

}

  3. Understand the Code

NOTE: 

If you only use an IF statement and not an IF-ELSE Statement, then the first time you press the button, the LED will turn on an stay on even if you let go of the button. This is because there is no alternative option for the LED to be explicitly set to. It will be set to the condition and stay there until the program is terminated. 

4. Upload and Monitor

 5. Experiment and Observe

This introductory lesson provides a foundational understanding of how to use the Serial Monitor to read digital inputs from a button. This knowledge can be applied to a wide range of projects involving switches, sensors, and other digital components.

Questions: