STEM with mBot LEDs

Science and coding LEDs with mBots

 STEM with mBot LEDs

In this article we will take a look at learning science concepts with mBots and LED lights. The mBot from Makeblock is a robot ideal for learning STEAM concepts. STEAM refers to Science, Technology, Engineering, Arts, and Math. STEAM is an extension of STEM with the inclusion of Arts. I like to include Research to form STREAM. Research incorporates reading and writing. It also includes vocabulary and academic language.

The mBot consists of a microcontroller connected to a circuit board and components. A microcontroller is a simple computer processor. It isn’t designed to handle as many tasks as the processor on your typical computer. The processor is designed to interact with the components on the board and similar components attached to the board.

One of these attached components includes motors. Motors are attached to wheels on the mBot robot for locomotion. Other components include sensors for input. These input sensors include a sonic sensor, infrared sensors, and photo-resistor. Components for output include a buzzer for sound and LED lights.

A review of the basic sensors

The sonic sensor is used to determine distance. The sonic sensor uses ultrasound. Ultrasound waves are used to determine the distance to objects. A sonic sensor is very similar to echo location and radar. The sensor is often used to avoid obstacles as the robot travels through a course.

The infrared sensor uses light in the infrared spectrum. This light is not visible to the human eye. Infrared is commonly used with remote control devices. Remote control wands for television are a common example. A remote is included with the mBot.

There in an infrared receiver and transmitter on the board. A line follower component with infrared sensors attached to the board with a cable. It is used to detect a black line. The black line is used to navigate across the floor or through an obstacle course.

A photoresistor is a component that is sensitive to light. I works like a switch. It allows current to flow through a circuit when exposed to light. 

A buzzer is a small speaker. It generates sound when current flows through the speaker. This current is controlled with the microprocessor to generate a variety of sounds.

There are several LEDs on the mCore. The microprocessor is coded to turn the lights On or OFF. Through code we control the brightness and color emitted by these lights. 

LEDs and science concepts

On the mCore board there are several LEDs. Some of them are used to provide status information. There is a small LED next to the power supply. There is an LED on the BlueTooth component. Below the mCore name are two sets of LED lights. One on the left and the other on the right. Each is a set of three LEDs. We will use these to learn and understand concepts related to light and color.

Light and the human eye

Understanding how the human eye works will help understand the concepts behind how LEDs are used to display color. 

The human eye has two different types of cells to help detect and respond to light. These cells are called rods and cones. The rods work in very low light conditions. Cones work in brighter light conditions. The eye has about six-million cones and about 110 million rods.

Cones help distinguish colors. They contain color detecting cells. These cells consist of three types of cones. Each cone is sensitive to different wavelengths of light. These color wavelengths are related to the colors red, green, and blue. The cones are concentrated in the center of the eye’s retina. This central region is called the macula.

The three types of color detectors allow our brains to interpret millions of colors. When we look at petals of a sunflower the cones for red and green are activated. The cones send a signal to the optic nerve in the visual cortex. The visual cortex is located within the brain. The brain processes the number of activated cones and the strength of the signal. The brain interprets these signals into a color. In this case, the color is yellow. The intensity of the signal determines the intensity of the color. This color is perceived by light reflecting from the flower. 

Color hasn’t always had names

Color has always been around but we didn’t always have a name for these colors. Colors have been discovered over the centuries. One of the first to discover colors and experiment with lights was Issac Newton. He used a triangular prism to see the different colors in ordinary sunlight. He discovered that ordinary light seen through a prism has red, orange, yellow, green, blue, indigo, and violet. This combination of colors has an acronym ROYGBIV. These are the same colors we see in a rainbow. Each water drop in a rainbow behaves like a prism to separate the colors in light.

Color has meaning and emotion

Color has meaning in our lives. Businesses use color in marketing because color has important psychological meaning to all of us. The meaning of color is also dependent on cultures and regions of the world. In western America the color red could represent danger or love. In Asia, the same color represents happiness or joy. 

