Archive for December, 2008

Hall-effect Sensor

December 31, 2008
Hall Effect Sensor Pin Values

Hall-effect Sensor Pin Values

Today I got my first unipolar Hall-effect Sensor and was eager to find out how I could test it. But first there was the issue of how can you determine which pin is the input voltage and which pin the sensor out. The documentation, as with most electronics part documentation, is very terse and assumes that you already know everything. Click on the thumbnail to the left to see the value of the pins.

The Hall-effect Sensor incorporates a magnet. This magnet is on the center of the sensor. The side with no label is north and the side with the label (the branded side)  is south. If you hook up this sensor to a LED (with a pull-up resistor, pick a value that you normally use with your LEDs), when you move the north polarity of a magnet close to the sensor (the side with no label), the LED with light up. If you move the south pole of the magnet close to the side with the label, the LED will also light up.  I connected the sensor to 4 AA batteries (6 volts).

Hall-effect with LED test circuit

Hall-effect with LED test circuit

If you now hook up the sensor output to the red wire and the ground to the black wire of a oscilloscope, and start moving the north pole of a magnet back and forth within the range of this sensor you’ll see a square wave. 

This sensor is not particularly effective for weaker magnetic fields. In my test, a fridge sized magnet had to be millimeters away from this sensor for it to be detected. So depending on your application, you will need to pay careful attention on the Bop and Brp specs of this sensor and the requirements of your own application. Here is the sensitivity of this particular sensor:

Magnetic Properties of this Sensor

Magnetic Properties of this Sensor

Here is a good article on Hall-effect sensors that includes a useful trouble-shooting guide. For my application, I had to give up on this sensor and go with a magnetic sensor with 0.5 Gauss sensitivity, i.e., a magnet that can detect earth’s magnetic field.
 

 
Most linear Hall-effect sensors are ratio-metric, where the quiescent output voltage (typically half of the supply voltage) and sensitivity are proportional to the supply voltage. For example, with a supply voltage of 5 volts and no magnetic field present, the sensor’s quiescent output will typically be 2.5 volts and will change at the rate of 5 mv/g (milli-volts per gauss). The output of the sensor will depend on the regularity of the input. If the input magnetic field is defined by a rotating magnetic circle, then you may get a sine-wave type output. If you need a pulse output, then you must convert this sine-wave output to a square wave. Linear sensors act as input for analog-to-digital converters. A comparator cable needs to be added to the circuit to provide a set point or trip point and thereby convert the linear sensor into an adjustable digital switch.

unipolar Hall-effect sensor act as switches require a single polarity magnetic field for operation. When the magnetic flux density increases above the operate point (Bop), the unipolar sensor will switch on (output changing from high to low). When the flux density drops below the release point (Brp) the sensor will switch off (output changes from low to high). Typically, a unipolar sensor require a positive magnetic field (a south pole) directed toward the branded face of the sensor.

An omnipolar sensor will activate with either a north or a south pole.

latching sensor are digital output Hall-effect switches. They switch on (output from high to low) with a positive magnetic field and switch off (output from low to high) with a negative magnetic field. Both magnetic polarity are required for operation.

How much water can you get out of your main water pipe?

December 29, 2008

A typical residential water service in our area has a dynamic water pressure of about 65 PSI, and a 3/4 or 1 inch supply line. This roughly translates to about 17 to 32 gallons per minute maximum water flow.

Well exactly how much water is that?

32 gallon = 512 cups = 4096 ounces = 24576 teaspoons

17 gallon = 272 cups = 2172 ounces = 13056 teaspoons

32 gallons per minute is the same as 512 cups per minute, 4096 ounces per minute, or 24576 teaspoons per minute. Which is 0.53 gallons per second, 8.533 cups per second, 68.26 ounces per second or 409.6 teaspoons per second.

17 gallons per minute is 0.2833 gallons per second, 4.533 cups per second, 36.2 ounces per second or 217.6 teaspoons per second.

I’ve a 3/4 inch supply line with 65 PSI dynamic water pressure and I was expecting the maximum of 17 gallons per minute. Based on my actual measurement, I was able to get about 12 gallons per minute.

