Posts | Comments

Planet Arduino

Archive for the ‘Sonar’ Category

Sometimes the technology part of a project isn’t the hard part. It is having an idea for something both useful and doable. Sure, a robot butler that would do your cleaning and laundry would be useful, but might be out of reach for most of us. On the other hand, there’s only so many use cases for another blinking LED.

[Martinhui] knows how to use an ultrasonic sensor with an Arduino. Driving a motor isn’t that hard, either. The question is: what do you do with that? [Martin’s] answer: Automate a trash can. You can see a video of the result, below.

You can find commercial versions of this, of course, but what fun is that? The can is a bit small, but a larger motor or a different mechanical design could scale it up easily.

As robotic trash cans go, this isn’t that ambitious, but it is highly doable. If only it connected to the Internet.


Filed under: Arduino Hacks

If you have a good sense of balance, you can ride a unicycle or get on TV doing tricks with ladders. We don’t know if [Hanna Yatco] has a good sense of balance or not, but we do know her Arduino does. Her build uses the ubiquitous HC-SR04 SONAR sensor and a servo.

This is a great use for a servo since a standard servo motor without modifications only moves through part of a circle, and that’s all that’s needed for this project. A PID algorithm measures the distance to the ball and raises or lowers a beam to try to get the ball to the center.

Servos like this usually operate in radio control vehicles and they are very easy to drive. A pot coupled to the shaft generates a pulse that the servo internally compares to a pulse from the microcontroller. If the pulse is wider than the reference pulse, the motor drives in one direction. If the pulse is narrower than the reference, the motor operates in the other direction. Just how much it drives depends on how much difference there is between the two pulses. When the pulses match, the servo motor stops moving. This pulse arrangement is very simple to drive from a logic output on an Arduino or other microcontrollers.

The build details are a bit sparse, but you can see in the video the general layout, and she links to a similar project that inspired this one if you are looking for more details.

You can do the same trick in two dimensions if you prefer. Or perhaps you’d like to try using a time of flight sensor, instead.


Filed under: Arduino Hacks

Motion control is a Holy Grail of input technology. Who doesn’t want an interface that they can control with simple and natural movements? But making this feel intuitive to the user, and making it work robustly are huge hills to climb. Leap Motion has done an excellent job creating just such a sensor, but what about bootstrapping your own? It’s a fun hack, and it will give you much greater appreciation for the currently available hardware.

Let’s get one thing straight: This device isn’t going to perform like a Leap controller. Sure the idea is the same. Wave your hands and control your PC. However, the Leap is a pretty sophisticated device and we are going to use a SONAR (or is it really SODAR?) device that costs a couple of bucks. On the plus side, it is very customizable, requires absolutely no software on the computer side, and is a good example of using SONAR and sending keyboard commands from an Arduino Leonardo to a PC. Along the way, I had to deal with the low quality of the sensor data and figure out how to extend the Arduino to send keys it doesn’t know about by default.

The Plan

The plan is to take an inexpensive SONAR module (the HC-SR04) and an Arduino Leonardo and use it to perform some simple tasks by mimicking keyboard input from the user. The Leonardo is a key element because it is one of the Arduinos that can impersonate a USB keyboard (or mouse) easily. The Due, Zero, and Micro can also do the trick using the Arduino library.

I wanted to determine how many gestures I could really determine from the HC-SR04 and then do different things depending on the gesture. My first attempt was just to have the Arduino detect a few fingers or a hand over the sensor and adjust the volume based on moving your hand up or down. What I didn’t know is that the default Arduino library doesn’t send multimedia keys! More on that later.

How the SONAR Works

The SONAR boards come in several flavors, but the one I used takes 4 pins. Power and ground, of course, are half of the pins. In fact, my early tests didn’t work and I finally realized the module requires more power than I could draw from the Arduino. I had to add a bench supply to power the module (and, of course, I could have powered the module and the Arduino from the same supply).

The other two pins are logic signals. One is an input and a high-going pulse causes the module to ping (8 cycles at 40kHz). There is a delay and then the other pin (an output) will go high and return low when the module detects the return ping. By measuring the time between your signal to ping and the return, you can judge the distance. In my case, I didn’t care about the actual distance (although that’s easy to compute). I just wanted to know if something was farther away or closer.

pingThe scope trace to the right shows the sensor pointing at something relatively near. The top trace is the start pulse and the bottom trace is the input to the Arduino. The center trace is the output of the SONAR transducer. All the signal conditioning is inside the sensor, so you don’t need to worry about the actual signal processing to generate and recover the audio. You only need to measure the width of that bottom pulse.

