Wednesday, January 5, 2011

RadarSPOT

The new year has begun and I was not lazy. I'm still eagerly waiting for my arduino kit, but for the time being, I decided to experiment some more with my SunSPOTs and some sensors I had laying around.

As a start I decided to hook up my radar sensor to the SPOT. I used the radar module CON-RSM1650. It's operating voltage is from 4.75V to 5.25V and the supply current has to be 30mA to 40mA. I could use the +5V pin of the SPOT to power the radar module. The only thing to do was to limit the current with some resistors. I chose a 100Ω and a 47Ω resistor to limit hte current to 34mA. In the datasheet was stated that the outputsignal of the radar module is at a very low voltage level. That means that you need to build an amplifying circuit to enhance the signal so that it can be processed by a microcontroller. I took a LM358 operational amplifier and configured it as a non-inverting amplifier. That means that you have to connect the output to the inverting input. The weak signal that needs to be amplified is connected to the non-inverting input. The inverting input is also connected to ground and some resistors which define the amplification of the outputsignal. A very good and funny explanation of this circuit type can be found here. Now all that was left to do was to connect the ground pins of the SPOT and to connect the amplified outputsignal to an analog pin of the SPOT. I chose A0.

Here is a simplified schematic on how to connect everything:


In my example program, I check every 250ms for the current pin voltage on A0. If the value is above a certain threshold, the LEDs on the SPOT blink red.

RadarSPOT class:
import com.sun.spot.peripheral.Spot;
import javax.microedition.midlet.MIDlet;
import javax.microedition.midlet.MIDletStateChangeException;
import com.sun.spot.sensorboard.EDemoBoard;
import com.sun.spot.sensorboard.io.IScalarInput;
import com.sun.spot.util.Utils;
import java.io.IOException;

public class RadarSPOT extends MIDlet {

    private EDemoBoard edemo;
    private float range;
    private static final float vref = 3.0f;
    private IScalarInput adc[];

    private float getVoltage(int idx) throws IOException {
        return (vref * ((float) adc[idx].getValue())) / range;
    }

    protected void startApp() throws MIDletStateChangeException {

        try {
            new com.sun.spot.service.BootloaderListenerService().getInstance().start();
            edemo = EDemoBoard.getInstance();
            adc = edemo.getScalarInputs();
            range = (float) adc[0].getRange();
            int rawValue = 0;
            while (true) {
                rawValue = adc[0].getValue();
                System.out.println(getVoltage(0) * 1000 + "mV");
                System.out.println("rawValue: " + rawValue);
                if (rawValue >= 300) {
                    LEDIndicator.showAlarm();
                }
                Utils.sleep(125);
            }
        } catch (IOException ex) {
            System.out.println("Error reading A0: " + ex);
        }

    }

    protected void pauseApp() {
    }

    protected void destroyApp(boolean arg0) throws MIDletStateChangeException {
        Spot.getInstance().getSleepManager().enableDeepSleep();
    }
}
LEDIndicator class:
import com.sun.spot.sensorboard.EDemoBoard;
import com.sun.spot.sensorboard.peripheral.ITriColorLED;
import com.sun.spot.sensorboard.peripheral.LEDColor;
import com.sun.spot.util.Utils;

public class LEDIndicator {

    public static void showSPOTStarted() {
        EDemoBoard board = EDemoBoard.getInstance();
        ITriColorLED[] leds = board.getLEDs();
        for (int x = 0; x < leds.length; x++) {
            leds[x].setColor(LEDColor.BLUE);
            leds[x].setOn();
            Utils.sleep(50);
            leds[x].setOff();
        }
    }

   

    public static void showAlarm() {
        EDemoBoard board = EDemoBoard.getInstance();
        ITriColorLED[] leds = board.getLEDs();
        for (int x = 7; x >= 0; x--) {
            leds[x].setColor(LEDColor.RED);
            leds[x].setOn();
        }
        Utils.sleep(125);
        for (int x = 7; x >= 0; x--) {
            leds[x].setOff();
        }
    }
}
You can see in the video that it is triggered if the radar waves are reflected by my hand.