Category: Arduino

Again with the lasers

There is an Instructable up on using speakers as galvanometers for a laser projector. This looks just about optimal for the Nuiteblaster, as it provides readable text without defocusing or otherwise spreading the laser beam.

I’ve started building one, with a couple of modifications. Instead of resistors, I’m using diodes to snub the back-EMF from the speakers. I’m also using MOSFETS instead of transistors to switch the power to the speakers. MOSFETS have lower on-resistance than transistors, and so transfer more power and waste less energy as heat. They also have VERY low gate current (low enough to treat as non-existent for my purposes), so there’s no need for current-limiting resistors on the gates, although a resistor might be good to limit any ringing that might happen from slamming 5V into it. Since I’m driving it directly from a 5V microcontroller, gate drive and switching time hopefully won’t be a concern.

Low Power Electronics

I am building a set of strings of lights to illuminate a labyrinth. As someone walks the labyrinth, the strings of lights will light up ahead of them to show the way, and fade out behind them as they pass. Instead of doing the build from the ground up, I’m starting with solar-powered garden lights that charge during the day, and light a string of lights at night.

My initial thought was that this would be a pretty simple task. I’d rig each light with a Sharp IR ranger, poll the ranger, and light the lights when something got close enough. Once it passed, I’d set a timer based on how long it takes to walk a strand of lights, and then shut the lights off when the timer timed out.

Unfortunately, that idea went away when I got the solar light. The light uses a single 1.2V battery, and runs the LED strand by having a simple boost converter double that to pulses of around 2.5V at a high enough rate that the LEDs don’t look like they are pulsing. I figured I would get around that by rectifying the pulses using a voltage doubler, which would get me 5V for my microcontroller and sensor. Unfortunately, voltage doublers get you voltage at the expense of current. The Sharp IR rangers can eat around 20mA, and the microcontroller is another 15mA or so. With that amount of load, the voltage on the voltage doubler rapidly falls back to ~2V. The Sharp IR rangers don’t work at anything less than about 4 volts, so I couldn’t use them.

I decided that since I don’t need range measurement, just the presence or absence of something in the range of the detector, I could get by with lighting the area up with 38kHz modulated IR, and picking it up with an IR detector module like the ones used in TVs to receive the remote signal. The microcontroller can generate the modulation signal to drive the IR LED. I got the code to do it here, I think, but that site is down now. In practice, this works just fine. I used my Arduino to do a quick sketch of the detection circuitry, and got it to blink an LED.

Unfortunately, the IR detectors I have also don’t work with less than 5V. However, unlike the Sharp IR rangers, there are a bunch of manufacturers that make the TV remote receivers, and some of them operate down to 2.4V. I ordered some of these, and set up my microcontroller, IR LED, and remote receiver so I could blink an LED by sending a IR pulse.

That worked just fine on battery power, but running from the voltage doubler still drained the caps too fast. Powering the IR LED at reasonable brightness just took too much current. In order to let the capacitors in the voltage doubler recharge, I shortened the IR LED on time to a 10th of a second, and put the microcontroller in a very low power (i.e. it runs on microamps, rather than milliamps) sleep mode when it was not firing the LED. Since the circuit spends most of its time off, the IR detector is the main draw on the voltage doubler. So far, this seems to work. If I want to save even more power, I can power the IR detector from a pin of the microcontroller, and shut it down when the microcontroller goes down.

Soon, I’m going to test the full circuit. I’ll post about it if I have to make any wild and crazy hardware changes.

ToyBrain at the Maker Faire

I’ll be at the Cambridge Mini Maker Faire (details here, here, and here) this Friday, showing off my ToyBrain boards, LED art, and other oddities. Look for the guy with the unnatural red hair.

Chris Connors was kind enough to include my work from 2010 in his post about the Faire.

Touch and pressure sensing with the Arduino

