Introduction: SuperScope: Circuit Simulation Through Arduino-Processing Interface
Step 1: What You Will Need
*Resistors - Available @ RadioShack [Catalog #: 271-003 http://www.radioshack.com/product/index.jsp?productId=2994585]
*Capacitors - Available @ RadioShack [Catalog #: 272-802 http://www.radioshack.com/product/index.jsp?productId=2062376]
*Inductive Components (inductors, ferrite chokes, motors, transformers) - Available @ RadioShack [Catalog #: 273-102 http://www.radioshack.com/product/index.jsp?productId=2103978]
*SolderlessBreadBoard - Available @ RadioShack [Catalog #: 276-098 http://www.radioshack.com/product/index.jsp?productId=12165713]
*LM339 Comparator (probably my absolute favorite IC) - Available @ RadioShack [Catalog #: 276-1712 http://www.radioshack.com/product/index.jsp?productId=2062593]
*555 Timer (I recommend the TLC555) - Available @ RadioShack [Catalog #: 276-1718 http://www.radioshack.com/product/index.jsp?productId=2062595]
Step 2: Circuit Schematic
If you are using an op-amp instead of the LM339 comparator you may need to add in the positive feed-back loop depicted in the schematic.
The component you are testing connects to the two open circles.
Step 3: 1523 Lines of Code on the Wall...
The Processing Code:
The code is so large that instructables won't let me upload it as text :p
A text file and the processing app file are attached.
Attachments
Step 4: Whew... Only 94 Lines This Time
//The Arduino Code:
///////////////////////////////
#include <math.h>
byte chargePin = 9;
byte triggerPin = 8;
byte noninvertingPin = A0;
byte invertingPin = A1;
float constRes = 100;
unsigned long timeStart;
unsigned long timeEnd;
unsigned long timeDelta;
unsigned long capacitance;
unsigned long inductance;
unsigned long resistance;
unsigned long frequency;
String str;
char c;
void setup() {
Serial.begin(9600);
pinMode(chargePin, OUTPUT);
pinMode(triggerPin, INPUT);
pinMode(noninvertingPin, INPUT);
pinMode(invertingPin, INPUT);
str = "";
c = '\n';
}
void loop() {
while((Serial.available() > 0)) {
c = Serial.read();
if(!(c=='\n')) {
str += c;
}
else {
if(str == "requestFarads") {
testCapacitance();
Serial.println(capacitance);
}
else if(str == "requestHenrys") {
testInductance();
Serial.println(inductance);
}
else if(str == "requestOhms") {
testResistance();
Serial.println(resistance);
}
else if(str == "requestHertz") {
testFrequency();
Serial.println(frequency);
}
str="";
while(Serial.available()>0) Serial.read();
}
}
digitalWrite(chargePin, LOW);
}
void testCapacitance () {
digitalWrite(chargePin, LOW);
while(analogRead(noninvertingPin)>1) {}
timeStart = micros();
digitalWrite(chargePin, HIGH);
while(!digitalRead(triggerPin)) {if((micros()-timeStart)>5000000) break;}
timeEnd = micros();
timeDelta = timeEnd-timeStart;
//capacitance in nanoFarads
capacitance = (-1*((timeDelta*1000)/((log((1000000-(1000000*analogRead(invertingPin)/1024)))-log(1000000))*constRes)));
}
void testInductance () {
digitalWrite(chargePin, LOW);
while(analogRead(noninvertingPin)>1) {}
timeStart = micros();
digitalWrite(chargePin, HIGH);
while(digitalRead(triggerPin)) {if((micros()-timeStart)>5000000) break;}
timeEnd = micros();
timeDelta = timeEnd-timeStart;
//inductance in nanoHenrys
inductance = (-1*((1000*timeDelta*constRes)/(log(1000000*analogRead(invertingPin)/1024)-log(1000000))));
}
void testResistance () {
digitalWrite(chargePin, HIGH);
delay(100);
resistance = (float(analogRead(noninvertingPin))*100)/(1024-float(analogRead(noninvertingPin)));
}
void testFrequency () {
frequency = pulseIn(triggerPin, HIGH);
frequency += pulseIn(triggerPin, LOW);
frequency = 1/frequency;
}
Attachments
Step 5: A Few Notes...
I would like to thank http://www.hawkee.com/, http://www.radioshack.com/ and http://www.falstad.com/circuit/ for their help and resources.
You are free to disect the code an add to it if you wish (just don't forget to mention where you got it).
An immeasureable amount of time and work went into this project.
Please vote for this i'ble in the Arduino Contest!
Also, check out my YouTube Channel for more awesome electronics projects like a 360kV Marx Generator!
http://www.youtube.com/user/inductivecapacitor/feed