Store some output values from a sensor o an array

I am developing a rain sensor. My sensing device is a piezo plate. the readings from the sensor is displaying in a 16*2 LCD display. For now I have developed my code to this level. I want to store my sensor out put values to an array using five elements . In 10s time interval. please help me this is my first industrial based project

#include <TimerOne.h>
#include <LiquidCrystal.h>
LiquidCrystal lcd(12, 11, 5, 4, 7, 9);

int inPin = 2;
int inPinCounter = 0;

void setup () {
lcd.begin(16, 2);
Serial.begin(9600);
Serial.println();

attachInterrupt(digitalPinToInterrupt (inPin), countFallingPluse, FALLING);

}
void countFallingPluse()
{
inPinCounter++;
}

void loop() {

inPinCounter = 0;

lcd.print("Counter Reset");
delay(10000);
lcd.clear();

if

(inPinCounter>10 && inPinCounter<50) {
lcd.print("Low Rain");
delay(10000);
lcd.print("Counter Reset");
lcd.clear();

}
else if
(inPinCounter>50 && inPinCounter<100) {
lcd.print("Mid Rain");
delay(10000);
lcd.print("Counter Reset");
lcd.clear();
}
else if
(inPinCounter > 100) {
lcd.print("High Rain");
delay(10000);
lcd.print("Counter Reset");
lcd.clear();
}

else {
lcd.print("No Rain");

}

lcd.setCursor(0, 1);
lcd.print("Counts:");
lcd.print(inPinCounter);
delay(1000);
lcd.clear();

}`#include <TimerOne.h>
#include <LiquidCrystal.h>
LiquidCrystal lcd(12, 11, 5, 4, 7, 9);

int inPin = 2;
int inPinCounter = 0;

void setup () {
lcd.begin(16, 2);
Serial.begin(9600);
Serial.println();

attachInterrupt(digitalPinToInterrupt (inPin), countFallingPluse, FALLING);

}
void countFallingPluse()
{
inPinCounter++;
}

void loop() {

inPinCounter = 0;

lcd.print("Counter Reset");
delay(10000);
lcd.clear();

if

(inPinCounter>10 && inPinCounter<50) {
lcd.print("Low Rain");
delay(10000);
lcd.print("Counter Reset");
lcd.clear();

}
else if
(inPinCounter>50 && inPinCounter<100) {
lcd.print("Mid Rain");
delay(10000);
lcd.print("Counter Reset");
lcd.clear();
}
else if
(inPinCounter > 100) {
lcd.print("High Rain");
delay(10000);
lcd.print("Counter Reset");
lcd.clear();
}

else {
lcd.print("No Rain");

}

lcd.setCursor(0, 1);
lcd.print("Counts:");
lcd.print(inPinCounter);
delay(1000);
lcd.clear();

}`

Hello dhananjaya_l_bandara

Post your sketch, well formated, with comments and in so called code tags "</>" and a none-Fritzing schematic to see how we can help.

Have a nice day and enjoy programming in C++ and learning.

volatile

Although you display the message "Counter Reset", you don't ever reset the counter.

'delay()' is not a good way to do timing. See the "BlinkWithoutDelay" example for a way to do something periodically without using delay().

Your 'inPinCounter' variable should be marked 'volatile' and you should disable interrupts while reading or writing it in loop:

void loop() 
{
  static unsigned long timer = 0;
  if (millis() - timer >= 10000)
  {
    timer += 10000;  // Repeat

    noInterrupts();
    int localCount = inPinCounter;
    inPinCounter = 0; // Prepare for next interval
    interrupts();

    lcd.clear();
    if (localCount < 10) 
    {
      lcd.print("No Rain");
    }
    else if (localCount < 50) 
    {
      lcd.print("Low Rain");
    }
    else if (localCount < 100) 
    {
      lcd.print("Mid Rain");
    }
   else
    {
      lcd.print("High Rain");
    }
    lcd.setCursor(0, 1);
    lcd.print("Counts:");
    lcd.print(localCount);
  }
}

Sir can you help me to store my sensor values to the array

#include <TimerOne.h>
#include <LiquidCrystal.h>
LiquidCrystal lcd(12, 11, 5, 4, 7, 9);

int inPin = 2;
int inPinCounter = 0;

void setup () {
lcd.begin(16, 2);
Serial.begin(9600);
Serial.println();

attachInterrupt(digitalPinToInterrupt (inPin), countFallingPluse, FALLING);

}
void countFallingPluse()
{
inPinCounter++;
}

void loop() {

inPinCounter = 0;

lcd.print("Counter Reset");
delay(10000);
lcd.clear();

if

(inPinCounter>10 && inPinCounter<50) {
lcd.print("Low Rain");
delay(10000);
lcd.print("Counter Reset");
lcd.clear();

}
else if
(inPinCounter>50 && inPinCounter<100) {
lcd.print("Mid Rain");
delay(10000);
lcd.print("Counter Reset");
lcd.clear();
}
else if
(inPinCounter > 100) {
lcd.print("High Rain");
delay(10000);
lcd.print("Counter Reset");
lcd.clear();
}

else {
lcd.print("No Rain");

}

lcd.setCursor(0, 1);
lcd.print("Counts:");
lcd.print(inPinCounter);
delay(1000);
lcd.clear();

}

This topic was automatically closed 180 days after the last reply. New replies are no longer allowed.