A friend of mine is working on a device that requires multiple soft fabric pressure sensors over a volume approximately equivalent to a human arm. I have more Arduino experience than her, so I’m helping out with the electronic implementation details.

Our first attempt was to examine some commercial force-sensing resistors. These consist of a plastic layer with a pattern of interleaved contacts printed on it, and a layer of carbon-impregnated rubbery material over the contacts. The more pressure there is on the rubber, the more it touches the contacts and the lower its resistance becomes. These devices are very stable, yielding repeatable resistance measurements with repeated contacts. Unfortunately, they are of a fixed size, and cannot be cut or reshaped. They also are flexible, but not exactly soft.

Back of a set of force sensitive resistors, showing contacts

After discarding that approach, we tried making our own force sensitive resistors out of the conductive foam from IC packaging. This works, but has a couple of problems. The first is that the resulting device doesn’t have a simple response to force. Its resistance goes down when pressed, and goes back up when released, but it doesn’t always return to the same values, and the resulting sensor data is noisy. We also don’t have a good source for a lot of IC packaging foam.

Most recently, we’ve tried making a pressure sensor based on a capacitor. The Arduino CapSense library provides a simple way to turn two pins of an Arduino into a capacitance sensor. One plate of the capacitor is a sheet of conductive material, the other plate is the user, and is effectively connected to ground (or at least “away” as charges can leave the circuit that way). The page notes that you can use the capacitive sensing pad, covered with an insulator, as a pressure sensor with an approximately logarithmic response.

However, it also notes that putting a ground plane under the touch sensor makes the results more stable. Instead of doing that, I put down the sensing plate, made of copper-coated nylon, two layers of soft interfacing (A sewing material kind of like a sheet of stuffed toy stuffing) and a ground plate made of silver-coated spandex over the interfacing. Pressing on the ground pad compresses the interfacing and brings the ground plate closer to the sensing plate, increasing the capacitance, and registering as pressure to the sensor. Because the upper/interactive surface is the ground plate, it shields the sensing plate, so the capacitive pressure sensor does not also act as a proximity sensor and trigger before it is touched.

I taped the bottom layer down to my desk, and hooked a clip lead to it. This lead goes to pin 2 of my Arduino.
Bottom layer of fabric pressure sensor
Then I put two layers of interfacing on top.
Middle layer of fabric pressure sensor
Then I put the ground layer on top. This is connected to a clip lead that goes to a ground connection on the Arduino.
Top layer of fabric pressure sensor

In the finished device, there will probably be a stuffed fabric tube with rings of conductive fabric around it as sensors, surrounded by a layer of interfacing, and then by a conductive grounded layer. There will also likely be an outer layer of fabric to protect and decorate the whole thing. In order to determine if this is a good way to build the thing, I intend to use the technique to make a stuffed toy that can detect squeezing.

This is the code I used to read the values from the sensor:


 * CapitiveSense Library Demo Sketch
 * Paul Badger 2008
 * Modified by Abe Shultz 2012
 * Uses a high value resistor e.g. 10 megohm between send pin and receive pin
 * Resistor effects sensitivity, experiment with values, 50 kilohm - 50 megohm.
 * Larger resistor values yield larger sensor values.
 * Receive pin is the sensor pin - try different amounts of foil/metal on this pin
 * Best results are obtained if sensor foil and wire is covered with an insulator
 * such as paper or plastic sheet

CapSense cs_4_2= CapSense(4,2);        // 1 megohm resistor between pins 4 & 2, pin 2 is sensor pin

void setup()

void loop()
    long start = millis();
    long total1 =  cs_4_2.capSense(30);

    Serial.print(millis() - start);        // check on performance in milliseconds
    Serial.print("t");                    // tab character for debug window spacing

    Serial.println(total1);                // print sensor output 1

    delay(10);                             // arbitrary delay to limit data to serial port


Pololu makes a controller (called the “Baby Orangutan”) very similar to the one I am building. It has an Arduino-compatable microcontroller, 1A motor driver, and user IO lines. It is also cheap. However, there are a few things my design has that theirs does not.

