In this paper, we train a robot to learn online a task of obstacles avoidance. The robot has at its disposal only its visual input from a linear camera in an arena whose walls are composed of random black and white stripes. The robot is controlled by a recurrent spiking neural network (integrate and fire). The learning rule is the spike-time dependent plasticity (STDP) and its counterpart – the so-called anti-STDP. Since the task itself requires some temporal integration, the neural substrate is the network’s own dynamics. The behaviors of avoidance we obtain are homogenous and elegant. In addition, we observe the emergence of a neural selectivity to the distance after the learning process.