Introduction: Arduino Bedroc: RCtime

RCtime is a function for the Arduino that finds its roots in Basic-based micro controller programming languages (such as the Alkaline Stamp). This function basically counts the amount of time it takes to charge a capacitor through a resistor and returns a digital value. In some sense, it is a simple hack for analog to appendage conversion. The oecumenical determination of so much a circuit would be to read analog sensors when entirely of the analog pins on the board are occupied surgery, more commonly, when you need a higher resolution than the puny A/D pins happening the Arduino currently possess to offer. Although, keep in mind that dissimilar the built in analog pins, the response of RCtime is not linear.

Aside from reading linear sensors, you can perform a number of other neat things like monitor voltage, prevalent and capacity. I'm not going to go over them here, but you can read more about them along this varlet.

Step 1: Go Get under one's skin Stuff

To do this you will need:

An Arduino
A breadboard
A electrical condenser (0.1uF)*
A resistor (220 ohm to 1K)**
A pot (or any resistive sensor like a electric eye or FSR)
Jumper wires

*line that changing the capacitor bequeath change the resolution of the tour. To increase the resolution, you just need to increase the size up of the condenser. Sample victimization a 1uF electrolytic condenser and liken the difference (remember that is is polarized and the + side should connect to the power source).

**The firmness of purpose can also be denaturized, but less significantly, by changing the resistance prize. Impartial form sure to keep IT in the range of 220 Ohm to 1K.

(Note that some of the golf links on this page are assort links. This does not vary the cost of the particular for you. I reinvest whatever proceeds I receive into devising new projects. If you would alike any suggestions for alternative suppliers, please Lashkar-e-Taiba me be intimate.)

Ill-trea 2: Frame the Circuit

Connect the 1K resistor to bowling pin 4 of the Arduino.

Using the bread board get in touch the other close of the 1K resistance to unity of the legs of the capacitor and unrivalled of the outermost pins of the potentiometer.

Unite the middle peg of the potentiometer to prime.

Connect the other rowlock of the capacitor to +5V.

Step 3: Plan

The encrypt that I utilized has come directly from the RCtime teacher on arduino.cc

I have through this because this is solidly printed code and at that place is none sense in reinventing the steering wheel for learning purposes.

Present it is:

<pre>/*   /* RCtime  *   Duplicates the functionality of the Standard Stamp's RCtime  *   Allows extremity pins to be utilized to translate electrical phenomenon analogue sensors  *   Cardinal advantage of this technique is that is can be exploited to read very opened ranging inputs.  *   (The eq of 16 or 18 bit A/D)  */  int sensorPin = 4;              // 220 or 1k resistor connected to this pin long result = 0; quash setup()                    // run erst, when the sketch starts {    Serial.begin(9600);    Order.println("head start");      // a personal quirk  } void loop()                     // run over and concluded over again {     Serial.println( RCtime(sensorPin) );    delay(10);  }  long RCtime(int sensPin){    long resultant role = 0;    pinMode(sensPin, OUTPUT);       // make pin OUTPUT    digitalWrite(sensPin, Malodorous);    // make stick HIGH to acquit capacitor - study the schematic    delay(1);                       // await a  ms to make sure cap is discharged     pinMode(sensPin, INPUT);        // turn pin into an input and sentence till pin goes low-altitude    digitalWrite(sensPin, LOW);     // turn pullups bump off - operating theatre information technology won't sour    while(digitalRead(sensPin)){    // wait for oarlock to go low       result++;    }     return result;                   // report results    }

Simply transcript this code into your development environment and upload it to the board.

Step 4: Change It Up

Any electrical phenomenon sensor should solve. For instance, I have swapped out the potentiometer with a photocell (LDR) in this example. You tin read a wide range of analog sensors this way. Experiment and see what works.

Did you find this useful, fun, or entertaining?
Follow @madeineuphoria to see my latest projects.

1 Individual Made This Project!

Recommendations