i’ve a one Water Flow sensor connect to Arduino with pin 11, the sensor result is work perfectly on arduino uno or mega.
but when i try to upload with USBasp to Atmega32 in pin PD3. and the Water Flow Sensor in pin PD3
the sensor can’t show the flow sensor result.
how to solved this?
thanks
#include <LiquidCrystal.h> //avr
const short rs = 16, en = 18, d4 = 20, d5 = 21, d6 = 22, d7 = 23; //lcd
LiquidCrystal lcd(rs, en, d4, d5, d6, d7); //lcd
#define flowsensor 11//11 in UNO PD3/INT1/d11 in ATMEGA32
float lt = 0;
float targetlt = 0;
long int targetrp = 0;
long int hrg = 8000;
int timerseg = 0;
volatile byte pulseCount;
float flowRate = 0;
float flowml = 0;
float flowl = 0;
float totalml = 0;
unsigned long oldTime;
byte sensorInterrupt = 0;
unsigned int frac;
short kal = 60;
void setup() {
pinMode(15, OUTPUT); //avr
pinMode(16, OUTPUT);//avr
pinMode(17, OUTPUT);//avr
pinMode(18, OUTPUT);//avr
pinMode(19, OUTPUT);//avr
pinMode(20, OUTPUT);//avr
pinMode(21, OUTPUT);//avr
pinMode(22, OUTPUT);//avr
pinMode(23, OUTPUT);//avr
digitalWrite(19, HIGH);//
lcd.begin(16, 2);
pinMode(flowsensor, INPUT);
digitalWrite(flowsensor, HIGH);
}
void loop()
{
if ((millis() - oldTime) > 1000)
{
detachInterrupt(sensorInterrupt);
flowRate = ((1000.0 / (millis() - oldTime)) * pulseCount) / (kal / 10);
oldTime = millis();
flowml = (flowRate / 60) * 1000;
totalml += flowml;
flowl = flowml / 1000;
lt = totalml / 1000;
frac = (flowRate - int(flowRate)) * 10;
pulseCount = 0;
attachInterrupt(sensorInterrupt, pulseCounter, FALLING);
pulseCount = 0;
lcd.setCursor(0, 0);
lcd.print(flowml);
lcd.setCursor(0, 1);
lcd.print(totalml);
int huntu=huntu+1;
lcd.setCursor(13, 1);
lcd.print(huntu);
}
}
void pulseCounter()
{
// Increment the pulse counter
pulseCount++;
}