I took three measurements from the closest water outlet to the water meter, and on average I was able to get 1 gallons per 5 seconds (12 gallons per minute or 3.2 cups per second). I’m sure that just after the meter, the rate will be closer to 4.5 cups per second. I also took a measurement at the water outlet furtherest away from the meter but still with minimum splits and turns, and as expected I was getting a lower flow rate — 1 gallon per 7 seconds.

Static Water Pressure is the water pressure measured as close to the water meter by hooking up a pressure gauge to the pipe before the meter.
Dynamic Water Pressure is the pressure that you’re left with after the water flows thru the meter, the back-flow device, and all of the pipes.


1 CCF = 748 gallons
1 gallon = 16 cups
1 cup = 8 ounces
1 ounce = 6 teaspoons

1 pint = 2 cups
1 quart = 2 pints
1 quart = 4 cups
1 gallon = 4 quarts

Here is how you can calculate the water flow rate

Q = V * A

where, Q is the Volumetric flow rate, V is the velocity of the water, and A is the cross-sectional area of the passage.

You can compute the velocity of the water

P0 - P = (rho) * V ^ 2

Where P0 is the total pressure calculated using a pitot-static tube, P is the static pressure, rho is the density of the fluid (water has a density of 1), and V is the Velocity of the water.

Most Water Utilities in North America and Britain charge water per CCFs (748 gallons per CCF). In our area a CCF is about $2.25.

1 gallon = 0.3 cents
1 cup = 0.0019 cents
1 toilet flush = 1.6 gallon = 0.48 cents

Pulse Counter

December 29, 2008

The Arduino digitalRead function appears to be non-blocking. It reads either a LOW or a HIGH. If the pin you’re reading from is not connected to anything, it will read a random value. Here is a simple pulse counter that also measure the duration of the HIGH or LOW part of the pulse.

int pulsePin = 3;
int ledPin = 13;
unsigned long highCounter = 0;
unsigned long duration = 0;
int pulse = 0;
int lastPulse = LOW;
unsigned long timeNow = 0;
unsigned long lastTime = 0;

void setup() {
   pinMode(pulsePin, INPUT);
  // enable the 20K pull-up resistor to 
  // steer the input pin to a HIGH reading.
   digitalWrite(pulsePin, HIGH);   
   Serial.begin(9600);
   Serial.println("Pulse Reader - Version 2");
}

void loop() {
  pulse = digitalRead(pulsePin);
  if (pulse != lastPulse) { // pulse has changed
    timeNow = millis();
    duration = timeNow - lastTime;
    // blink the LED
    digitalWrite(ledPin, pulse);
    Serial.print(pulse);
    Serial.print(" ,");
    Serial.println(duration);
    lastPulse = pulse;
    lastTime = timeNow;
    if (pulse == HIGH) highCounter++;
  } 
}

Circuit Gear, Arduino and Counting Pulses

December 28, 2008

 

Square Wave Generated by Circuit Gear

Square Wave Generated by Circuit Gear

Arduino has a convenient function called pulseIn that you can use to count the HIGH or the LOW of a pulse. To test this, I created a square wave using the excellent Circuit Gear Waveform Generator.

I uploaded this program and connected the output of the waveform generator to the board (connect the Red wire to the Arduino pin 3, and the black to the Arduino digital ground). The program started printing the count of the HIGH pulses. As I adjusted the frequency of the square ware, the print out was getting faster or slower depending on the frequency of the wave. But as I started changing the amplitude of the square wave, I noticed than when the voltage difference between the LOW and HIGH of the square wave was less than 4 volts, the pulseIn function could no longer read the HIGHs. The documentation for the HIGH confirmed that the difference between the LOW and HIGH must be at least greater than 3 volts. In my case, anything less than 4 volts just didn’t work.

To show a waveform on the Circuit Gear, connect the output of the generator (leftmost connector) to one of the oscilloscope inputs (the two on the right). You’ll need something that can connect to BNC connectors, either alligator clip leads or adaptors or scope probes.

In other words, there is no internal connection between the output of the generator and the input of the oscilloscope, you have to add that.

(If you had another oscilloscope, you could also connect the output of the generator to that oscilloscope and view the waveform.)