The scope has persistence and you can see that the bottom trace does not always come out right at the same time (look at falling edge and you can see “ghosts” for previous samples. It shouldn’t come as a surprise that it may take a little effort to reduce the variations of the signal coming back from the SONAR.

Noise Reduction and Actions

Averaging

I wound up trying several different things to attempt to stabilize the input readings. The most obvious was to average more than one sample. The idea is that one or two samples that are way off will get wiped out by the majority of samples that are hovering around some center value. I also found that sometimes you just miss–especially when looking for fingers–and you get a very large number back. I elected to throw out any data that seemed way off when compared to the majority of received data.

Verifying

One other tactic I used was to verify certain elements with a second reading. For example, the start event occurs when the SONAR reports a value under the idle limit. The idle limit is a number less than the reading you get when the SONAR is pointed at the ceiling (or wherever it is pointing) and you don’t have anything blocking it. To recognize a valid start, the code reads twice to make sure the value is under the limit.

The code inside the Arduino loop is essentially a state machine. In the IDLE state, it looks for a reading that is below the idle limit. When found, that causes a transition to the sampling state. When the reading goes up or down more than some preset value, the code in the sample state sends a volume up or down key via the keyboard interface. If the sample goes back over the idle limit, the state machine returns to IDLE.

I got pretty good results with this data reduction,  but I also found the NewPing library and installed it. Even though it isn’t hard to write out a pulse and then read the input pulse, the NewPing library makes it even easier (and the code shorter). It also has a method, ping_median, that does some sort of data filtering and reduction, as well.

You can select either method by changing the USE_NEW_PING #define at the top of the file. Each method has different configuration parameters since the return values are slightly different between the two methods.

I said earlier that the code sends volume up and down commands when it detects action. Actually, the main code doesn’t do that. It calls an action subroutine and that subroutine is what sends the keys. It would be easy to make the program do other things, as well. In this case, it simply prints some debugging information and sends the keys (see below). I didn’t react to the actual position, although since the action routine gets that as a parameter, you could act on it. For example, you could make extreme positions move the volume up two or three steps at a time.

Sending Keyboard Commands

I wanted to send standard multimedia keys to the PC for volume up and down. Many keyboards have these already and usually your software will understand them with no effort on  your part. The problem, though, is that the default Arduino library doesn’t know how to send them.

Fortunately, I found an article about modifying the Arduino’s library to provide a Remote object that wasn’t exactly what I had in mind, but would work. Instead of sending keys, you have methods on a global Remote object that you can call to do things like change or mute the volume. The article was for an older version of the Arduino IDE, but it wasn’t hard to adapt it to the version I was using (version 2.1.0.5).

The action routine really only needs the UP_IN and DN_IN cases for this example. However, I put in all four branches for future expansion. Here’s the action subroutine:

void action(int why, unsigned value=0)
{
 Serial.print(value);
 switch (why)
 {
 case START_IN:
 Serial.println(" Start");
 break;
 case STOP_IN:
 Serial.println(" Stop");
 break;
 case UP_IN:
 Serial.println(" Up");
 Remote.increase();
 break;
 case DN_IN:
 Serial.println(" Down");
 Remote.decrease();
 break;
 }
}

The Final Result

sonarThe final result works pretty well, although the averaging makes it less responsive than you might wish. You can turn down the number of samples to make it faster, but then it becomes unreliable. You can download the complete code from Github. The first thing you’ll want to do is check the top of the file to make sure your module is wired the same (pin 3 is the trigger pin and pin 8 is the echo return pin). You’ll also want to select if you are going to use the NewPing library or not. If you choose to use it, you’ll need to install it. I flipped my Leonardo upside down and mounted it on a breadboard with some adapters (see picture to right). It really needs a more permanent enclosure to be useful. Don’t forget to give the SONAR module its own 5V power supply.

If you look near the top of the loop function there is an #if statement blocking out 3 lines of code. Change the 0 to a 1 and you’ll be able to just get averaged data from the sensor. Put the module where you want it and see what kind of numbers you get. Depending on the method I used I was getting between 4000 and 9000 pointed up to the ceiling. Deduct a bit off of that for margin and change IDLETHRESHOLD (near the top of the file) to that number.

The DELTATHRESHOLD is adjustable too. The code sees any change that isn’t larger than that parameter as no change. You might make that bigger if you have shaky hands or smaller if you want to recognize more “zones”. However, the smaller the threshold, the more susceptible the system will be to noise. The display of samples is helpful because you can get an idea how much the readings vary when your hand is at a certain spot over the sensor. You can try using one or two fingers, but the readings are more reliable when the sound is bouncing off the fleshy part of your palm.

If you want to add some more gestures, you may have to track time a bit better. For example, holding a (relatively) stationary position for a certain amount of time could be a gesture. To get really sophisticated gestures, you may have to do some more sophisticated filtering of the input data than a simple average. A Kalman filter might be overkill, but would probably work well.

If you look around, many robots use these sensors to detect obstacles. Makes sense, they’re cheap and work reasonably well. There are also many projects that use these to show an estimate of distance (like an electronic tape measure). However, you can use them for many other things. I’ve even used a similar set up to measure the level of liquid in a tank and earlier this week we saw ultrasonic sensors used to monitor rice paddies.

If you really want to get serious, [uglyduck] has some analysis of what makes spurious readings on this device. He’s also redesigning them to use a different processor so he can do a better job. That might be a little further than I’m willing to go, although I was impressed with the 3D sonic touchscreen which also modified the SONAR units.


Filed under: Arduino Hacks, Featured, peripherals hacks
Aug
03

David Cuartielles and Bruce Sterling at Sonar

CasaJasmina, education, Exhibition, Featured, keynote, Sonar, workshop Comments Off on David Cuartielles and Bruce Sterling at Sonar 

Photo: Sonar+D

Sónar+D is the international conference that brings together a combination of activities with a common theme: the relationship between creativity and technology and the digital transformation of the cultural industries involved.

During latest edition David Cuartielles gave a talk about the value of Open Source and a workshop with Alessandro Contini titled Making Noise with Arduino

David presented some examples like:

  • The Alcontrol Device (a breath analyser that detects high alcohol levels and limits mobile usage of a user depending on how drunk he/she is)
  • The involuntary dance machine that uses electrical stimulus to different muscles
  • A 5-day hack to a car that needed be driven remotely by musicians playing live
  • A large scale light installation for the Jakarta Marathon

He also got the opportunity to talk about robotics, kids learning code and electronics, and the future of Arduino. Later on Bruce Sterling, curator of Casa Jasmina,  was the protagonist of the festival’s closing keynote and talked about technology, music and the past/current state of the industry.

Photo: Sonar+D
News originally posted on Arduino Verkstad blog

IMG_7818Using an ultrasonic range sensor we can sense how far away objects are.

Read more on MAKE

Oct
03

Tinkernut’s Lamp Comes To Life Using Ultrasonic Waves

arduino, Electronics, General, lamp, Sonar Comments Off on Tinkernut’s Lamp Comes To Life Using Ultrasonic Waves 

Tinkernut’s Motion Controlled Ultrasonic Lamp takes uses sound to detect motionThe Motion Controlled Ultrasonic Lamp is great for beginners starting out with the Arduino Uno. It may or may not detect ninjas but will illuminate and follow most everyone else.

Read more on MAKE

Jul
03

The Funky Chicken

arduino, disabilities, interaction, Sonar Comments Off on The Funky Chicken 

Funky Chicken
The Funky Chicken was created during a series of workshops that were given as part of the larger project “Interactive Sensory Objects Designed for and by People with Learning Disabilities”:

It was designed by Rumena, a student from the Reading College LLD/D course (people with learning disabilities) who attended the workshops on a regular basis. She made the papier mache chicken, painted it and added the frills and ornaments, and wanted it to sit inside a basket but flap it’s wings and cluck. We helped her to complete this artwork by adding the necessary electronics including an Arduino Uno, Adafruit Waveshield, speaker and a servo to make the wings flap.

The whole flapping/clucking of the chicken is triggered using a sonar attached to Arduino Uno. Moving within 1m of the chicken will trigger it:

 In the image below the sonar is hooked up to the Arduino Uno, and the Arduino is connected to the servo controller (not shown). The sonar is a very inexpensive off-the-shelf HC-SR04, which has a range of about 3m.

Funky Chicken

Here’s the video with the chicken at work:

 

aluminalis-completed-rbw“Let’s build something creepy, Dad…”, my teenage daughters said. We had no idea this creepy crawly creature would utilize our machining skills to the fullest.

Read more on MAKE



  • Newsletter

    Sign up for the PlanetArduino Newsletter, which delivers the most popular articles via e-mail to your inbox every week. Just fill in the information below and submit.

  • Like Us on Facebook