In the following circuit(picture) I am using 6 diodes, an alternative of 4.8V solar-panel:
const int V1 = A0;
const int V2 = A1;
float SolarVolt = 0.0;
float V1_VOLT = 0.0;
float V2_VOLT = 0.0;
float Id = 0.0;
int V1_value = 0;
int V2_value = 0;
double gateVoltage=150; //For Gate volt
double mstep=5.1;
int GatePin=2;
void setup() {
pinMode(GatePin,OUTPUT);
Serial.begin(9600);
pinMode(V1,INPUT);
pinMode(V2,INPUT);
}
void loop() {
analogWrite(GatePin,gateVoltage);
gateVoltage=gateVoltage+mstep;
Serial.print("GateVolt = ");
Serial.print(gateVoltage);
Serial.print(" ");
if (gateVoltage <= 0) {
mstep = 1;
} else if (gateVoltage>=255){
gateVoltage = 255;
mstep = -1;
delay(50);
}
V1_value = analogRead(V1);
V1_VOLT = (V1_value * 5.0) / 1024.0;
Serial.print("V1_VOLT= ");
Serial.print(V1_VOLT);
Serial.print(" ");
V2_value = analogRead(V2); // for Id1
V2_VOLT= (V2_value * 5.0) / 1024.0;
Serial.print("V2_VOLT= ");
Serial.print(V2_VOLT);
Serial.print(" ");
Id=V1_VOLT-V2_VOLT;
Serial.print("ID= ");
Serial.print(Id);
Serial.println();
delay(1000);
}