Category Archives: Tutorials

Using a FUNCTION in Scratch

A function is basically a series of steps that you teach the computer – it then learns the steps and can use them when you ‘call it’. The idea is you don’t need to continually tell the computer how to do something as it already knows.

In this case, we are going to teach the computer how to work out the percentage of a number.  The steps are:

  1. Take the number and divide it by 100
  2. Multiply that answer by the percentage you want
  3. Print out that answer

In Scratch, you can do this using the MAKE BLOCK function. You define the block and put in how many numbers you need. In the function, you define the steps and return the answer.

You then ‘call the function’ by adding the block to the code.

function

Using REPETITION in Scratch

REPETITION is a very useful function on coding and saves time rather than doing a long list of code.  The basic idea is that you can have a variable and then write code so the variable increases by 1 (or another number) until a certain number is reached.

Example: To get Scratch to work out the 5x table

Using pseudocode:

  1. Declare a variable called MULTIPLIER
  2. Make MULTIPLIER = 0
  3. Work out 5 x MULTIPLIER
  4. PRINT the answer
  5. Add 1 to MULTIPLIER
  6. Repeat steps 3 – 5
  7. STOP the code when MULTIPLIER = 12

This is how the code looks like in Scratch.

repetition

 

 

The power of variables – making music easy in KS2 coding

Variables are really useful – as the name suggests, they can vary. When you make a simple change in the variable, the result can feed through a program rather than you having to type it in everywhere.

So for music, we have developed a function. In functions, you can “send” details to a function and it will carry it out for you. It saves you having to keep typing the function again and again.

Continue reading

ledfeatured

Using Arduino, a servo and a potentiometer

This is a guide showing you how to wire up and control a servo with a potentiometer.

Servos

servo

They have 3 wires.

POWER, GROUND and a CONTROL wire. They can either rotate continuously or they go to a fixed position between 0 and 180 degrees.

Potentiometer

Basically this is a variable resistor. As you turn the knob, the resistance changes and this can be measured on the Arduino.

Wiring it up

Wire the servo. The CONTROL wire can go to any digital pin.

POTIMAGE1

Then add the potentiometer. The wiper (middle wire) can go to any ANALOG input pin.

potless2

 

This is the circuit appearance.

potfizz

You will see that as you turn the knob round, the reading goes between 0 and 655.

However, the servo only needs a number between 0 and 180.

So you need to figure out:

a) A reading of 0 makes the servo go to 0 degrees.

b) A reading of 326 (half of 655 – half way on the knob) goes to 90 degrees.

c) A reading of 655 (all the way around) goes to 180 degrees.

 

 

 

 

ledfeatured

Using Arduino and a switch

This is a guide showing you how to wire up and read a basic switch. Any switch works – once a connection has been made, the switch reading changes – there is LOW and HIGH,

sw1

You now need to connect the components. The position of the components in the breadboard is very important. Make sure you are following the pictures.

Then – connect the wires to the Arduino. Use the 3.3 volt on the Arduino.

sw2

The 2 wires go to the switch – any switch works. When the switch is closed, the resistance changes and is detected on the INPUT.

 

 

ledfeatured

Using Scratch for Arduino and sensors

This is a guide showing you how to wire up and read a light sensor using Scratch for Arduino. You can also use it for other sensors such as force sensors and thermistors.

LDR1

You now need to connect the components. The position of the components in the breadboard is very important. Make sure you are following the pictures.

Now add the wires.

LDR2

The power input can be 3.3v or 5v. The ANALOG output can go to any of the Arduino analog inputs.

The circuit works by measuring the resistance in the circuit through the ANALOG input. If the light alters, then the LDR will alter the resistance and the sensor reading will alter.

 

ledfeatured

Using Scratch for Arduino to control an LED

This is a guide showing you how to wire up and light a single LED using Scratch for Arduino.

p1components

You now need to connect the components. The position of the components in the breadboard is very important. Make sure you are following the pictures.

p2led

Make sure you put the legs in the right way. These are diodes so current can only flow one way.

Now add the resistor

p3resist

The role of the resistor is to reduce the current flowing through the LED.

Finally connect the wires.

 

 

completed

The OUTPUT pin can be 5V – this will check you’ve made a connection. If it’s all ok, the LED should glow.

Then put the OUTPUT wire to an OUTPUT pin on the Arduino.

Once lit up – watch this video for how to use S4A