Hi,

I am designing a counter on arduino uno. if i apply 5V on arduino analog pin it should count 1000 in one hour similarly if i apply half the volt the reading in an hour should be 500.

I map the analog input and add delay according to it and increment the integer by one.

But I am not able to control the gain of it as if I apply any other value of voltage on analog pin the the counter gain is out. Need help if there is any other way to do it.

Code file is attached.

Thanks

AH_met.ino (562 Bytes)

You need to integrate the voltage over time in a float, and use the integer part of the float as the count.

OP's code:

#include <LiquidCrystal.h>

const int rs = 12, en = 11, d4 = 5, d5 = 4, d6 = 3, d7 = 2;
LiquidCrystal lcd(rs, en, d4, d5, d6, d7);

unsigned int x=0;
float inp=A0;
float in1=0;

unsigned int z=0;

void setup() {
lcd.begin(20,4);
Serial.begin(9600);

}

void loop() {
int Delay=map(in1,0,1023,10800,3600);
z=x++;
lcd.setCursor(0,0);
lcd.print(z);

Serial.print(in1);
Serial.print("\t");
Serial.print(Delay);
Serial.print("\t");
Serial.println(z);
delay(Delay);

}

Not a good idea:

float inp = A0;
[...]

How often do you need the count? At one hour intervals, or do you require a "running count", i.e. the count during the one hour previous to now?

@Aarg I need running count

MarkT:
You need to integrate the voltage over time in a float, and use the integer part of the float as the count.

OP's code:

#include <LiquidCrystal.h>

const int rs = 12, en = 11, d4 = 5, d5 = 4, d6 = 3, d7 = 2;
LiquidCrystal lcd(rs, en, d4, d5, d6, d7);

unsigned int x=0;
float inp=A0;
float in1=0;

unsigned int z=0;

void setup() {
lcd.begin(20,4);
Serial.begin(9600);

}

void loop() {
int Delay=map(in1,0,1023,10800,3600);
z=x++;
lcd.setCursor(0,0);
lcd.print(z);

Serial.print(in1);
Serial.print("\t");
Serial.print(Delay);
Serial.print("\t");
Serial.println(z);
delay(Delay);

}

Hi Mark Thanks for the reply.

As I am new to arduino and programming stuff. Please give some example code for help if possble

Thanks