Replacing 1930's relays

MikeML

Joined Oct 2, 2009
5,444
To generate a delay of 5s, I would do this:

Code:
unsigned long time5;
pinMode(foo,OUTPUT);
...
digitalWrite(foo, high);     // turn port "foo" on
time5=millis()+5000;         //value of millis() when to turn it off

while millis()<time5         //wait until time has advanced by 5s
{ ...                        //optional stuff to do while waiting
}
digitalWrite(foo, low);      //turn port "foo" off
...
 
Last edited:

Thread Starter

offthegridshed

Joined Aug 24, 2015
22
Mike, I tried to add your code to the basic analogue read sketch example and use it to turn the board led on.
I hooked up a 12v power supply through the shunt and a small 6 watt globe as the current draw.

Things I discovered were that the INA board always had an output of around 13mv whether the light was on or not. (The shunt always has a small mv reading) I managed to play around with the threshold figure to get it to turn on or not, but the timing example didn't work.
Is the output from the INA board because I didn't have resistor to ground as in their example? Or am I just not pulling enough current to measure properly?
With the complexities of what I need the arduino to monitor, I'm starting to think the overall programming may be beyond me.

Here's the code I modified
// These constants won't change:

const int analogPin = A0; // pin that the sensor is attached to

const int ledPin = 13; // pin that the LED is attached to

const int threshold = 13.9; // an arbitrary threshold level that's in the range of the analog input

const int time5=millis()+5000; //value of millis() when to turn it off

void setup() {

// initialize the LED pin as an output:

pinMode(ledPin, OUTPUT);

// initialize serial communications:

Serial.begin(9600);

}

void loop() {

// read the value of the potentiometer:

int analogValue = analogRead(analogPin);

// if the analog value is high enough, turn on the LED:

if (analogValue > threshold) {

digitalWrite(ledPin, HIGH);

}

unsigned long time5;

while (millis()<time5 //value of millis() when to turn it off

)digitalWrite(ledPin, LOW); //turn port off

// print the analog value:

Serial.println(analogValue);

delay(1); // delay in between reads for stability
 
Top