Loading [MathJax]/extensions/MathMenu.js

Thursday, 29 November 2018

Distance Sensor


Another online purchase saw me get a set of HC-SR04 Ultrasonic sensors. These sensors contain an ultrasonic transmitter and receivers. Sound waves sent from the transmitter reflect off a distant surface and are sensed by the receiver. The time taken for the round trip can be used to calculate the distance. Details how it works are on the datasheet.
The company that sold the sensor, www.elegoo.com provided an download for Arduino, this consisted of a library and sample sketch.
The .cpp and .h files needed to be setup as an Arduino Library. To do this i needed to copy the files to ~/Arduino/Libraries/SR04/  The SR04 folder must match the library name.
The simple sketch below could then be created:
#include "SR04.h"
#define ECHO_PIN 11
#define TRIG_PIN 12

SR04 sr04 = SR04(ECHO_PIN, TRIG_PIN);
long distance;

void setup() {
  // put your setup code here, to run once:
  Serial.begin(9600);
  delay(1000);
}

void loop() {
  // put your main code here, to run repeatedly:
  distance = sr04.Distance();
  Serial.print(distance);
  Serial.println("cm");
  delay(1000);
}

Unfortunately, when I tried to upload to the Arduino I got this error:

/home/jonathan/Development/Arduino/arduino-1.6.7/hardware/tools/avr/bin/avrdude: error while loading shared libraries: libreadline.so.6: cannot open shared object file: No such file or directory

Looking in the /lib/x86_64-linux-gnu folder I discovered I only had libreadline.so.7.
An upgrade to Ubuntu 18.04 meant the installed version of the Arduino IDE, 1.6.7 was no longer compatible. However, simply installing the latest version 1.8.7 resolved the problem and I was able to upload the sketch.
Finally I added a piezoelectric buzzer configured to beep more rapidly the closer something got to the sensor.


The speaker was plugged into pin 8 and ground, with the code changed as below:
#define SPEAKER 8
void loop() {
  // put your main code here, to run repeatedly:
  distance = sr04.Distance();
  Serial.print(distance);
  Serial.println("cm");


  tone(SPEAKER, 550, 100);
  int delayTime = distance * 10;
  delay(delayTime);
}


This is what the setup looked like:


In practice the maximum distance reported by the sensor was around 1.25m.

Tuesday, 27 November 2018

Why everyone should keep a Soldering iron (and wire stripper)


The children have a toy guitar which they played with for quite a lot, with plenty of dropping and banging before it disappeared in a cupboard for a few months. Here it is, plenty of buttons for playing tunes, LEDs and the like.

But horror, when it was found in the back of the cupboard and new batteries inserted absolutely nothing happened. Horror for the children I have to add, I didn't really miss the sound it made!

But given my geeky nature I had to see what was the problem.  Opening it proved to be tricky. Although not glued it was held together by 18 screws, some of which were very tight. Eventually the inside was revealed:


Fortunately, the reason nothing worked was immediately obvious.

The wire to the positive battery terminal had snapped off. So the fix was a quick strip of the insulation and soldering the wire back onto the terminal.

Finally, replacing 18 screws turned out to be a lot quicker and the guitar lit up and played as soon as it was turned back on!

I'm looking forward to years more play out of it !!

Tuesday, 13 November 2018

Bird Box Camera Failure

After 2 years of continuous filming. The BirdBox camera has finally failed.

The Raspberry Pi itself is fine, I could still log onto it but unfortunately, when I tried to start up the motion detector python it complained it couldn't find the camera and that I should try enabling the camera. Now, clearly I'd already done this so some more investigation was required.

I then tried to take a still picture with raspistill, but this returned the following:

mmal: Camera is not detected. Please check carefully the camera module is installed correctly

This didn't look good.

I decided to take the Birdbox down to investigate. Being November there are no issues around disturbing nesting birds and the box itself can be taken down and cleaned between September and January.

The Birdbox was showing signs of age but the Raspberry Pi and Power over Ethernet box both looked as good as new.


As for the camera, this was looking a bit worse for wear. It turns out a large spider had made a home under the camera and had made meals of a number of woodlice.



After getting the Camera IC indoors I could certainly now see some quite significant corrosion. This is clear in the image below taken with a microscope. In particular the C8 capacitor looks to have corroded completely. Notice also the droppings.


I have a spare camera so I'll be setting up a new installation. Next time I'll look at to seal it more thoroughly.

Some links I discovered while looking for what the corroded capacitor was for