latest update. i managed it. there was a problem with code.
i will try this. it seems this will work.
previous one did not care the panel voltages and accepts the first preset panel input voltage. ( which is actually make me able to add a potentionmeter and have varible pedelec settings- but i want presets)
rest of functions works. when halls ensor pulsing it gives voltage to thrtottle as i want, and when no pulse it cuts power. also if it matches the magnet on pedal sensor it also cuts power after a specified time. so now it acts like current control system.
here is latest code which i will try next.
i need to learn something. since battery pack is depleting over time, if i supply voltage from 36 volts pack, won't this effect arduino? if i use DC to DC converter from aliepxress will this work when it is depleting? it says converter input is 40 volt max. battery goes over 41.2 volts when fully charged.
i will try this. it seems this will work.
previous one did not care the panel voltages and accepts the first preset panel input voltage. ( which is actually make me able to add a potentionmeter and have varible pedelec settings- but i want presets)
rest of functions works. when halls ensor pulsing it gives voltage to thrtottle as i want, and when no pulse it cuts power. also if it matches the magnet on pedal sensor it also cuts power after a specified time. so now it acts like current control system.
here is latest code which i will try next.
Code:
int val = 0;
int panel = 11; //panel voltage input pin 2 3 4 volts preset.
int thr = 6; //voltage output
int THR1 = 150; // output preset voltage. approx 1.7 volts 8 bit. RC filter for PWM to DC.
int THR2 = 190; // 2.7 volts
int THR3 = 230; // 4.3 volts
int PNLLO = 400; // constant signal from control panel 2 volt. 10 bit
int PNLMD = 630; // 3 volt. 10 bit
int PNLHI = 800; // 4 volt. 10 bit
int ledPin = 13; //integrated led
int hallsensor = 2; // hall sensor pin.
int firsttime = 1;
unsigned long startTime;
unsigned long hallTime;
void setup()
{
pinMode(ledPin, OUTPUT);
pinMode(hallsensor, INPUT);
pinMode(hallsensor, INPUT_PULLUP);
digitalWrite(hallsensor, HIGH);
Serial.begin(9600);
}
void loop()
{
if ((digitalRead(hallsensor) == LOW) ) { //if panel gives 2 volts.
if ((firsttime == 1) && (panel > PNLLO)) {
startTime = millis();
firsttime = 0;
analogWrite(thr, THR1); // arduino has 1.7 volts output
val = digitalRead(panel);
Serial.println(val);
delay (400);
} else {
if ((firsttime == 1) && (panel > PNLLO)) { //adjustment required
startTime = millis();
firsttime = 0;
analogWrite(thr, THR2); //
val = digitalRead(panel);
delay (400);
} else {
if ((firsttime == 1) && (panel < PNLLO)) { //adjustment required
startTime = millis();
firsttime = 0;
analogWrite(thr, THR3); //
val = digitalRead(panel);
delay (400);
} else
hallTime = millis() - startTime;
if (hallTime >= 1) {
Serial.print("Time: ");
Serial.print(hallTime);
Serial.print(" milliseconds ");
Serial.print(int(hallTime / 1000));
Serial.println(" seconds");
}
if (hallTime > 500) { // if hall sensor matches to the magnet for more dan 0.5 sec
digitalWrite(ledPin, HIGH);
analogWrite(thr, 0); // cut power
}
}
}
} else if (firsttime == 0) { // if no pulse on hall sensor
firsttime = 1;
Serial.println("Time: 0 milleseconds; 0 seconds");
digitalWrite(ledPin, LOW);
delay (500);
analogWrite(thr, 0); // more than delay, cut power.
Serial.println("idle");
}
}
i need to learn something. since battery pack is depleting over time, if i supply voltage from 36 volts pack, won't this effect arduino? if i use DC to DC converter from aliepxress will this work when it is depleting? it says converter input is 40 volt max. battery goes over 41.2 volts when fully charged.