DetroitTitan13:
Thank you for your help, it has greatly helped us to move forward. We are now having a problem that the buzzer is correct the first time the voltage is >= saturation, but then the buzzer just continues to go off without waiting anytime. How do we get the elapsed time to reset for each time when the voltages is <saturation?
Well first, let's clean up the code. Start by putting each curly brace on its own line and using the Auto Format Tool (Under Tools > Auto Format in the Arduino IDE).
// Start serial at 9600 baud
Serial.begin(9600);
The comment doesn't tell us much here.
pinMode(13, OUTPUT);
pinMode(9, OUTPUT);
If you're not going to tell us what these pins do via comments, you should be using descriptive const. This will also make it easier down the road to change pins:
In the Global Scope:
const int ledDisplayPin = 13;
const int someUnkownPin = 9;
and then in the setup:
pinMode(ledDisplayPin , OUTPUT);
pinMode(someUnkownPin , OUTPUT);
Then anywhere in your code where you do something with pins 13 or 9 (like digitalWrite()) use the named constants instead.
unsigned long time=millis();
This goes out of scope as soon as setup is finished, so it's useless
// Read the input on analog pin 0:
// Convert the analog reading (which goes from 0 - 1023) to a voltage (0 - 5V):
// Print out the value you read:
// Turn on light if voltage value is greater than 3.5V
Way too much white space and pointless comments. When you're asking people for help with your code, it's best to get rid of stuff like this.
float voltage = sensorValue * (5.0 / 1023.0);
Serial.println(voltage);
int voltageValue = 2.0;
...
if (voltage > voltageValue) {
The Arduino doesn't have a floating point unit, so any floating point calculations are fairly taxing on the new system. This is an example of where floating point calculations can be substituted with a couple simple arithmetic calculations before hand. Since you are assuming 5V = 1023 reading, you can multiple 1023 by 5/2 which gives you a result of 409. That means that you can simple do this:
int sensorValue = analogRead(A0);
if (sensorValue > 409)
...
In addition, in line 3, you are trying to assign a floating point value to an int. It may not affect the functionality, but it's confusing and unnecessary.
unsigned long elapsed= millis();
...
if (elapsed>=sitTime){
millis() tells you how long the Arduino has been running for. You don't want to compare the Arduino's runtime, you want to compare and elapsed time. In addition, once the if statement is over, elapsed goes out of scope, so it can't be used by any other part of the program.
digitalWrite(9, 125);
digitalWrite accepts the pin number and either HIGH or LOW. While 125 won't break it, it's again, confusing and unnecessary. Since I have no idea what this mystery pin is used for, I can't tell if you're trying to do with it. You might need analogWrite(), but that's just a shot in the dark.
if (voltage < voltageValue){
unsigned long upTime = millis();
Again, upTime goes out of scope as soon as the if statement ends, so this is doing nothing.
I recommend scrapping the majority of your code and starting over with the psuedo code that I posted.