This is one of the things I love about teaching. In one concept, I can touch on the history of color. The art of color. And the psychology of color.

Reflected light and color

Objects reflect light and color. Only some parts of the light spectrum are reflected in the colors we see. The leaves of a tree reflect light in the green portion of the spectrum. The brown in the bark of a tree is a result of the same process. The spectrum has many colors and many shades of the same color. Green has dark shades and light shades. A leaf has different shades of green. 

Refracted and filtered light

Reflected light is one way in which our eyes perceive light. Light can be filtered so we see a specific range of colors. When we put on a pair of yellow sunglasses we are using a filter to favor the yellow spectrum. The lenses are yellow and the light that passes through those lenses is yellow. 

Refracted light is how we see the different colors of the spectrum through a prism. Water droplets act like a prism in the atmosphere to produce rainbows. The refraction of light can scatter light molecules. This scattering is how we see the blue in our sky. It acts like a filter where the blue light is scattered more than the other colors. 

Producing color with LEDs

On the mCore board we have sets of LEDs. Each set contains three LEDs in different colors. These colors are red, green, and blue. Do those colors sound familiar? Those are the same colors that can be detected by the cones in the retina of our eyes.

LEDs emit light when a current passes over the surface of a semiconductor. The semiconductor is surrounded by a plastic case. This case is often colored red, blue, or green. 

We can setup three different LEDs. Each with a different color of red, green, and blue. These LEDs are placed next to each other in a circuit. When current passes through the LEDs they begin to emit light and we can see the three district colors. 

Something happens when we get further away from the LEDs. Our eyes blend the colors together. This is part of the persistence of vision. This is what makes color television possible. Our brains fill in the gaps between the colors so we don’t see three district colors but a blending of all three.

Use this link to an online simulator. Drag the three colored dots and stack them on each other. When all the colors are combined we see white. This is a process known as additive color. In this process we create color by adding different combinations of color with different shades. Shades of color are darker or lighter versions of the same color. 

Another common form of creating color is known as subtractive color. This is when we use color pigments in paint to create color. Subtractive color in printers uses three main pigments. The pigments are Cyan, Magenta, and Yellow. Combining all these colors produces black. It is not really a good black. This is why there is a separate cartridge in printers to create the true black color needed in documents. The same black is used to enrich the colors printed on photographs.

The LEDs on the mCore board are arranged very close to one another. This proximity is used to fool our brain into thinking there is one color being emitted from the combination of LEDs. This combination of LEDs is found in every display today. The LEDs are smaller and closer to one another. Each combination of three LEDs is referred to as a Pixel. There are millions of these pixels on computer screens and mobile devices. 

Each light on our mCore board has a combination of three LEDs. We could say that our mCore board has a resolution of 2 pixels. 

LEDs and coding

The light and colors we produce with these pixels in controlled by code sent to the microcontroller. To code the microcontroller we need to download software from Makeblock for the mBot. The software is available for Mac, Windows, Linux and Chrome. Download and install the software. 

To work with the LEDs, we use one line of code. The block of code is found in the Robots section in the scripts panel. The code block begins with the text “set led on board…” This text is followed by four options with pull down menus. These options are called options or parameters. The line of code itself is called a function. In this case, the function is a procedure. In coding, a function or procedure performs a specific task. In this case, that task is to turn the LED lights ON or OFF. It is also used to change the color of each light.

The first parameter in the function is set to control all the LED lights on the mCore board. These would be the two sets below the mCore name. The pull down menu for this option lets us select the left or right set. This option allows us to set a different color for each set of LEDs. 

To set a different color for each LED we need two functions. To set the color for the left LED choose the left LED option. To set the color for the right LED we connect another “set led on board…” function. The argument for the function is changed from All to the right LED.

