So i have built my first bigger arduino project, and basically an a arduino uno that controls a bunch of relays ( ebay relay modules ), and a lcd 16/2 screen. And reads a few sensors, sutch as weight, ir ( module ), and a set of buttons and switches.., everything powerd by a external computer psu 12v, and 5v..,
anyway,. after a load of debugging and testing and problem solving i have got most of the functions working.., but when it counts the most it sort of crasher..,
the program is 2 main parts 1, is calibraition, and 2 is running..,
and once i have calibratet and start to run the machine it does begin , and then when it has reached the calibrated value , then everything goes sideways.., i beleve it crashes then resets, and somewhere inbetween the lcd starts to show random letters..,
and then i have to reset to restart at all..
i did a pullup on the resetpin to 5v througn 10k ohm..,
( the board runs on 12v pin-in)
the code :
const int weight = A0; // pin that the sensor is attached to
const int bottleSwitch = 9; // pin that the Bottle Switch is attached to
const int motor = 8; // pin that the motor is attached to
const int valve = 7; // pin that the valve is attached to
const int mode = 6; // pin that the system mode switch is attached to
const int motorMan = 10; // pin that the manual motor switch is attached to
const int manVal = 1; // pin that the manual valve switch is attached to
const int setVol = A5; // pin that the set volume is attached to
int vol = 0;
int goalVol = 500;
#include <LiquidCrystal.h>
LiquidCrystal lcd(12, 11, 5, 4, 3, 2);
void setup() {
pinMode(weight, INPUT);
pinMode(bottleSwitch, INPUT);
pinMode(mode, INPUT);
pinMode(motorMan, INPUT);
pinMode(manVal, INPUT);
pinMode(setVol, INPUT);
pinMode(motor, OUTPUT);
pinMode(valve, OUTPUT);
lcd.begin(16, 2);
lcd.print("Marek");
lcd.setCursor(0, 1);
lcd.print("oil ver:1,4");
delay(3000);
lcd.clear();
}
void loop() {
if(digitalRead(mode) == HIGH){
delay(10);
digitalWrite(valve, HIGH);
delay(10);
vol = analogRead(weight);
lcd.clear();
lcd.setCursor(0, 0);
lcd.print("Volume: ");
lcd.print(vol);
delay(50);
if (vol > (goalVol-20)) {
digitalWrite(valve, LOW);
lcd.setCursor(0, 0);
lcd.print("pause");
delay(100);
}
digitalWrite(valve, HIGH);
if (vol > goalVol) {
digitalWrite(valve, LOW);
lcd.setCursor(0, 0);
lcd.print("pause");
delay(100);
digitalWrite(motor, HIGH);
delay (10);
lcd.clear();
lcd.setCursor(0, 1);
lcd.print("next..");
if(digitalRead(bottleSwitch) == HIGH){
digitalWrite(motor, LOW);
lcd.clear();
lcd.print("stop");
}
}
}else{
lcd.clear();
vol = analogRead(weight);
lcd.setCursor(0,0);
lcd.print("current volume : ");
lcd.setCursor(0,1);
lcd.print( vol );
lcd.print(" units");
delay(30);
while(digitalRead(motorMan) == HIGH){
digitalWrite(motor, HIGH);
lcd.clear();
lcd.setCursor(0,0);
lcd.print("rotate...");
lcd.print(digitalRead(motorMan));
delay(10);
}
digitalWrite(motor, LOW);
while(digitalRead(manVal) == HIGH){
digitalWrite(valve, HIGH);
lcd.clear();
lcd.setCursor(0,0);
lcd.print("fill...");
delay(10);
}
digitalWrite(valve, LOW);
while(digitalRead(setVol) == HIGH){
vol = analogRead(weight);
goalVol=vol;
lcd.clear();
lcd.setCursor(0,0);
lcd.print("volume set");
lcd.setCursor(0,1);
lcd.print(vol);
delay(1000);
}
}
}