The ToyBrain motor driver is replaceable. If you accidentally short the output pins and destroy the chip with overcurrent, you can remove it from the socket and replace it. The motor driver of the Baby Orangutan is a fairly fine-pitch SMD package, and so is difficult for the average user to desolder and replace.

Connections to the ToyBrain are also a bit more convenient than those on the Baby Orangutan. The ToyBrain has headers designed for servos, and headers for sensors that carry power for those sensors. The Baby Orangutan breaks all the pins out as single pins, leaving the user to deal with power wiring.

The ToyBrain uses the serial port for programming with a $5 FTDI cable available from multiple vendors. This means that it integrates very easily with the Arduino development environment, and it can send serial data back to an attached computer. The Baby Orangutan uses a USB to ICSP adapter to program the chip. It has the ability to send data back to a computer via serial, but it would require a second cable.

This post isn’t intended to slam Pololu. They make useful products with incredibly high quality. I know this because I buy their stuff. The point isn’t that my device is better, it’s that it’s different, in ways that make it better for me.

Some Short Notes

The ToyBrain project has been on hold for a variety of reasons, mostly time and money. I finally have enough money to order the motor driver chips I wanted from Digikey. They are on back order, but should arrive near the end of the month. Once I have those, I’m going to put together a little video of the first boards doing a variety of motor driving tasks. That video will go into a Kickstarter funding round to get the second edition of the boards produced and populated.

At least one of the ToyBrain boards is going to end up hooked to a computer via the serial port at one end, and a vibrating motor at the other end. I’m reviving an old project to add a teledildonics plugin to Pidgin. It will allow a remote user to use commands like /harder and /faster (and of course /softer and /slower) to control the speed of the vibrator. That one may not make it into the Kickstarter video.

I found an interesting post about laser power ratings recently. It covers the relationship between PWM and laser output power, which is going to be useful for the power supply that I’m building for my laser. Once I build that power supply, I’ll be in the rather interesting position of having designed a cutting laser power supply that can be built from easy-to-obtain materials. Hopefully, that will knock the price down enough that more people can do DIY CNC laser builds. I may also make that PCB available as a kit, so people can build their own.

I also looked up TEA Laser plans again, and started wondering about making a dye laser. The TEA laser emits in the UV range. so it could be used to pump a UV-reactive dye. Vitamin b12 (in energy shot drinks) and tonic water both are UV reactive, so it may be possible to make a yellow or blue laser using a dye that is drinkable. Normally, laser dye is a toxic dye in a toxic solvent, so this would be pretty neat for the home experimenter.


Adding smarts to common materials

I found a couple of neat sites, and figured I’d link them here so they get more google juice, or link sauce, or whatever combination of a wet thing and food seems appropriate.

The first is the MIT High-Low Tech Lab’s Kit of No Parts. This site has suggestions for ways to incorporate electronics into a lot of other materials, such as wood and cloth, to make more engaging interactive objects. Things like speakers built out of seashells are a lot closer to art than useful products, but that’s part of the intent. It also inspires me to build a device that records and plays sound, and hide it inside a very large seashell as an art project.

The second site is called How To Get What You Want, but that’s rather predicated on you wanting fabric sensors, odd conductive materials (felting wool!), hacked toys, and so forth. There are a lot of good ideas here, waiting to be remixed into other cool stuff.

New ToyBrain Board Design

Version one of the ToyBrain boards had a bunch of problems:

  • TX and RX were swapped on the serial line header
  • The ICSP header was backwards
  • There was no debug LED
  • The SMD resistor pads for the reset pull-up resistor were too small
  • The connection for the reset switch was a 0.1″ header rather than a proper footprint
  • There was a lot of wasted space

Despite all of that, I managed to eventually get them working, with a slowed-down version of the Arduino bootloader, adapters for the ICSP and serial headers, and much messing about.

