Help Needed with Sharp Tilt Sensor

I am trying to use a GP1S036HEZ tilt sensor in a project, and I am having a problem reading it digitally.

Here is my hookup: Pin 1 goes to 100Ohm resistor to arduino 5v pin Pin 2 goes to ground Pin 3 goes to Analog 0 and through XXXohm resistor to ground (pulldown) Pin 4 goes to Analog1 and through XXXohm resistor to ground pin 5 goes through YYYohm resistor to 5v arduino pin.

I have varied XXX and YYY and have received all kinds of results. At first I started with XXX as a very high resistor for pulldown but then all my readings were 1000+. I did see changes when tilted but only on the order of +- 15 Then I brought XXX down to 160Ohms and got values between 0 and 24. These values changed with tilting as they should, 0:0 for upright 25:25 for upsidedown etc. If I brought XXX to 320 I would get a bigger range 25-75, and at 500ohm 75-175 but there it would start acting flakey. At the 1000ohm level I am seeing 1000 high, but around 440 low, and the change in one direction is not correct.

My thought at that point is that I am pushing too much current through and that is messing things up. So I made YYY at 1K ohms but this did nothing.

I really just want to be able to read digital HIGH and LOW but am going to need better numbers (like 1000 for high and 300 or less for low) to do that.

Did I wire up something wrong?

Thanks, Ben

It sounds like you're using an 'analogRead()' call to read the sensor. But isn't it a digital sensor? Could you post your sketch code, please?

Sorry, originally I had a digitalRead, but this was always returning 1 value (depending on the resisters).

In digital domain, it is my understanding that 0V=LOW and since I had it plugged into an analog pin (pin0, which is the same as dig pin14), I moved to using that.

The code of the sketch is just setting the pin to input (in setup)

then doing int val=analogRead(mypin) Serial.println(val,DEC);

For my application (smart clock), I can use the output I am getting (0 or 15 from analog) but am confused as to why it is so small (15 is (15/1024)*5 V small)

I am also worried that I am wasting alot of power through those small pulldown resistors...can someone chime in on that? (5V directly through emitter to arduino pin and to 160 ohm resistor to that alot for the resistor to turn into heat?)

Thanks, Ben

is anyone could send me a sketch of the hookup for this tilt sensor, i can't mange to retrieve any datas.

Many thanks.