basic algorithm implemented on arduino