Tag Archives: S4A

Programming a light sensor alarm in a primary school

The basic principle of a light alarm is to measure any changes in the light levels. If the level goes above or below a certain level, something is triggered.

I like this because it teaches variables and responding to a change in that variable.

FOREVER measure the light level

IF the level changes, do something.

You can even use the > and < signs to extend it. The circuit is very simple – a light dependant resistor, 10k resistor , 3 wires and an Arduino. You can add more OUTPUTS or use Scratch on screen to do something.

This is an example of Scratch reacting – by 10 and 11 year olds.

Programming RGB LEDs in a primary school

RGB LEDs are great. They can produce a range of colours depending on the amount of power give to each LED bulb. Once you have access to the colour codes, you can produce 256 x 256 x 256 colours. Which is a lot of combinations.

We use Scratch For Arduino. This allows you to easily edit the analog power outputs. Put in a delay and a repeat and you’ve got a disco. As it’s Scratch based, it’s easy to do for primary children.


Using Arduino, a servo and a potentiometer

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



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.


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.


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



This is the circuit appearance.


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.






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,


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.


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




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.


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.


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.



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.


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.


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

Now add the resistor


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

Finally connect the wires.




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

Arduino microcontroller

Using the Arduino to make an LED glow

We’ve been using both the Arduino and the Raspberry Pi to control LEDS, motors, switches and sensors. I’m going to do a series of simple tutorials explaining how both can be used as control devices and explain to teachers – especially primary teachers – how the National Curriculum for computing can be taught in the classroom in an interesting way.

The Arduino


Arduino microcontroller

An Arduino microcontroller. Each pin can control and input or and output.

It’s got pins which can be used for input and output. To set it up, you need the Arduino IDE which can be downloaded from the Arduino website.

Once set up, you connect it to the computer with a USB cable. You need to select the correct serial port.

Scratch for Arduino

This is a free adaptation of the popular Scratch program. It has been modified so you can turn pins on and off, give pins a variable power output, control motors and servos and also read sensors with an analogue input. This gives it a massive advantage over the Pi which can only read a digital input.

Download Scratch for Arduino here.

Once you upload the firmware in the Arduino program, you can then activate S4A. It searches for the board. Once detected, a sensor board comes up showing you 6 analogue inputs and the value of pin 2 and pin 3.

So to make an LED light up.

You need a breadboard, 2 wires, a resistor (about 400 ohm – but depends on the LED) and an LED.

Connect one wire to the 5V pin. Connect the other end to the breadboard along with the LED and resistor. The other wire connects to the GROUND  on the Arduino. Look at the diagram to see how the circuit works. If it’s correct, the LED will light up. Common mistakes include the LED being the wrong way round (long wire on the positive side) or too high an LED.

Once that works, disconnect the wire from the 5V and put it in pin 10 (or 11, 12 or 13).


The commands are as for normal Scratch. So if you select



Then when you press the SPACE key, digital 10 will turn on and the LED will light up.

To turn it off, DIGITAL 10 OFF.

S4a basic LED

It’s that simple.

To make things more interesting, you can connect multiple LEDs with a common ground to pins 10, 11, 12 and 13.

If you want to alter the degree of power, use pins 5,6 and 9. In this case, you use ANALOG 5 (0 – 255) where 0 is no power and 255 is full power.