Category Archives: News

Blink a led with style

Basically, when we want to make a LED blink with an Arduino, the program will stick in a loop and hang on delays. Imagine if we want this LED to fade in and out. The program could take all the process time to do it, and the processor won’t be able to do something else. So I imagined a little piece of code that work like this: a list of commands is sent to the program and the LED will turn OFF and ON following these commands. The list of commands is executed, but he program can continue polling other methods. When the program has nothing else to do, it goes back blinking the LED. The timing is respected, but the number of steps to go from the start point to the stop point may vary when the micro-controller is busy doing something else.

The following steps explains how to use the program.

First, list the commands you want the LED do

Create an array containing the scheme that will be played by LED. Each row of this array contains four parameters:

    1. Start brightness;
    2. Stop brightness;
    3. Duration;
    4. Easying (not yet implemented).

The array look like this:

const int commandCount = 4;
int commands[commandCount][4] = {
    {0,255,1000,0}, // 1st command: Start with the LED off then go to full brightness progressively in 1 second.
    {255,255,5000,0}, // 2nd command: Keep the LED at full brightness for 5 seconds.
    {255,0,1000,0}, // 3rd command: Turn the LED off progressively in 1 second.
    {0,0,3000,0} // 4th command: Keep the LED off for 3 seconds.
};

Second, declare your LED

LED myled (LED_PIN, &commands[0][0], commandCount);
  • The first argument is the pin number where the LED is connected.
  • The second argument is the address of the first item of the array.
  • The third argument is the number of commands.

Finally, call the LED loop method in the Arduino loop method

void loop() {
    myled.loop();
}

You can also declare multiple LEDs. They will blink together accordingly to the timing you set.

You can get the source code on my Git account.

Do you hear something?

You probably saw a bit more of the project I am currently working on, the robot flower. I have completed the second prototype and it works as expected. Now, I want to give the robot the ability to interact autonomously with the environment. Not just be controlled has with the Wii Nunchuk.

I want the robot to interact with many things, but first, I wish it to detect which direction the sound come from around it. Then the flower could orient itself this way.

Sound detection technique

In think using three microphones and measure which one receive more sound will permit to know the sound direction. I saw some complex project in which they also acquire the distance by triangulation. This is too complex for what I want. The direction is enough.

Then I start digging the web for some schematics. I found many electret microphone amplifier build around an operational amplifier (Op-Amp) chip. So I check for cheap and preassembled ones on eBay. I bough different models before I get one that works as expected. Almost all the microphones breakout boards I found only detect impacted sounds, like hand clapping. I need one enough sensible to capture voice.

Electret microphone circuit boards

The advantage I found with these microphones is that it possible to connect them directly to an analog to digital converter. Then the signal can be interpreted by a microcontroller.

Testing the microphones

To find the best one for me, I first check with my DSO Nano oscilloscope what is going on at the microphone circuit output. But the real test has been to hook the microphone to my Arduino ADC input. Then with Processing, I plotted the value of the analog input on my screen. This way I really saw how they reacted to sounds and what can I get from it.

Multiplexed analog to digital converter

Then came the time I tried with two. I quickly faced the fact that the Arduino ADC reads only one input at once. It cycled to read all entries. The delay to switch from one to another take a few milliseconds. Because my idea is to get the highest microphone input at precisely the same time, using this method is useless. This delay broke all my expectation of simplicity.

After some thinking and Googling, I saw a way to use the Arduino’s ADC as a comparator.  This idea may be interesting for testing purpose, but it only works with two inputs. I continued my research and look for other microcontrollers, circuits or chips. I saw some very expensive professional devices, no microcontrollers that can do that, and finally a bunch of  ICs (AD7865) specialized for that task. However, I did not found any breakout boards for theses simultaneous-sampling ADC ICs and build one is a project by itself. So I slept on that.

Compare analog inputs

The next day I imagine another way. Not tested yet. I will need to put some parts and wires together first. My idea is to compare each input with an Op-Amp, then send the digital logic output to the Arduino.

Compare three inputs

The microcontroller will be able to understand which microphone is the highly stimulated. I think it will be possible to sample the data over a short period of time, then average the result to know which direction the sound come from. So the next step is to put all this on my proto board and test my theory!

Swash plate actuated by three servos

These lasts weeks, I work a little on the first idea that makes me renew with DIY electronics. I won’t currently tell what it is all about, I’m not ready for that now. But I want to share what giving me a headache for now. The idea is to make a plane tilt and lift, following the movement of three servo actuators. The following video of the cardboard prototype demonstrate the mechanism.

Recently I replace the mechanical part with a RC helicopter swash plate. It’s much more efficient for this prototype.

The swash plate

Servos, linkages and swash plate

The body and the servos linked to the Arduino

I tried to do the formula myself, but I’m really rusted in trigonometry. A friend’s coworker give me great help. He wrote the formula I needed to make the motor move like I imagine.

I wanted the servo motors to be actuated from a given angle of inclination, the direction of this inclination and an offset in height. There is the formula. It needs some adjustment for the offset. I still don’t really understand how to calculate it. I want the height to be relative to the ray of the swash plate.

void calculateHeights( double phi, double theta, double H, double R, double &L1, double &L2, double &L3 )
{
	const double phi1 =   0*pi/180;
	const double phi2 = 120*pi/180;
	const double phi3 = 240*pi/180;

	double x1 = R*cos(phi1);
	double y1 = R*sin(phi1);

	double x2 = R*cos(phi2);
	double y2 = R*sin(phi2);

	double x3 = R*cos(phi3);
	double y3 = R*sin(phi3);

	double nx = cos(theta)*sin(phi);
	double ny = sin(theta)*sin(phi);
	double nz = cos(phi);

	double D = nz*H;

	L1 = ( D - nx*x1 - ny*y1 ) / nz;
	L2 = ( D - nx*x2 - ny*y2 ) / nz;
	L3 = ( D - nx*x3 - ny*y3 ) / nz;
}

This is it for now. I’ll work on the function and get back with it. If you understand more than me, any help is welcome!

A work in progress

The summer is over, so much time to type some lines of code. I work hard to make an updated version of my little Integer to serial relay, Insek. Obj-c is not familiar for me, but I like to lern it. I’ve just created a project page on Google code to distribute the files, show code examples, and maintain the development. Currently, I’m working on the communication from the serial device (the Arduino) to the computer (Insek). It’s work, but I have many issue with the the data inputs buffering. Follow the development on Insek project home page. If you can help developing this project, you are welcome!

Make things works

Well, now that all things are weld together, I’m investigating the programmation. At this time I want to build an app in Objective-C Cocoa for Mac. I’m totally new to it. I work hard to create an app that will act as a Web server that send the data received from an Internet connexion to the serial port of the Arduino. I found some base code that will probably help me doing it. I’ll let you know when I’ll succeed.

All parts are assembled and it’s ready to be programmed

All the mechanicals parts and the control boards are now assembled and wired up together. All functions have been tested separately. Now come the time to do some programming. But before I will show you what I’ve already done in my next posts.

Because some pins of the Arduino have a special function, like interrupt, the connections on the proto will be useful to connect thinks to the right pins when I will start programming. I’ll probably use my previous (modified yesterday) multitasking script to be able to control all things at virtually the same time.

Glowing Marquee prototype assembled and wired up