My Cart:

0 item(s) - £0.00
You have no items in your shopping cart.

0

Inventors Kit Experiment 2 Full Experiment

In this tutorial you will find Experiment 2 Using an LDR & Analog Inputs from the Kitronik Inventors Kit for the BBC micro:bit. We've included the entire experiment as a free example of the great practical experiments that are contained within the Inventors Kit. Learn how to build the circuit and how to code the micro:bit to control the circuit.

experiment-2-block-intro-870

You can complete this experiment with or without the Inventors Kit. If you do not have the Kitronik Inventors Kit you will have to source all of the required components separately, a full list of the things you will need can be found below.

 

This Experiment Requires:

 

The Aims Of This Experiment Are:

  • To use a Light Dependent Resistor as a sensor.
  • To perform an analog reading from the Light Dependent Resistor via input pin P0.
  • To set a light threshold to decide whether to display a sun or a moon on the LED matrix.

 

Experiment 2 Video Walk Through:

 

Experiment 2 - Using an LDR & Analog Inputs:

An LDR (Light Dependent Resistor) is an electrical component with unique properties. As the name suggests, it is a type of resistor that has its resistance determined by how much light is shining on it. The brighter the light, the less resistance it has. These resistors are used along with normal resistors to form potential dividers. When used in this configuration it gives a voltage that changes depending on the light level. A micro controller such as the BBC micro:bit can read this (analog) voltage, allowing a program to react to different light levels. This experiment will explain how to use the LDR and take an analog reading.

 

Creating The Code Using The Microsoft MakeCode Editor:

Below is an example of how to write the code for the experiment in the Microsoft MakeCode Editor.

experiment-2-block-editor-1-870

experiment-2-block-editor-2-870

experiment-2-block-editor-3-870

If you're having difficulty producing your own code for this experiment, we've created the code for you that you can compile, download and place onto your BBC micro:bit. You will find the links for the code towards the end of this article.

 

Building This Circuit On The Prototyping System:

It is possible to build this circuit using the Prototyping System for the BBC micro:bit and the components listed at the top of the page, you can follow the diagram below.

Experiment 2 Using an LDR & Analog Inputs-breadboard-870

What Will Happen:

The BBC micro:bit should display a sun image. If you cover the LDR with your finger it should then show a moon image. When the LDR is in light the BBC micro:bit should display the 'sun' image. When the LDR is in the dark (by covering it) the BBC micro:bit should display the 'moon' image.

 

Building This Circuit With Crocodile Leads:

If you don't have the Kitronik Inventors Kit for the BBC micro:bit or the Prototyping System you can still build this circuit using the circuit diagram for reference and Crocodile Leads to join the components together. You can see an example of this in the picture below.

experiment-2-block-crocodile-leads-870

Circuit Diagram:

Experiment 2 Using an LDR & Analog Inputs-circuit-diagram-870

What's Going On (How does it work?):

The resistor R1 and LDR are in series so they divide the 3V. The proportion of the 3V across each of them depends on their relative resistance. If they both have equal resistance then the voltage in the middle will be half. If the resistor makes up 75% of the total resistance then the voltage in the middle will be 75% of the 3V and so on. As more light shines on the LDR its resistance goes down, meaning resistor R1 makes up a greater percentage of the total resistance. This increases the voltage on P0. The analog read function measures the voltage on the selected pin and converts it into a value between 0 and 1023. If the voltage on P0 is 0V then this value will be 0. If the voltage on this pin is the maximum of 3V then the value will be 1023. If the voltage on P0 is 1.5V then the value will be approximately 512.

The pin P0 is read and the value is stored in the variable 'light'. The 'if' statement then checks if the value stored in 'light' is greater than 512. If it is then the LED's in the pattern of a sun is displayed on the LED matrix, otherwise the moon pattern is displayed.

 

Inventors Kit Experiment 2 Code Examples:

Although we advocate moving over to the Microsoft MakeCode Editor, we will continue to provide links to legacy code examples for as long as the links work or until the legacy editors are no longer available. Please select your desired option below and the options for your choice will open up.

The PXT option is a download, the file has been zipped and will need to be unzipped before transferring to a microbit. You can also drag and drop the unzipped file directly into the PXT editor for viewing or editing.

 

Booklet Errata:

inventors-kit-experiment-2-errata

The current version of the BBC micro:bit booklet is 1.3. If you have version 1.1 then please see below for corrections made to the current version.

  • On page 19 there is a box describing which blocks you need for this experiment.
  • We incorrectly listed an IF DO ELSE block. This should be an IF DO block.
  • You then need to click the cog icon to change the 'if do' block into an 'if do else' block by dragging the 'else' into the 'if' loop as shown above.

The booklet has now been updated to Version 1.5 with all code examples being produced and shown in the Microsoft PXT editor. The image below shows the corect block to use when coding this experiment using the PXT Editor.inventors-kit-experiment-2-errata-2

 

Kitronik Inventors Kit Resources:

Exp No#. Experiment Name. Resource Type.
1 Say Hello to the BBC micro:bit. Further Help.
2 Using an LDR and analog inputs. Full Experiment + Further Help.
3 Dimming an LED using a potentiometer. Further Help.
4 Using a transistor to drive a motor. Full Experiment + Further Help.
5 Using the accelerometer to control motor speed. Further Help.
6 Setting the tone with a piezo buzzer. Further Help.
7 Wind Power. Full Experiment + Further Help.
8 Making a game using the compass. Further Help.
9 Capacitor charge circuit. Further Help.
10 Using an RGB LED. Further Help.
11 Making a pedestrian crossing. Full Experiment + Further Help.
12 Making a random dice. Full Experiment + Further Help.

 

Get The Kitronik Inventors Kit For The BBC microbit:

We do two versions of the Inventors Kit for the BBC micro:bit, with or without the BBC micro:bit included. Chose the option that is right for you from the links below.

Free Delivery
← Previous Post Next Post →

2 thoughts on “Inventors Kit Experiment 2 Full Experiment”

  • Mark Ruskell July 1, 2017 at 7:36 pm

    I couldn't get the second experiment to work despite following all instructions could the LDR be faulty?

    Reply
    • Mark Donnison July 5, 2017 at 11:54 am

      Hi Mark, Sorry you are having difficulties. If you drop our admin team an email they can help you get to the bottom of the problem and hopefully help you resolve it. Use the following email address: sales@kitronik.co.uk

      Reply
Leave a Reply