Hi Guys,
A seemingly simple question that I cant find an answer to...
I need to read the output from an INA169 current sensor. When the output value exceeds 300mv as read on analogue read A0, my Arduino has some work to do.
My question is, what value should the threshold that the analogue read value is compared to be set at? Is it the mv (i.e 300 mv) value, or the equivalent integer value (which I think is 66?) once the analogue read value has been converted?
Lots of examples explaining how things are converted to between 0 and 1023, but I cant find any info on what value is actually compared to the nominated threshold value
// These constants won't change:
const int currentPin = A0; // pin that the current sensor is attached to
const int voltagePin = A1; // pin that the voltage sensor is attached to
const int relayPin = 13; // pin that the relay is attached to
const int threshold = 300; // the current draw threshold level that's in the range of the analog input
unsigned long starTime = 0; // global variable
unsigned long interval = 5000; // 5 seconds
bool relayFlag = false;
byte attempts = 0;
void setup() {
// initialize the RELAY pin as an output:
pinMode(relayPin, OUTPUT);
// initialize serial communications:
Serial.begin(9600);
}
void loop() {
// read the value of the current sensor:
int analogValue = analogRead(currentPin);
// if the analog value is high enough, power the relay:
if (relayFlag == false && attempts < 3 && analogValue > threshold)
{
digitalWrite(relayPin, HIGH);
relayFlag = true;
starTime = millis(); // start timer
}
if(relayFlag == true && millis() - starTime >= 5000UL)
{
// current time - start time >= 5 seconds
digitalWrite(relayPin,LOW);
delay(100); //this could be removed if needed
relayFlag = false;
attempts = attempts + 1;
}
} //END of loop
Cheers
Chris