Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- String unit = "ohm";
- String unitC = "A";
- unsigned long Rzero;
- int VD;
- float current;
- float voltage = 5.09; //Voltaggio esatto Arduino 5.09V
- float resistance = 0.0; //Resistenza da individuare
- float tResistance = 0.0; //Resistenza totale
- void setup() {
- // put your setup code here, to run once:
- Serial.begin(9600);
- }
- void loop() {
- // put your main code here, to run repeatedly:
- pinMode(2,INPUT);
- pinMode(4,INPUT);
- pinMode(7,INPUT);
- pinMode(8,INPUT);
- Rzero=391000;
- pinMode(2,OUTPUT);
- digitalWrite(2,HIGH);
- delay(100);
- VD = analogRead(A0);
- resistance = Rzero;
- pinMode(2,INPUT);
- if(VD<105){
- Rzero = 45800;
- pinMode(4,OUTPUT);
- digitalWrite(4,HIGH);
- delay(100);
- VD = analogRead(A0);
- resistance = Rzero;
- pinMode(4,INPUT);
- }
- if(VD<105){
- Rzero = 4650;
- pinMode(7,OUTPUT);
- digitalWrite(7,HIGH);
- delay(100);
- VD = analogRead(A0);
- resistance = Rzero;
- pinMode(7,INPUT);
- }
- if(VD<105){
- Rzero = 466;
- pinMode(8,OUTPUT);
- digitalWrite(8,HIGH);
- delay(100);
- VD = analogRead(A0);
- resistance = Rzero;
- pinMode(8,INPUT);
- }
- float RX = VD*Rzero/(1024-VD);
- unit = "ohm";
- current = voltage/(RX+resistance);
- unitC= "A";
- if(RX>1000000){
- RX = RX/1000000;
- tResistance = (RX+resistance)/1000000;
- current = voltage/tResistance;
- unit = "Mohm";
- unitC = "μA";
- }else if(RX>100000){
- RX = RX/1000;
- tResistance = (RX+resistance)/1000;
- current = voltage/(tResistance/1000);
- unit = "Kohm";
- unitC = "μA";
- }
- else if(RX>1000){
- RX = RX/1000;
- tResistance = (RX+resistance)/1000;
- current = voltage/tResistance;
- unit = "Kohm";
- unitC = "mA";
- }
- if(VD>1020){
- Serial.print("Lettura non significativa");
- Serial.println();
- }else{
- Serial.print(RX,2);
- Serial.print(unit);
- Serial.println();
- Serial.print(current,2);
- Serial.print(unitC);
- Serial.println();
- }
- delay(1000);
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement