Electricity and Coding with Tinkercad

Electronic Circuit Basics with TinkerCAD 3.png

Electricity and Coding with TinkerCAD

Create a basic LED circuit. Learn to use TinkerCAD to assemble components. Code the circuit to blink. Create a traffic light circuit.

Tinkercad is a free online service with applications for designing 3D models and electronic circuits. The circuit simulator has basic electronic components for assembling a variety of circuits. The simulator provides a way for us to integrate lessons on electricity. Students assemble circuits in a structured environment. The simulator is easy to use and appropriate for students of all ages. 

Tinkercad includes teacher tools to manage student accounts and projects. Students 12 and younger are not permitted to create an account. But, a teacher account permits us to invite and moderate student accounts.

Read my March 15th issue where I demonstrate how to use Tinkercad for 3D modeling. The issue has instructions for creating student accounts and managing those accounts through Tinkercad.

An LED circuit to teach the basics

In the circuit application, we assemble circuits with basic components. There are some pre-built circuits to get us started. These pre-built circuits connect an LED to a battery through a resistor and switch. This is the first and simplest circuit to assemble with students. The LED circuit has a battery, LED, resistor, and switch. Students and teachers take them apart in the simulator to learn how they work. 

With the LED circuit we teach students about closed and open circuits. The connection of an LED in an electric circuit is special. One of the connectors on the LED must be connected to the negative flow of current and the other to the positive. An LED has a bias. This means it will either allow current to flow through the component or it will block current from flowing. It depends on how we connect the LED to the power source. When it allows current to flow, we call it forward-bias. We call it reverse-bias when current is blocked. The forward-bias is what causes the LED to light. 

There are two pins on the LED. One pin is longer than the other. The longer pin is called the anode. This is the pin that connects to the positive flow of current. The other end of the pin is the cathode. In Tinkercad, the anode is shown as a bent connector. 

This is a good time to review with students how electrons flow through a wire and through a circuit. We teach two ways that electrons flow through a circuit. When electricity was first discovered, we assumed that electricity flowed from positive to the negative end of a battery. This was proved wrong later. 

Electrons, which are negatively charged, flow from the negative to the positive terminal in a battery. When we show a circuit diagram with current flowing from the positive terminal of a battery this is called conventional flow. When we show a circuit diagram with current flowing from the negative terminal this is called electron flow. The positive terminal of a battery is actually sending out negatively charged electrons.

The LED circuit requires a resistor. This gives us the opportunity to teach students about resistance. An LED can accept a limited amount of current before it is damaged. LEDs come with a chart that provides information about the minimum and maximum voltage it will accept. This is often called the tolerance. LEDs for hobbyists typically accept a voltage between 2.2 and 3.5 volts. A single Double-A battery will not damage one of these LEDs. When we add two or more batteries, the voltage can easily exceed the recommended maximum. The simulated LED has a tolerance too. 

There are industrial LEDs that accept a much higher voltage tolerance.

Resistors resist the flow of current in a circuit. They come with a variety of resistance values. We measure resistance in Ohms. A resistor connects to the anode on the LED. The other end of the resistor connects to the positive flow of current from a battery. The resistor limits the amount of current going into the LED so it isn't damaged. Remember that the positive connection in a battery is actually sending out electrons.

Enhancing circuits with micro-controllers

A microcontroller is a very simple computer. It has some memory to store and run programs. The chip is connected to a circuit board with input and output connections. These connections connect to electronic components. Microcontrollers provide voltage to circuits. They control the flow of voltage to components through pins on the circuit board. 

General Purpose Input/Output (GPIO) pins connect to components. Each pin has a number imprinted next to it on the board. We refer to this PIN number when coding circuits. With code, we close or open the circuit at the pin location. The microcontroller takes the place of a switch. 

The simple LED circuit we talked about earlier can be a little more interesting with the aid of a microcontroller. Here is an example. We connect one of the numbered GPIO pins to a resistor which is in turn connected to the LED. The other end of the LED, the cathode, is then connected to the Ground pin on the board. The Ground pin is like the negative end of the battery terminal in conventional electron flow. With the components connected in this manner, we can program the microcontroller to control the flow of current to the LED.

Coding a circuit

Coding for the microcontroller takes place within the Tinkercad simulator. The code is assembled using Blockly. In the code, we refer to the PIN number where the LED connects. The code parameter has two options, High or Low. High sends current from the pin to the LED. A Low instruction stops current to the LED. To turn an LED connected to pin 5 ON, the code would read like this. Set pin 5 to High. To turn the LED off we set another code block that reads; set pin 5 to Low.

We can program the microcontroller to blink an led at regular intervals. We need four code blocks. 

Set pin 5 to high

Wait 1 second

Set pin 5 to low

Wait 1 second

We need to add a one second wait time so we can see the LED blink. This is because the microcontroller is very fast and would turn the LED ON and OFF faster than our brains could process. 

The Blockly coding environment doesn’t show this, but the instruction we just wrote is actually contained within a loop. This loop will repeat the blinking process until we send other instructions to the microcontroller. 

These instructions are saved within the microcontroller’s memory. This means we can turn the controller OFF to stop the LED from blinking. When we provide power to the microcontroller again, it will resume the instructions to blink the LED. This is one reason why microcontrollers are used in most modern technology from appliances to smart-phones.

We are able to code a microcontroller with ease because of an underlying library of coded instructions. The library has all the complex instructions that communicate with the processor. The code, set pin 5 to High, is a set of instructions that calls other instructions in libraries. These instructions send machine level instructions to the microcontroller. 

Microcontrollers read code sent in a language called “C”. Yes, the name of the programming language is “C”. Take a look at an example, and you will see why using blocky is much easier. 

Building on learned skills

These basic skills help students assemble projects with greater complexity. Students use these skills to assemble traffic light signals, chasing lights, and lights that turn on randomly.

With a simple circuit, students apply concepts that are not available with books or video. Students learn by doing. They learn the practical application of Ohms Law and use Ohm's Law to calculate resistance and voltage for a circuit. They learn how coding works in practical applications. Creating simulations provides authentic learning opportunities for students. Product or project-based assignments are purpose driven.