Electronic measuring of soil humidity - keeping your plants always nice, part 1

I love to have a lot of plans in my room, unfortunately I always forgot to water them and the result is that all of more demanding plans are dead in no time. It seems that only ferns and cactuses can survive with me! That's why I decided to make and device that could measure humidity of soil and warn me if it's too low.

In this post I will present a prototype that I made, it was created to check if this way would be enough or if I should use other methods (presented later in the post). The idea is to measure resistance of the soil - when it's dried, then of course there's not a lot of water in it, so it can't conduct electricity very well. As a control unit I hoped to use an old Arduino that I bought a couple of years ago. The device would be plugged to analog inputs, results would be stored in EPROM memory to protect them against power loss (additional piezo with built-in generator).

The device contains two electrodes plugged to the soil and a small capacitor plugged in parallel to filter noises. There's also a fotoresistor (and a capacitor plugged in the same way) to measure light intensity, that's because I wouldn't like to be waked up in the middle of the night to water the plants. The device would use two digital inputs of the Arduino.

Below you can see the device.

It works, but the results are unpractical:

  • different soil conduct different amount of electricity, so the device should be tweaked to each plant separately,
  • the capacitor plugged in parallel with electrodes can't discharge, probably I should also add a resistor in parallel to him
  • electrodes should be protected against moving or connecting in the ground.

I decided to leave this approach and make another check in the future:

  • I will place in a pot a small, hermetic container, it will be dug into the ground,
  • in this container I will place humidity sensor (a popular and inexpensive one that can be purchased online).

The humidity in the container will reflect directly humidity of the soil because it will be isolated from external environment.

That's what I will do, I didn't buy the sensors, so it's still waiting.

Ionization Chamber - my first attempt

The simplest of all gas-filled radiation detectors is the ionization chamber, today I will describe my first attempts to build and use it, I will also say a bit about my further ideas regarding this subject. The device is presented below.

The circuit is simple, it contains 2 (3 in later version) NPN transistors in Darlington configuration, the emitter is connected to the mass, the collector and Vcc is connected to a digital voltmeter, the base is connected to an electrode that is in a metal can, the can is plugged to Vcc. Vcc=5V (12V in later version). Input resistance of the multimeter is 10MOhm. In later version I plugged a capacitor 220nF in parallel to the multimeter, it was used to filter noises.

A can, together with the electrode makes an ionization chamber, rest of the circuit is used to gain a signal from the detector.

Temperature-measuring device made from two wires

Recently I've found an article about thermocouple, a simple device that can be used to measure temperature. It uses Seebeck effect where a current in conductor is created if the conductor is heated. The amount of current depends on temperature and type of the conductor.

The thermocouple consist of two different conductors, they are in the same temperature, but they create different amount of voltage because they are different materials. A thermocouple measure difference between those voltages.

I've tried built this sensor as simple as possible, so I used iron nail and a copper wire as parts of the thermocouple. I used a multimeter to measure voltage created by the thermocouple.

Is it possible to write a program in C without using semicolons?

Yes, it's possible! In this text I will show a set of tricks to do it. I will present this on a simple program that that reads two numbers from STDIN and prints theirs sum to the STDOUT.

Normally I would start this program from declaring two variables:

int a, b;

Unfortunately, there's a semicolon at the end of the line. It can be omitted by using variables already declared for the main function:

int main(int argc, char* argv[])

I will use argc as a and argv[0] as b. Normally, next thing would be reading two values from STDIN and placing them in a and b variables. It could be like this:

scanf("%d%d", &a, &b);

Once again, there's a semicolon! This one can be skipped by using 'if' statement:

if (scanf("%d%d", &a, &b)) {}

The same trick can be used for printing to STDOUT:

if( printf("%d", a + b ) ){}

Above code compiles and works correctly, but normally the main function should return zero if everything went OK:

return 0;

This semicolon can't be avoided by using the trick with 'if' statement, but we other construction can help here:

if(brk(0)){}

That's all, below is full source code:

#include <stdio.h>
#include <unistd.h>

int main(int argc, char* argv[]) {
    if (scanf("%d%d", &argc, &argv[0])) {}
    if (printf("%d", argc+argv[0])) {}
    if (brk(0)) {}
}

Leave a comment, if you know other interesting riddles or tricks that can be used here!

A proof of concept of a simple sonar

Sonar is a ship device detecting objects in surrounding water. It analyzes sounds that propagates in the water, an active sonar uses the sounds that it produces, a passive one uses the sounds from other sources (e.g. eruptions or sounds of other ships). A wide range of frequencies can be used, from infra-sounds to ultrasounds. A simple, active sonar can be built from a couple of electronic elements and a PC computer - I will present this idea here.

fake reservoir and a floating sonar

I used a piece of Styrofoam as a ship and a bowl as a water that surrounds the ship. The bottom of the "reservoir" is modeled by a couple of floors tiles.

Breaking CAPTCHA in Python

Usually CAPTCHAs are analyzed by using neural network, it's a good approach, but it may be overcomplicated in simple cases. Presented below, much shorter algorithm can produce sufficient results for uncomplicated CAPTCHAs.

In this algorithm an image with unknown letter is compared with samples of known letters, the letter in the most similar sample is probably also the letter in analyzed image. It was implemented as a Python script, usage presented below:

captcha breaker in python, sample of usage
bash-3.2$ python cracker.py test1.png 
e
other sample of usage of the script for breaking CAPTCHAs in Python
bash-3.2$ python cracker.py test2.png 
p

It can't be directly used on a raw CAPTCHA, firstly small artifacts have to be removed from the CAPTCHA, secondly each letter should be stored in a separate image.

Edge Detection by using Genetic Algorithms

Abstract

In this post I will present an algorithm for searching edges in images by using genetic approach.

Algorithm

The image is preprocessed before its usage, firstly Gaussian blur is used to remove small artifacts that could pollute the result. I could be also done by using image downsizing and upsizing as I presented in the post about breaking captcha. Secondly the image is converted to black and white version to simplify the implementation.

Original image:

input image used in edge detection based on genetic algorithm

Edges found by using a genetic algorithm (100 generations):

output image produced by genetic algorithm applied to search edges in the image

In presented version each children has only one parent, so gene change is provided only by mutation. Each specimen has two genes: X and Y that describes a location on the image. If a specimen has a good set of genes (they point to a location near the edge), then he's healthy and strong so he can breed, but if his genes are weak, then he's weak too and soon he dies. The edge is defined by a fitness function as a point that has neighbor points with different color.

Strong species breed so after couple of generations theirs children will cover the whole edge. The final result is a set of genes (each is a point on the image) in the last generation.