Hi,
i am new to programing with arduino and i am having problems, so i was hopping you can help me.
I am using an arduino pro mini 3,3V and i want to make an automated pump. The pump is turned on with a flow switch and turned off with a water flow sensor. The problems are:
- I have an LCD 20x4 and it displays strange symbols through the whole display.
- I am having problems with the counter. I want to make A counter that you can set how much water can pass through the flow sensor then stops the pump. To reset the counter you have to hold the button for 10sec.
i hope someone can help me with this
thank you
// include the library code:
#include <LiquidCrystal.h>
// initialize the library with the numbers of the interface pins
LiquidCrystal lcd(12, 11, 5, 4, 3, 2);
int button = 0;
byte ledPin = 10; // led on pin 10
int VolumeSetting = 0;
int Mainvolume = 0;
int PumpON = 1;
int PumpOFF = 0;
int stateofpump = 0;
// which pin to use for reading the sensor? can use any pin!
#define FLOWSENSORPIN 7
// count how many pulses!
volatile uint16_t pulses = 0;
// track the state of the pulse pin
volatile uint8_t lastflowpinstate;
// you can try to keep time of how long it is between pulses
volatile uint32_t lastflowratetimer = 0;
// and use that to calculate a flow rate
volatile float flowrate;
// Interrupt is called once a millisecond, looks for any pulses from the sensor!
SIGNAL(TIMER0_COMPA_vect) {
uint8_t x = digitalRead(FLOWSENSORPIN);
if (x == lastflowpinstate) {
lastflowratetimer++;
return; // nothing changed!
}
if (x == HIGH) {
//low to high transition!
pulses++;
}
lastflowpinstate = x;
flowrate = 1000.0;
flowrate /= lastflowratetimer; // in hertz
lastflowratetimer = 0;
}
void useInterrupt(boolean v) {
if (v) {
// Timer0 is already used for millis() - we'll just interrupt somewhere
// in the middle and call the "Compare A" function above
OCR0A = 0xAF;
TIMSK0 |= _BV(OCIE0A);
} else {
// do not call the interrupt function COMPA anymore
TIMSK0 &= ~_BV(OCIE0A);
}
}
void setup() {
lcd.begin(20, 4);
pinMode(6,INPUT_PULLUP);
pinMode(10, OUTPUT);
// Serial.begin(9600);
pinMode(FLOWSENSORPIN, INPUT);
digitalWrite(FLOWSENSORPIN, HIGH);
lastflowpinstate = digitalRead(FLOWSENSORPIN);
useInterrupt(true);
}
void loop()
{
lcd.setCursor(0, 0);
lcd.print("Start");
// Serial.print("Start");
button = digitalRead(6); // SET button
if (button == LOW) // pritisk set buttona
{
int e = 0;
while(button == LOW)
{
e++;
delay(50);
button = digitalRead(6);
}
if(e > 25)
{
VolumeSetting = 0;
digitalWrite(10, HIGH);
lcd.clear(); // ciscenje zaslona
for (int i = 0; i < 200; i++) //zanka za meni
{
lcd.setCursor(0, 1);
lcd.print("Volumen: ");
// Serial.print("Volumen:");
// Serial.println(VolumeSetting);
lcd.print(VolumeSetting);
button = digitalRead(6);
if(button == LOW)
{
delay(100);
VolumeSetting = VolumeSetting + 1;
button = 0;
}
if(VolumeSetting == 500)
{
VolumeSetting = 0;
}
delay(120);
Mainvolume = VolumeSetting;
pulses = 0;
}
}
delay(120);
}
lcd.clear();
lcd.setCursor(0, 0);
lcd.print("Set quantity: ");
lcd.print(Mainvolume);
lcd.setCursor(0, 1);
lcd.print("Current quantity: ");
lcd.print(Mainvolume);
float liters = 0;
while (liters < Mainvolume and Mainvolume != 0)
{
liters = pulses;
liters /= 7.5;
liters /= 30.0;
if(stateofpump == 0 && liters > 0.50)
{
stateofpump = PumpON;
// Serial.println(" Crpalka ON");
digitalWrite(ledPin, HIGH);
}
// Serial.print(liters);
// Serial.println(" Liters");
lcd.setCursor(0, 1);
lcd.print(liters);
lcd.setCursor(1, 1);
lcd.print(" Liters.");
if (liters > Mainvolume)
{
if (stateofpump == 1 || stateofpump == 1 && liters < 0.50)
{
stateofpump = PumpOFF;
Mainvolume = 0;
// Serial.println(" Crpalka OFF");
digitalWrite(ledPin, LOW);
}
}
}
}
Moderator edit: code tags


