[Solved]Digital Pin Low

This is my first project i have worked on for a day or two. I can not find a definite reference if LOW as a digital input is 0V or xV? What is the value of LOW, if the reference/supply voltage is 5v? I understand 5v is HIGH.

My project is using 2 analog inputs A0 / A1 to measure temperature as voltage, and outputs either HIGH or LOW after comparing those values to a single Digital Pin 13 as Output. I would like to take a HIGH or LOW value from a Digital Pin as INPUT, serving as a condition as whether the arduino should sleep or not to save power.

This is where i am at so far;

int tempPinA=A0;                                 //input read pin for LM35_A is Analog Pin 0
int tempPinB=A1;                                 //input read pin for LM35_B is Analog Pin 1
int outPin=13;                                     //output pin Pin13
float valA=0;                                       //variable_A to store the value from sensor_A
float valB=0;                                       //variable_B to store the value from sensor_B

void setup()
{
pinMode(outPin, OUTPUT);                  //outPin set to output
}
void loop ()                                       //loop
{
valA = analogRead(tempPinA);             //read the value of sensor_A
valB = analogRead(tempPinB);             //read the value of sensor_B
if (valA > valB)                                 //Check if temperature_A is greater than temperature_B
{
digitalWrite (outPin, HIGH);               //If temperature_A greater than temperature_B set outPin to ON
}
else                                               //Otherwise
{
digitalWrite (outPin, LOW);               //If temperature_A is equal or lesser set outPin to OFF
}
delay(300000);                               //wait 5 minutes
}

At Digital Pin X, i would like to have an LDR as input. And nest within the loop, SLEEP if Pin X is LOW, But if Pin X is HIGH reiterate the loop.

Any hints greatly appreciated

An LDR is not very good for generating the sort of signal you need for digital inputs. You should use it to drive a voltage comparator likee the LM399 before you feed it into the arduino.

This is because? 4v, 3v, 2v or even 1v is not an acceptable value for HIGH when 0v for LOW

I can not find a definite reference if LOW as a digital input is 0V or xV? What is the value of LOW, if the reference/supply voltage is 5v?

0V

As there is only one ADC in the Arduino the two readings short after each other will affect each other. There are several ways to overcome this, reading the analog port twice is the easiest way imho.

BTW If you press CTRL-T in your IDE the sketch will autoformat, making it easier to read

You can minimize the sketch considerably as TRUE and HIGH are equal and FALSE and LOW too I added some things, not tested BTW

#define INTERVAL  5 * 60 * 1000L 
#define OUTPIN 13
#define SWITCH 3

int tempPinA = A0;
int tempPinB = A1;

void setup()
{
  pinMode(OUTPIN, OUTPUT);
  pinMode(SWITCH, INPUT);
  digitalWrite(SWITCH, HIGH); // this enables the internal pullup resistor.
}

void loop () 
{
  digitalWrite (OUTPIN, analogRead(tempPinA) > analogRead(tempPinB));

  if (digitalRead(SWITCH) == LOW)  // connect the switch to GND and the pin , the internal pull up will keep it high when switch is not connected.
  {
    delay(INTERVAL);   
  }
}

However your version is more extendable ;)

robtillaart , looking at it many times now. Small is beautiful :) , was staring at SWITCH for quite a while, thankyou very much.

What is the value of LOW, if the reference/supply voltage is 5v?

According to the datasheet (Section 28.2 DC characteristics), an output LOW is a maximum of 0.9V for a 5V supply, and an output HIGH is a minimum of 4.2V for a 5V supply.

An input LOW is a maximum of 0.3 times the supply voltage, and an input HIGH is a minimum of 0.6 times the supply voltage.

Umm which datasheet? My Uno hasn't come yet, but i am using "Simulator for Arduino" by Vitronics, till then.

The processor's datasheet, available from the Atmel website.

Reference Atmel 328P-PU Datasheet http://www.atmel.com/Images/Atmel-8271-8-bit-AVR-Microcontroller-ATmega48A-48PA-88A-88PA-168A-168PA-328-328P_datasheet.pdf

Something to read :astonished:

29.2 "DC Characteristics"

JB_AU: This is because? 4v, 3v, 2v or even 1v is not an acceptable value for HIGH when 0v for LOW

No it is because of the speed of transition of the signal. Using the analogue input is all well and good but it will not allow you to wake up from a sleep mode which I believe is what you want to do.

Original question asked for Digital Input of Pin X, Hypothetical X

@Awol my datasheet for the 328P-PU section 28.2 is "Fuse Bits" Which Datasheet ? Can you provide a link?

Original question asked for Digital Input of Pin X, Hypothetical X

Answer is still the same using a LDR as a direct digital input is not what you want to do.

DCChars.pdf (45.7 KB)

Was trying for a down & dirty approach.

My initial idea was to count up 12hrs of operation time and sleep for 12hrs. or Place a resistor from gnd on the ldr, compare the voltage, then sleep.

Whichever results in the smallest amount of code.

Thanks everyone, i have learnt quite a lot today.

about power saving and sleep - http://www.gammon.com.au/forum/?id=11497 -

Excellent! You have really excelled :) I was planning to port this over to an ATtiny, dependent on final code size. Thanks heaps!