i need help dispalying the value

my code is this but it not displaying the value

int sense = A2;
int heater = A1;
int analogValue = 0;
void setup() {
  Serial.begin(9600);
  pinMode(heater, OUTPUT);
  pinMode(sense, INPUT);
}

void loop() {
  COCycle();
}

void COCycle() {
  digitalWrite(heater, HIGH);     // Turn heater on
  Serial.println("Purge started...");
  for(int i = 60; i > 0; i--) {   // Delay for 60 seconds
    Serial.println(i);
    delay(1000);
  }
  Serial.println("Purge complete...");

  Serial.println("Sensing...");
  analogWrite(heater, 71);        //1.4V PWM

  for(int i = 0; i <= 90; i++) {  // Read for 90 seconds
    Serial.print(i, DEC);
    if(digitalRead(sense) == 1)   // Show alarm if triggered
      analogValue = analogRead(A2)/4;
      Serial.print("   co2 dectected");
    Serial.println ( analogValue);
    delay(1000);
  }
  Serial.println("Sense complete...");

Not displaying it where? Serial monitor?

What do you have the baud rate set to in the Serial Monitor?

yes. and 9600

have you checked port being detected or not??

Goto device manager make ensure that port being detected properly. If not install driver again

I have attached driver pack here. Just update with this & try again

drivers.zip (1.19 MB)

if(digitalRead(sense) == 1)   // Show alarm if triggered
      analogValue = analogRead(A2)/4;
      Serial.print("   co2 dectected");
    Serial.println ( analogValue);

How does digitalRead of sense (A2) get to be ==1? Is it a floating input? If not ==1, then the code will ignore the analogRead instruction on the next line.

yes my port is being detected. im just 3 days into this. it's for my final year project. i'm a noob at this and i need to show voltage reading from the sensor into the uno board

can you send me screen shot of device manager & arduino IDE where these port being detected & set .

If you have team viwer ID share me ajit.nayak87@gmail.com. let me check once.

for(int i = 0; i <= 90; i++) {  // Read for 90 seconds

How many seconds?

AMPS-N:
can you send me screen shot of device manager & arduino IDE where these port being detected & set .

If you have team viwer ID share me ajit.nayak87@gmail.com. let me check once.

i pmed u the screenshots and it read for 90 seconds

and it read for 90 seconds

Close.

91 seconds (plus overhead)--91 times through a loop containing a 1 sec delay.

Does it print anything at all? "Purge started..." 60 times?

--Michael

Edit: I see I misread. It should print it once and then 60 new lines with counts. Does this happen?

ya it happen

Share us the value you getting on serial monitor DOC file. So we can understand . WHat exactly means displaying the value

I believe by "displaying the value" he means the value of the variable analogValue, which holds the reading from a CO2 sensor. The Serial.println for this has an extraneous space inside the parentheses; don't know if that matters.

The code as posted doesn't compile because it's missing a closing brace at the end of void COCycle() function.

I also notice that you use a digitalRead on the same pin (A2, aka sense) that you later analogRead. I don't have my board with me to test and don't know off the top of my head if this is a problem. Maybe somebody else here who's more experienced can say.

I'm guessing those long looped delays are for CO2 to "purge" and accumulate, yes?

Edit: BTW, in Serial.print(i, DEC) you don't have to specify decimal. It's default.
--Michael

The Serial.println for this has an extraneous space inside the parentheses; don't know if that matters

It doesn't

I found a few more minutes to look at this.

I don't find anything in the references that says you can't perform a digital read followed by an analog read on the same pin. That said, however, your problem has to be in that "if" statement:

if(digitalRead(sense) == 1)   // Show alarm if triggered
      analogValue = analogRead(A2)/4;
      Serial.print("   co2 dectected");

Two things. "digitalRead(sense) == 1" looks for a HIGH (ie, about 5 v) on that pin. What kind of sensor are you using that will give either a digital HIGH or an analog range? Something there that one of us doesn't understand. The other thing is the lack of braces on this call. Without enclosing braces, the compiler will only think "analogValue = analogRead(A2)/4;" is included in the conditional execution (the semicolon becomes the delimiter).

--Michael

can you send exact output of Serial monitor & code you are kept for testing.
The question i understand like you cant even open serial monitor.can you come on skype ajit.nayak87.

As per your code it showing proper outcome

Serialout.doc (26 KB)