Advertisement
Guest User

Sheet Arduino 4

a guest
Nov 19th, 2019
155
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.02 KB | None | 0 0
  1. String unit = "ohm";
  2. String unitC = "A";
  3. unsigned long Rzero;
  4. int VD;
  5. float current;
  6. float voltage = 5.09; //Voltaggio esatto Arduino 5.09V
  7. float resistance = 0.0; //Resistenza da individuare
  8. float tResistance = 0.0; //Resistenza totale
  9.  
  10. void setup() {
  11. // put your setup code here, to run once:
  12. Serial.begin(9600);
  13. }
  14.  
  15. void loop() {
  16. // put your main code here, to run repeatedly:
  17. pinMode(2,INPUT);
  18. pinMode(4,INPUT);
  19. pinMode(7,INPUT);
  20. pinMode(8,INPUT);
  21.  
  22. Rzero=391000;
  23. pinMode(2,OUTPUT);
  24. digitalWrite(2,HIGH);
  25. delay(100);
  26. VD = analogRead(A0);
  27. resistance = Rzero;
  28. pinMode(2,INPUT);
  29.  
  30. if(VD<105){
  31. Rzero = 45800;
  32. pinMode(4,OUTPUT);
  33. digitalWrite(4,HIGH);
  34. delay(100);
  35. VD = analogRead(A0);
  36. resistance = Rzero;
  37. pinMode(4,INPUT);
  38. }
  39.  
  40. if(VD<105){
  41. Rzero = 4650;
  42. pinMode(7,OUTPUT);
  43. digitalWrite(7,HIGH);
  44. delay(100);
  45. VD = analogRead(A0);
  46. resistance = Rzero;
  47. pinMode(7,INPUT);
  48. }
  49.  
  50. if(VD<105){
  51. Rzero = 466;
  52. pinMode(8,OUTPUT);
  53. digitalWrite(8,HIGH);
  54. delay(100);
  55. VD = analogRead(A0);
  56. resistance = Rzero;
  57. pinMode(8,INPUT);
  58. }
  59.  
  60. float RX = VD*Rzero/(1024-VD);
  61. unit = "ohm";
  62. current = voltage/(RX+resistance);
  63. unitC= "A";
  64.  
  65. if(RX>1000000){
  66. RX = RX/1000000;
  67. tResistance = (RX+resistance)/1000000;
  68. current = voltage/tResistance;
  69. unit = "Mohm";
  70. unitC = "μA";
  71. }else if(RX>100000){
  72. RX = RX/1000;
  73. tResistance = (RX+resistance)/1000;
  74. current = voltage/(tResistance/1000);
  75. unit = "Kohm";
  76. unitC = "μA";
  77. }
  78. else if(RX>1000){
  79. RX = RX/1000;
  80. tResistance = (RX+resistance)/1000;
  81. current = voltage/tResistance;
  82. unit = "Kohm";
  83. unitC = "mA";
  84. }
  85.  
  86. if(VD>1020){
  87. Serial.print("Lettura non significativa");
  88. Serial.println();
  89. }else{
  90. Serial.print(RX,2);
  91. Serial.print(unit);
  92. Serial.println();
  93. Serial.print(current,2);
  94. Serial.print(unitC);
  95. Serial.println();
  96. }
  97. delay(1000);
  98.  
  99.  
  100. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement