Tutorial.RCtime History

Hide minor edits - Show changes to output

February 10, 2009, at 04:50 AM by Paul Badger -
Changed lines 3-4 from:
If you have a lot of sensors to hook up, and use up all of your Duino's A/D pins, here's a workaround for reading any kind of resistive sensors on any digital pin.
to:
In situations where all of the Duino's A/D pins are used, RCtime is a workaround for reading any kind of resistive sensors on any digital pin.
February 10, 2009, at 04:48 AM by Paul Badger -
February 10, 2009, at 04:47 AM by Paul Badger -
Changed line 14 from:
* Allows digital pins to be used to read resistive analog sensors
to:
* Allows digital pins to be used to read resistive analog sensors
February 10, 2009, at 04:47 AM by Paul Badger -
Deleted line 12:
* Paul Badger 2009
Changed lines 14-15 from:
* To bad it's not in the Arduino Language eh?
* Allows digital pins to be used to read resistive analog sensors
to:
* Allows digital pins to be used to read resistive analog sensors
February 10, 2009, at 04:21 AM by Paul Badger -
Changed lines 9-10 from:
One virtue of RCtime is that it can be very wide ranging, reporting values that would require a 16-18 bit A/D input to read. One downside is that it's not perfectly linear.
to:
One virtue of RCtime is that it can be very wide ranging, reporting values that would require a 16-18 bit A/D input to read. One downside is that it's not perfectly linear, because charging a capacitor through a resistor does not yield a linear curve.
February 10, 2009, at 04:20 AM by Paul Badger -
Changed lines 3-10 from:
This






to:
If you have a lot of sensors to hook up, and use up all of your Duino's A/D pins, here's a workaround for reading any kind of resistive sensors on any digital pin.

This RCtime function duplicates the Basic Stamp's function of the same name. It can be used to read resistive sensors of any type. Change the capacitor size to achieve the desired resolution.

The function can also be used to read voltage output type sensors, such as the Sharp infrared distance sensor's with some caveats.

One virtue of RCtime is that it can be very wide ranging, reporting values that would require a 16-18 bit A/D input to read. One downside is that it's not perfectly linear.
Changed line 15 from:
* To bad it's not in the Arduino Language eh :)
to:
* To bad it's not in the Arduino Language eh?
February 10, 2009, at 04:11 AM by Paul Badger -
Added lines 1-75:
!! RCtime

This







[@
/* RCtime
* Paul Badger 2009
* Duplicates the functionality of the Basic Stamp's RCtime
* To bad it's not in the Arduino Language eh :)
* Allows digital pins to be used to read resistive analog sensors
* One advantage of this technique is that is can be used to read very wide ranging inputs.
* (The equivalent of 16 or 18 bit A/D)
*

Schematic
+5V
|
|
___
___ Sensing Cap
| .001 ufd (change to suit for required resolution)
| (102) pfd
|
sPin ---\/\/\/-----.
220 - 1K |
|
\
/ Variable Resistive Sensor
\ Photocell, phototransistor, FSR etc.
/
|
|
|
_____
___
_

*/

int sensorPin = 4; // 220 or 1k resistor connected to this pin
long result = 0;
void setup() // run once, when the sketch starts
{
Serial.begin(9600);
Serial.println("start"); // a personal quirk
}
void loop() // run over and over again
{

Serial.println( RCtime(sensorPin) );
delay(10);

}

long RCtime(int sensPin){
long result = 0;
pinMode(sensPin, OUTPUT); // make pin OUTPUT
digitalWrite(sensPin, HIGH); // make pin HIGH to discharge capacitor - study the schematic
delay(1); // wait a ms to make sure cap is discharged

pinMode(sensPin, INPUT); // turn pin into an input and time till pin goes low
digitalWrite(sensPin, LOW); // turn pullups off - or it won't work
while(digitalRead(sensPin)){ // wait for pin to go low
result++;
}

return result; // report results
}
@]

Share