Micro:bit conductivity tester and Ohm’s Law
Conductors and resistors are very similar. Both of them allow electrons to flow through a circuit. Resistors allow less of the electrons to flow in a circuit. Too much current in a circuit going to a component can damage the component. Resistors are used to reduce the amount of current going into components.
The conductivity tester in our lesson will help us identify items that are conductors, resistors, or insulators. The lesson is heavily focused on Ohm’s Law. We will program the Micro:bit to display voltage and resistance information from different conductive materials.
This lesson is an extension from a previous lesson. That lesson focused on creating a basic conductivity tester for various items. That lesson includes documents with lists of items to test for conductivity. I have made those same lists available here for you to use. The links to that lesson and the Google Documents are available below.
Basic conductivity tester lesson
Conductivity list from Google Docs
Resources
Use the links below to get a copy of the final project.
Conductivity tester Make Code : https://makecode.microbit.org/_9gDPbzK8p2Xg
conductivity tester GitHub : https://github.com/digitalmaestro/conductivitytester
Conductivity tester
We are going to use two different development environments for this lesson. We will use the traditional Make Code Integrated Development Environment to create the code and download it to the physical Micro:bit. Furthermore, we are also going to use Tinkercad to demonstrate what is going on with the circuit. Tinkercad has a Micro:bit simulator and electronic components. We will use the components to understand what the finished program will do and how to read the information collected.
Tinkercad Development Environment
Use the link below to access the Tinkercad website. You need to create an account to work with Tinkercad. Teachers can create an account and invite students to join. Joining requires an email address. Tinkercad integrates with services like Microsoft and Google. Students can use their district accounts to log into Tinkercad.
Tinkercad is used to develop 3D models for printing. It also has an environment for working with virtual electronic components. Use the menu on the side to go to the Circuits page.
Click the ‘Create new Circuit’ button.
The main white are is the workspace. Components used for our project are available in the panel on the right.
Scroll down the list of components; look for the micro:bit.
Drag the Micro:bit component to the workspace.
The Micro:bit has various internal components. These components include LEDs, buttons, contacts, and a speaker for the latest Micro:bit. The Micro:bit has options for connecting external components.
Scroll back to the top of the components panel; find the LED.
Place the LED on the workspace, below the Micro:bit.
Components are connected to the Micro:bit with wires. Wire connections are created in Tinkercad by touching one end of a component or contact. Move the mouse pointer over the 3-volt contact on the Micro:bit. A label for the contact and a red square appear.
Click on the red square and move the mouse pointer toward the resistor. One end of a green line attaches itself to the Micro:bit connector. The other end follows the mouse pointer.
Move the pointer to the connector on the right side of the LED. A red square appears with a label for the connector. Click the mouse to make the connection.
This green line represents a wire connection. We have connected the 3-volt contact with the Anode side of the LED.
Click on Pin1 of the Micro:bit to create a wire connection from that contact to the connection on the left side of the LED. The left side contact is called the Cathode.
We have a basic circuit connection. To complete the circuit, we need to program the Micro:bit with instructions for what to do.
Go to the button bar; click the Code button.
A code panel open with code blocks on the left and a coding workspace on the right.
Move the mouse pointer over the left edge of the code blocks section. Look for the pointer to change to opposing arrows. Click and drag the panel to the left. This increases the size of the coding workspace.
The coding workspace includes two code blocks. We are not going to use these blocks for our program. It’s okay to leave them on the workspace.
Click the Input code blocks category.
Find the [on button A pressed] code block.
Place the code block on the workspace.
Go to the Basic code block section.
Find the [show number] code block.
Place the code into the [on button A pressed] function.
Go to the Output section; find the [write analog pin P0 to] code.
Place the code into the [on button A pressed] function.
This code writes values to the pins on the micro:bit. We need to provide a numeric value into the parameter. The code does not send the literal number to the pins. It sends current to the pins. The numeric value represents the current.
Micro:bit uses 10bit binary strings. The values available to the code range from 0 to 1023. A 10 bit binary string has 1024 possible values. The numeric values represent the possible voltages that can be sent to the component. The Micro:bit provides 3-volts through our connection. Entering 0 provides no voltage to the circuit. Entering 1023 provides 3-volts. Entering half that value, 512, provides 1.5 volts.
Type 1023 into the [analog write pin P0] parameter.
Click the Pin selector and choose P1.
Click the ‘Start Simulation’ button. The runs the code in our program and activates the circuit.
Press button A on the micro:bit. The LED color changes slightly. This represents a light LED. The micro:bit does not produce enough current to fully light the LED. That isn’t the purpose of this lesson.
Change the value in the [analog write pin P0] parameter to 512.
The simulation stops when we change anything in the circuit or code. Click the Start Simulation button again.
The LED is still light, but it is less noticeable. Change the value to 0 and note what happens to the LED.
The micro:bit can send values to components. It can also read values from components. Get the [analog write pin P0] code block and drag it to the codes section.
This is all the code we need. The LED will light without the code because we don’t have a switch between the pin and the voltage supply. Release the code when it is over the section. This removes the code from the workspace.
Go to the Basic section; find the [show number] code block.
Place the code block into the [on button A pressed] function.
Go to the Input section; find the [read analog pin P0] code block.
Place the code block into the [show number] parameter.
Change the read pin to P1.
Start the simulator and press button A. The value 577 will scroll across the display. Voltage is supplied to the component. Some current powers the component and the rest flows through.
Three volts goes in and about 1.5 volts is registered by the micro:bit. Remember that a binary string of 512 is half the 3-volts. The voltage read after it passes through a component is called the voltage drop. The voltage on the other end of the component dropped by less than 1.5 volts.
To use Ohms Law, we need to establish some constants. In Ohms Law, we need to know two of three values. We have to know the voltage, current, or resistance.
Click on the LED component.
Click the Trash icon in the button bar.
Go to the components panel; find the resistor.
Place the resistor on the workspace; below the micro:bit.
Click the rotate button in the button bar. Click the button three times.
The resistor has rotated to a horizontal position.
Go to the component configuration panel. Change the resistor value to 10Kh, 10-kilo ohms.
Connect the resistor to the 3-volt contact and to Pin P1.
The circuit has a resistor with a resistance value of 10 kilo ohms. Three volts are being supplied to the resistor. We know two of the three values needed in Ohm’s Law. We can calculate the current flowing through the circuit. In Ohms law we calculate the voltage by multiplying the distance by the current. We change the formula to calculate the current by dividing the voltage by the resistance.
We divide 3-volts by 10000 ohms. The resistor is 10-kilo ohms or 10,000 ohms. The current flowing through the circuit is .0003 amps.
Make Code Development Environment
Use the link below to access the Make Code development environment.
Click the New Project button.
Use ‘conductivityTester’ for the project name; click the Create button.
Every new project includes two code blocks on the coding workspace. These blocks include the [on start] section and [forever] loop.
The [on start] section is used to run code as soon as the Micro:bit starts or is restarted. This is where we usually define variables. We will use plenty of variables in our project.
The [forever] loop runs code for as long as the Micro:bit is powered. Code inside this loop does not require any user interaction. This is where we will develop the code for our tester.
The Make Code development environment has a Micro:bit simulator. The simulator has contacts along the bottom, just like the real Micro:bit. Some contacts have labels. Contacts with labels 0, 1, and 2 are used to connect with external components. The contact labeled 3V provides current to external circuits. The GND contact is called the Ground. All circuits need to be connected to a ground to complete the circuit.
Important: Never connect the 3v and GND directly. This could severely damage your Micro:bit.
The 3V contact provides electric current for circuits. The contacts labeled 0, 1, and 2 also provide current. These contacts are referred to as General Purpose Input and Output connectors. They can function as either input or output. We will use one as an input contact.
We are going to use the simulator to provide a foundation for the readings from the actual Micro:bit. This will help us understand the information to be displayed later.
The Micro:bit will also provide information on current, resistance, and voltage. This ties in the understanding and practical application of Ohm’s Law.