Category Archives: Programming

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 Kayaker’s Conundrum: Solutions

Kayakers on the river Adur

Many thanks to everyone who suggested solutions to this conundrum.

It would appear there are two algorithms you can can follow to solve it. Your choice of algorithm depends on whether you live near the start or finish of the paddle. Either way, you only need one bike.

 

Algorithm 1: If you live near the start:

  1. Drive to the start, drop the two kayaks off. One of you stays with the kayaks.
  2. The other person drives to the finish, leaves the car there, then cycles back to the start and locks up the bike.
  3. You both paddle down the river to the finish.
  4. You both load the kayaks onto the car and drive back to the start.
  5. Unlock the bike, load it onto the car, and drive home.

Algorithm 2: If you live near the finish:

  1. Drive to the finish and lock the bike up.
  2. Drive to the start and unload the kayaks.
  3. You both paddle down the river to the finish.
  4. One of you stays with the kayaks, while the other unlocks the bike, cycles back to the start and loads the bike onto the car.
  5. Drive back to the finish, load the kayaks onto the car, and drive home.

Both algorithms work, whether you live nearer the start or the finish, but choosing the wrong algorithm could result in driving twice the distance you need to. Imagine the distance (by road) between start and finish is 10km, and you live at the start. Algorithm 1 will result in 20km of driving, while algorithm 2 will result in 40km of driving. If you live at the finish, it’s the reverse.

If you live midway between start and finish it doesn’t matter which algorithm you choose. they both involve 30km of driving.

So a little logic (‘selection’ in programming speak) is required before the correct algorithm is chosen:

IF home to start < home to finish

algorithm 1

ELSE

algorithm 2

How to fix ‘Unfortunately micro:bit has stopped’ error.

Screenshot_2016-09-20-18-15-42Screenshot_2016-09-20-18-16-00J5 microbit error

A few weeks ago, keen to use my micro:bit to control my Google Nexus 5’s camera I tried to install the Samsung micro:bit app. I was a little surprised when I was told (by the app) that it wasn’t compatible with my hardware. A bit annoying I thought, but it’s Samsung’s app so I thought maybe they’ve coded it so it only works on Samsung devices.

So last week when my new Samsung Galaxy S5 arrived I was keen to try the app again. Surely it will work with Samsung’s most popular smartphone. This time there was no polite incompatibility message, the app installed in an instant. I then used the app to pair my micro:bit and S5, and after a couple of failed attempts (where I didn’t follow the instructions properly it must be said) it appeared to have paired successfully. Brilliant I thought. Now lets have some fun.

Well, unfortunately that’s where the fun ended, because every time I tried to connect to my micro:bit with the app I instantly got the message ‘Unfortunately micro:bit has stopped’. I tried un-pairing and re-pairing my devices, updating my S5, and I even updated the firmware on my micro:bit. But still the same error message.

Then I did what I should have done in the first place: I googled the error message. I didn’t get a direct hit, but I did notice a lot of people were getting remarkably similar error messages with other apps installed on the S5 (and other smartphones). This was their solution and I can confirm it fixed my micro:bit app error a treat.

  1. From the home screen, tap ‘Apps’, then ‘Settings’.
  2. Scroll down to ‘Applications’ then tap ‘Application manager’.
  3. Scroll down to, and tap micro:bit.
  4. Tap the ‘CLEAR DATA’ button, then ‘Clear’ to confirm. This should clear the cache as well.

Unfortunately, now that the micro:bit app is working on my S5, I’m sorry to report that it isn’t actually very good. Writing code is extremely fiddly and it takes forever to compile. It could be that I’m not using it properly, so I’ll persevere for now. Watch this space for a full review of the app.