The new board is smaller, measuring about 1.5″ by 1.28″, and adds a proper reset switch, a SMD LED for debugging, corrected resistor footprints, and a (in my opinion) slicker layout. I still didn’t add voltage regulation or mounting holes, but I may be able to get a little space for the holes by moving a few traces in the corners of the board.

Pride Goeth…

My ToyBrain boards are programmable over ICSP, but when I connect them to an FTDI USB-to-serial cable, I can’t load a program into them from the Arduino development environment. The error I get back is that the programmer is not responding, which could be caused by several things, listed here by increasing order of how tedious they are to check:

  1. I might have some misconfiguration on the USB ports or Arduino IDE. I can eliminate this possibility by using the same FTDI cable to program a known-working Arduino BBB. If that works, I know that my problem is off the end of the FTDI cable, in my own hardware.
      • I tried this, and got a working blinking light program on my BBB. This means my cable and computer are fine.
      1. I might have messed up the bootloader configuration for my board. I think this is somewhat likely, as I’m using the Arduino bootloader on a board that is running at 8MHz. If the Arduino bootloader or IDE requires the Arduino 16MHz crystal for proper timing, it is now running at half the normal clock speed, resulting in the serial timings being double what they should be. I can test this by telling the IDE to attempt to talk to the board at half of whatever the normal speed is, using the platform support in recent Arduino IDE releases. If it’s a timing issue, that should fix it.
        • This was the problem. I reflashed with the 8Mhz bootloader from here, and now I can load programs and have them run.
      2. I might have screwed something up in the reset or power circuitry of the Arduino (I already know I got TX and RX backwards). I can check out the connections with a voltmeter pretty easily. I can also burn an LED blink program to the board with ICSP and see if it runs.
        • The power and reset circuitry is fine. I burned a LED blinking test program to the board using the command avrdude -c usbtiny -p m8 -U flash:w:test.hex and got a square wave on port B, so the chip is running code and the fuses make at least enough sense that the onboard oscillator starts.
      3. I may have used bad fuse settings, and put it in some mode that doesn’t result in the bootloader starting. I can test this by burning my own LED blink program to the bootloader section and seeing if it blinks an LED. This won’t make it load code, but it will at least confirm that the bootloader is getting started.
        • This is covered by the previous section. The chip isn’t bricked, and it runs code.

      Victory is Mine

      As I suspected in my previous post, I did put the ICSP header on my boards backwards (or more accurately, flipped along its long axis). As a result, I burned up the chip on one of the boards when I plugged the ICSP header in. I also took a closer look at the chip that I had populated two of the boards with, an ATMega48, and found that it doesn’t have a separate bootloader section. The quicker wits among you are realizing that I should have checked that before I soldered it down.

      Since one board had a chip that had been operating as a resistive heater, and the other two had chips I didn’t want to use, I was left with one good board.This evening, I managed to burn the Arduino bootloader to that board.

      First, I threw together an adapter to flip the ICSP header back to the right layout. Using that and my trusty USBTinyICSP, I programmed the fuses for the chip like so:

      avrdude -c usbtiny -p m8 -P usb -B 32 -U lfuse:w:0xc4:m hfuse:w:0xca:m efuse:w:0xFF:m

      and burned in the arduino bootloader like so:

      avrdude -c usbtiny -p m8 -P usb -B 32 -U ./arduino-0022/hardware/arduino/bootloaders/atmega8/ATmegaBOOT.hex

      For the curious, the fuse settings are the same as the ones for the Arduino, as documented here, but with the clock selection set to 8MHz internal clock rather than 16Mhz external clock. I used this fuse calculator to find the proper values.

      Since that seemed to have worked, I removed the chips from the other three boards, replaced them with ATMega8s, and put bootloaders on them as well. Now I’m going to add IC sockets for the motor driver chips and see if I can get an LED blink program onto them.