Category Archives: Curriculum

How to Build a Wildlife Camera with the BBC micro:bit and Samsung’s micro:bit App

After much fiddling about I’ve finally managed to work out how to get Samsung’s micro:bit app working properly with my micro:bit. Before I tell you how you can use it to turn your phone into a wildlife camera there are two very important points to bear in mind:

1. You need to make sure you have the latest version (1.5.3 – 11 October 2016) of the app installed. I couldn’t get my micro:bit to control my phone’s camera with previous versions. So install/reinstall the latest version of the app now.

2. Every time you flash new code to your micro:bit you need to un-pair your micro:bit from your phone (go to ‘Settings’ then ‘Bluetooth’ on your phone) then re-pair it via the micro:bit app. Very, very important point this. It took me ages to work this out.

OK, now we’ve got that out of the way, here’s how to build a wildlife camera.

You will need:

  • Wildlife camera kit 1 x BBC micro:bit, its USB lead, and its 3V battery pack.
  • 1 x PIR motion sensor (I used this one from Squirrel Labs. Strictly speaking it’s a 5V motion sensor, but seems to work OK with 3V of power from the micro:bit.
  • 3 x crocodile clips.
  • 1 x male to female jumper lead. Not essential, but makes connecting the crocodile clips to the motion sensor a lot easier.
  • A Samsung smartphone (I used an J5) with the Samsung micro:bit app (1.5.3 or later) installed.

First, adjust Sensor setupthe sensitivity and time delay on the motion sensor. Turn both orange dials anti clockwise as far as they’ll go.

This sets the motion sensitivity to it’s least sensitive setting (left dial in the photo above) and the time delay between sensing to the shortest possible interval (right dial in the photo above). Five seconds for this motion sensor.

Next, connect your jumper lead to the middle pin (labelled OUT) on your PIR motion sensor. This just makes it a bit easier to connect the motion sensor to the micro:bit with crocodile clips.

Now connect your motion sensor to yMotion sensor to micro:bit wiringour micro:bit with crocodile clips:

  •  The ‘GND’ pin needs to be connected to the GND ring on the micro:bit.
  • The ‘OUT’ pin (jumper lead) needs to be connected to ring P0 on the micro:bit.
  • The ‘VCC’ pin needs to be connected to 3V ring on the micro:bit.

Now you’re ready to code. I created the following code in the Block Editor on my computer. Use your computer, not your smartphone to write code. It’s very, very annoying trying to code on your phone. The screen is just too small.

Wildlife camera code

All the time nothing is sensed, a simple line pulses across the display – – – But when something is sensed the motion sensor sends an electric signal out on its ‘OUT’ pin, which is detected by the micro:bit as a change from 0 to 1 on ring P0 (the ring the ‘OUT’ pin is connected to by the crocodile clips).

All the time a 1 is detected on ring P0, the micro:bit will change its display to ! ! ! and send three commands (via bluetooth) to your smartphone. The first launches your smartphone’s camera app. The second command initiate a countdown of 5 seconds, then the third command actually takes a photo and saves it to the ‘Images’ folder on your phone. You need the time delay between the ‘launch’ and ‘take photo’ commands because the camera doesn’t kick into life the instant the app is launched. But you may be able to get away with a delay of less than 5 seconds. I guess it depends on what model of phone you are using.

Once you’ve written the code (on your computer) connect your micro:bit to your computer via the USB cable, then compile the .hex file and drag it onto your MICROBIT icon.

Now un-pair your micro:bit from your phone (go to ‘Settings’ then ‘Bluetooth’ on your phone) then re-pair it via the micro:bit app.

Don’t forget to press the micro:bit’s reset button after pairing!Paired micro:bit

Now your ready to test. It takes a good minute for the sensor to start up properly. After that you should be able to trigger your phone’s camera into life by waving your hand in front of the sensor.

If it doesn’t work, double check your crocodile clip connections and/or try increasing the sensitivity of the motion sensor by gradually turning the orange dial (the one on the right if the dome it pointing upwards) clockwise. Try a tiny increment. These motion sensors are very sensitive.

If all is working well, your phone will say ‘Selfie time!’ every time the camera is triggered into action. This is extremely annoying. To turn off this alert go to ‘Settings’ then ‘Accessibility’ then ‘Hearing’ on your phone and switch on ‘Turn off all sounds’. Remember to turn this off again when you want to use your phone as a phone again, or you won’t be able to hear anyone!!!

So far I’ve only managed to capture my cat rolling about on a rug in our lounge. To make a true wildlife camera I need to design some sort of water proof case for the whole ensemble, and leave it outside somewhere (the bird table maybe) for a while. But for now, I’m very pleased with what I’ve got and I’m finally able to say I quite like the Samsung micro:bit app.

20161017_132532 Cookie the Cat

FacebookTwitterGoogle+Share

The Paper Round: The Best Route for a Marginal Gain

The current route (blue) is very inefficient because it doesn’t offload papers very quickly. It takes 4 units of distance (hops) to offload just 3 papers, and we still have 3 papers in the bag at H (hop 8) just 2 hops from the finish. If we take advantage of the fact that H is a block of flats where we delivery two papers, and head straight for that delivery (via D) then we can get rid of three papers in just two hops. This is the pink route on the map below.

Paper round best routeFrom H we cycle on to I, where we have a choice of routes to deliver the remaining five papers. Neither loop offloads papers faster than the other, so the decision here should be based on which offloads the heaviest paper/s first. E has the Telegraph, and J the Daily Mail if I recall, so lets take the loop that offloads the Telegraph first.

Bye the time we get to J (hop 8) we have delivered all our papers and have the luxury of cycling the final two hops with a paper free bag.

The marginal gains of the new route are probably best illustrated in a table.

Blue route Papers in bag Pink route Papers in bag
A
B
E
B
C
F
J
I
H
D
H
8
7
6
6
5
4
3
3
1
0
0
A
D
H
I
E
B
C
F
J
I
H
8
7
5
5
4
3
2
1
0
0
0
Hops = 10 Total Papers in bAG =  43 hOPS = 10 Total pAPERS IN BAG = 35

This may not look like a huge advantage, but remember these are the sort of ‘marginal gains’ British Cycling and Team Sky search for in the pursuit of Olympic gold and Tour de France glory. Just steer clear of the TUEs, unless you wake up with a bad cold!

The Paper Round: A Real World Exercise in Computational Thinking

Paper bag While doing my stepson’s paper round for him this morning, I couldn’t help but think the end part of the round seemed a bit inefficient.

Surely we can shave some time off the round by delivering these papers in a different order I thought. A little computational thinking (graph theory in this case) will reveal a shorter route is possible…

…so I drew a map (graph) of the current route, labelling the road junctions and mid points (called nodes or vertices in graph theory) A to J and marking the houses where papers are delivered with an X.

Paper round graph

The route must start at node A (there are papers to deliver just before we reach A) and finish at node H (the closest point to home).

The current route (blue arrows) A – B – E – B – C – F – J – I – H – D -H  has a total distance of 10 units, assuming the distance between each node is the same, which give or take a few metres it is. But I can’t beat 10 units!!! There is no shorter route.

But is there a marginal advantage to be gained by delivering the papers in a different order?

Given that newspapers are very heavy these days (especially on a Saturday and Sunday) which route minimises the number of papers in the bag and allows me (or my stepson) to cycle that bit faster? Can you prove which route is best? We always start with 8 papers at node A.