Hi
thanks to all who have replied, I have decided to ditch the op-amp and bypassed it with just a voltage divider, which is working out a lot more better, I ditched the 5% and stuck with 1% resistors for better accuracy (still the same values 10K and 100K). I have also updated my code
code below
#define NUM_SAMPLES 10
int sum = 0; // sum of samples taken
unsigned char sample_count = 0; // current sample number
float voltage = 0.0; // calculated voltage
float voltage_change = 0.0;
int output_tran = 5;
void setup() {
// put your setup code here, to run once:
Serial.begin(9600);
pinMode(output_tran, OUTPUT);
digitalWrite(output_tran, HIGH);
}
void loop() {
while (sample_count < NUM_SAMPLES) {
sum += analogRead(A0);
sample_count++;
delay(10);
}
voltage = ((float)sum / (float)NUM_SAMPLES * 5.09) / 1024.0;
voltage_change = voltage * 12.000;
if (voltage_change < 9.80) {
digitalWrite(output_tran, LOW);
}
if (voltage_change > 14.00) {
digitalWrite(output_tran, HIGH);
}
sample_count = 0;
sum = 0;
}
The issue I am facing is that it doesn’t work that well. As you can see by my code the transistor turns off at 9.80 which is actually 10.2 on my bench power supply and turns on at 14.00 which is actually 13.00 on my bench power supply. the difference between the two is that before the voltage drop to 10.2 there is a load and before it comes back on at 13.00 there isn’t a load apart from the Arduino.
the track is connected to a DC- DC converter (traco power) which outputs 12V 2.5A (however only uses 1.5A) to differenct things, example PC, a router and a Radar, which all use 12V. the Vin to the traco is controlled by the Transistor.
is it possible that the issue is the vin voltage is on the same track as the vin to the voltage divider?