To keep things simple, we will work with one function and control both LEDs. The three remaining arguments set the values for each color. The value for each LED is currently set to zero. The maximum value is 255. Click the pull down menu for one of the colors to see the selector options. We are not limited to these color values. The field accepts any numerical value we enter. 

The number 255 and computer programming

We see the value 255 or 256 very often when coding. The values from 0 to 255 represent the range of values that are represented in an 8-bit binary number. That sounds complex so let’s take a look at what that means. Computers use transistors to send signals through the computer. Transistors are very fast On and OFF switches. 

In computer terms a zero(0) is used to represent OFF and a one(1) is used to represent ON. Two numbers On and OFF are binary. Binary means base two. Computers read and store information in bits. A bit is either a one or a zero. An 8-bit binary number can store eight ones or zeros. For example, 11111111 or 00000000. 

They don’t all have to be the same number. The eight numbers can be any combination of ones and zeros. For example, 11001101 or 01011001. The number of possible combinations of ones and zeros in this format is the number two(2) to the power of eight(8). This gives us 256 possible combinations. 

This is a good opportunity to introduce or review the concepts of permutations and combinations with students.

Each set of eight bits is called a byte. This is where we begin to represent information in terms of kilobytes, megabytes, gigabytes, terabytes, and more. Think of a byte as the number of bits needed to represent one of the letters in the alphabet. The word computer uses eight bytes of information.

LED brightness and color combinations

Each color of our LED set has values from 0 to 255. The value of 0 represents zero volts sent to the LED. The value of 255 represents 3.3 volts. This is the maximum voltage sent to these LEDs. To send half the voltage to each LED we enter a value of 127. 

The values represented here apply both to the voltage and to the color we want to generate. Return to the RGB simulator. Place the circles on top of each other. Move the red, green, and blue sliders to the left. Move the red slider to 58 percent, the green slider to 37 percent, and the blue slider to 1 percent. These settings generate a brown color.

The sliders represent percentages of the colors opacity. What we need is a way to select the color we want and to get the RGB values for that color. There are plenty of tools on the Internet to help us. Google has a free tool to select a color and find the RGB values for that color.

Perform a search in Google for rgb color picker or click this link. The color picker has a gradient box and a slider below. The slider has colors that range from red on the right to orange on the left. In between we have blue, green, and yellow. Move the slider to the left or right to find a color you want to use on the LED. Move the circle in the gradient box to choose a darker or lighter version of the color. 

The RGB values for the color are generated on the panel to the left. The values are in parenthesis and separated by commas. Take these values and plug them into the corresponding argument in the code. The LED lights will represent this color when lighted. 

Keep in mind that the color seen on your display and the color seen on the robot might be a little different. The display on your computer has a much higher resolution and probably represents a more vivid version of the color.

The science of LEDs

An LED is very different from a light bulb or florescent lights. A light bulb uses the heat from a filament inside a glass enclosure to generate light. A florescent light bulb contains gases that are excited by electric current. The excited molecules cause a coating on the glass to glow. The primary gas used is mercury vapor. 

Light bulbs are not efficient. Most of the electric current through a bulb is given off as heat. Only a small fraction is given as light. Florescent bulbs are more efficient because less electricity is required to excite the mercury vapor. Mercury vapor can be dangerous and must be disposed of properly.

An LED uses a semiconductor. A semiconductor is part conductor and part resistor. The conductivity of a semiconductor increases with the increase in temperature. This is the opposite of what happens in metals like copper. Semiconductors can be modified with impurities to increase or decrease their conductivity. One of these impurities to a semiconductor is what is used to create LEDs. 

One of the impurities increases the space available for electrons. These are called electron holes. Current through an LED goes into these electron holes to create a glow in the LED. This is referred to as electroluminescence. 

The semiconductors in LEDs use less current to illuminate. They are more efficient than florescent bulbs. Most of the current is used to generate light and very little generates any heat. Silicon is made from sand and much friendlier to the environment. LEDs last for ten years or more. They have a low carbon footprint.