Here is the pulse counter program for the Arduino:


int pulsePin = 3;
unsigned long counter = 0;
unsigned long duration = 0;
unsigned long timeout = 1000000; // in microseconds

void setup() {
  pinMode(pulsePin, INPUT);
  // enable the 20K pull-up resistor to steer
  // the input pin to a HIGH reading.
  digitalWrite(pulsePin, HIGH);
  Serial.begin(9600);
  Serial.println("Here we go again");
}

void loop() {
  duration = pulseIn(pulsePin, HIGH, timeout);
  if (duration == 0) {
    Serial.print("Pulse started before the timeout.");
    Serial.println("");
  } else {
    counter++;
    Serial.print(counter);
    Serial.print(", ");
    Serial.print(duration);
    Serial.println("");
  }
}

How to control GM862 from Arduino

December 20, 2008
Arduino to GM862 pin connection

Arduino to GM862 pin connection

It took some effort to figure out how to connect the GM862 GSM module to a UART (in my case the Arduino USB evaluation board, so I decided to document the steps here.

I also have the GM862 USB Evaluation board, if you plan to use this board and control the GM862 from Arduino, e.g., to programmatically send an SMS message, then you need to be careful how you power the GM862 USB board. If you power it via a battery or external power source (but not USB), then you’re fine. Otherwise, you must remove the jumper that disconnects the TX and RX pins from the GM862 USB FT232. To remove this jumper, you must remove the solder that is on the pins marked TX-I and RX-O. This Sparkfun.com board is not designed to accept a two pin header and a plastic jumper to allow you to easily switch between USB control and external control. So to get going, don’t use the GM862 USB to power the GM862, whilst it is being externally controlled through your Arduino board.

For a minimum implementation, only the TXD and RXD lines needs to be connected, the other signals of the GM862 modem serial port (DCD/pin 36, DTR/pin 43, DSR/pin 33, RTS/pin 45, CTS/pin 29, and RI/pin 30) can be left open provided a software flow control is implemented (which is what we are trying to do).

You’ll need to disconnect the RX pin 0 on the Arduino board each time you upload your program. If you don’t, upload will fail with the “avrdude: stk500_recv(): programmer is not responding” error message. After you’ve uploaded the program you can reconnect pin 0. Pin 1 can remain connected at all times, so there is no need to disconnect pin 1.

It helps to have a LED attached to the status indicator LED (pin 39 of GM862), but this is optional and not required for you to control the GM862 from Arduino. Pin 39 is an Open Collector output where we can directly connect a LED to show network and call status information (fast blink means net search, not registered or turning off, slow blink means registered full service, always on means a call is active). I connected a LED with a pull-up resistor.

After connecting the Arduino RX pin (pin 0) to GM862 RX-O pin (pin 37), Arduino TX pin (pin 1) to GM862 TX-I pin (pin 20), and Arduino Ground to GM862 Ground, you are ready to take control of GM862 right from Arduino (click on the thumbnail for detailed schematics). To test this set up, send a SMS message. Here is the code to do just that:

#include <SoftwareSerial.h>

int rxPin = 0;
int txPin = 1;

// set up a new serial port
SoftwareSerial serial=SoftwareSerial(rxPin,txPin);

void setup()  {
  pinMode(rxPin, INPUT);
  pinMode(txPin, OUTPUT);

  // set the data rate for the SoftwareSerial port
  serial.begin(9600);

  // Set SMS to text mode. Note it is critical 
  // to use \r\n to end each line
  // The delays are also critical, without them, 
  // you may lose some of the
  // characters of your message

  serial.print("AT+CMGF=1\r\n");
  delay(300);
  serial.print("AT+CMGS=");
  delay(300);
  // Replace with a valid phone number
  serial.print("+14081234567\r\n");
  delay(300);
  serial.print("Hello from Arduino.");
  delay(300);

  // End the SMS with a control-z
  serial.print(0x1A,BYTE);
}

void loop() {
}

Here is a function that takes a char array and use that as the content of the SMS. Not sure if a delay after each print statement is really needed or not.


#define PHONE_NUMBER  "+14081234567\r\n" 
#define PRINTDELAY 500

void sendSms(char msg[]) {
  modem.print("AT+CMGF=1\r\n");
  delay(PRINTDELAY);
  modem.print("AT+CMGS=");
  modem.print(PHONE_NUMBER);
  delay(PRINTDELAY);
  modem.print(msg);
  delay(PRINTDELAY);
  modem.print(",");
  delay(PRINTDELAY);
  modem.print(millis());
  delay(PRINTDELAY);
  // End the SMS with a control-z
  modem.print(0x1A,BYTE);
  delay(PRINTDELAY);
}

 

Select the correct GSM band – AT#BND

December 14, 2008

I just got my second Telit GSM862 Quad module and I could not get it to work. I could use various AT commands to find out various configurations of the system, but I could not send an SMS message or make a call. Well after going though the entire AT command manual and comparing the configuration of my first module versus the second module, I found out that the reason my new module was not working was that it was factory set to use band 0 (900MHz + DCS 1800MHz) instead of band 1 (900MHz + PCS 1900MHz), after setting the module to use band 1 — AT#BND=1 — the module starting working fine. Clearly, band 1 is the correct setting for US.

But why didn’t the module automatically pick the correct band? After all there is the AT#AUTOBND=1 command that is suppose to pick the correct band. The factory default is to disable automatic band selection. I suspect that the automatic selection consume more power and that is the reason why it is by default turned off.

Basic AT Commands for SMS

December 14, 2008
The list of AT commands is long, but there is basic set that I’m finding that I need to constantly refer to for testing, so here they are for ease of reference:

 

AT COMMAND
AT Echo OK means that you can connect to the device.

 

MODEL & CONFIGURATIONS
AT+CGMI Read manufacturer information
AT+CGMM Read model information
AT+CGMR Read software version
AT+CGSN Read serial number
AT&V Display base configuration
AT&V2 Display last connection statistics
AT#MONI Display neighboring cell information

BASIC SMS COMMANDS
AT+CMGF=1 Set SMS message format to text
AT+CMGS=“+14081234567″<CR>Hello, World.<Ctrl+z> Send SMS message
AT+CMGL=? List all messages. Depending on the CMGF settings (text or PDU), the argument to this command is a number from 0 to 4 or an enum. The ? parameter will inform you which one you’ll need to pass. Make it easier on yourself and set CMGF to text.
AT+CMGD=? Delete messages from memory.

DIAL A NUMBER
ATD +14081234567; Dial the given number. “;” is essential since it means make a voice call.

How to send a SMS message from Mac with Screen

December 2, 2008

I just received my GMS 862 Evaluation Board and here is how I managed to send my first SMS message (by reading this article and some trial and error):

  • Install the Virtual Com Port Driver (if you’ve already not done that) to be able to use USB to communicate with the board.
  • Connect the board to the USB port on your Mac. The red light on the board will light up indicating that it is getting power.
  • On the Mac, start the Terminal application
  • Find out the “name” for the serial port: issue the command ls /dev/tty.* 
  • The name will be something like /dev/tty.usbseria;-A80081n2
  • Start a serial session by using the screen application: issue the command screen /dev/tty.usbseria;-A80081n2 115200. To end the screen session enter control-a \
  • Start the GSM module (this is critical, if you don’t start it up then anything you type on the screen session simply wont show up and the AT commands will, of course, wont be sent to the GSM module. You can start up the module, by pressing and holding the little start button on the evaluation board for at least 1 second.
  • Issue the following 3 AT commands:


AT+CMGF=1
OK
AT+CMGW="+14081234567"
> HELLO WORLD!
+CMGW: 1

OK
AT+CMSS=1
+CMSS: 3

OK

The command AT+CMGF=1 will format SMS as a TEXT message.

The command AT+CMGW provides the phone number you wish to send the SMS message to. When you hit enter, the GSM module responds with >. Now you can enter your text message and you terminate it with control-z. The message is read into memory and the module replies with the message index.

The command AT+CMSS=1 sends the SMS message with the specified index.

Here is an excellent introduction to the SMS AT commands.


Follow

Get every new post delivered to your Inbox.