Hello!
The project im working on is a bar in a VW T3 Van.
With an Android App - or a rotary phone encoder you can select your drink and in the Van there are 7 metal-bottles with
solenoid valves, that are connected to relays with are controlled by a arduino duemilanove.
The project is already working - the problem is the arduino gets resetted everytime when there are 2 relays to switch.
There is also a second relay modul connected for other things.
I already tried to use different power sources - to make sure that there is enough power for the relays/ the arduino.
Here i s the code i used:
And the relay modules i used:
If you have any ideas for solving my problem, please let me know!
Thank you very much in advance -
greetings
markus
/*
Mobile Bar Steuerung LEIDER GEIL vers 1.0
*/
/*-----( Import needed libraries )-----*/
#include <Wire.h>
#include <LiquidCrystal_I2C.h>
#include "MeetAndroid.h"
// Zeugs für TelefonCotnroller
int needToPrint = 0;
int tel_count;
// wählscheibe angeschlossen an pin 1 und an masse
int tel_in = 7;
int lastState = LOW;
int trueState = LOW;
long lastStateChangeTime = 0;
int tel_cleared = 0;
// constants
int drinks_gesamt;
int dialHasFinishedRotatingAfterMs = 100;
int debounceDelay = 15;
// Zeugs für Telefon Controller
/*-----( Declare objects )-----*/
MeetAndroid meetAndroid;
LiquidCrystal_I2C lcd(0x27,20,4); // set the LCD address to 0x27
/*-----( Getränke aufrufen )-----*/
void weiss_wein(){
digitalWrite(8, LOW);
delay(3900);
digitalWrite(8, HIGH);
lcd.clear();
lcd.print(" *** Mobile Bar *** Weisswein");
//pause einlegen
delay(500);
//drinks_gesamt++;
//klingel ansteuern
digitalWrite(3, LOW);
delay(30);
digitalWrite(3, HIGH);
//pause einlegen
delay(500);
}
void captain_cola(){
/*
//cola einschenken
digitalWrite(6, LOW);
delay(1000);
digitalWrite(6, HIGH);
//captain einschenken
digitalWrite(10, LOW);
delay(300);
digitalWrite(10, HIGH);
*/
lcd.clear();
lcd.print(" *** Mobile Bar *** Captain Cola");
//drinks_gesamt++;
//klingel ansteuern
digitalWrite(3, LOW);
delay(30);
digitalWrite(3, HIGH);
}
//...
/*-----( restl Verbraucher aufrufen )-----*/
byte red_bull_state = HIGH; // Red Bull Sign deklarieren - am start: aus
void red_bull_sign(){
//toggle our switch (if off make it on and vice-versa)
if (red_bull_state == LOW){
red_bull_state = HIGH;
} else {
red_bull_state = LOW;
}
//PIN 4 - red bull sign bekommt wert von red_bull_sign zugewiesen
digitalWrite(6, red_bull_state);
lcd.clear();
lcd.print(" *** Mobile Bar *** Red Bull Sign");
}
void bim_klingel(){
//klingeln telefon
digitalWrite(3, LOW);
delay(300);
digitalWrite(3, HIGH);
delay(150);
digitalWrite(3, LOW);
delay(300);
digitalWrite(3, HIGH);
lcd.clear();
lcd.print(" *** Mobile Bar *** ring ring ");
}
/*-----( Relay aufrufen Ende )-----*/
/*-----( MeetAndroid Funktion übergeben )-----*/
void android_weiss_wein(byte flag, byte numOfValues){
weiss_wein();
}
void android_captain_cola(byte flag, byte numOfValues){
captain_cola();
}
void android_red_bull_sign(byte flag, byte numOfValues){
red_bull_sign();
}
void android_bim_klingel(byte flag, byte numOfValues){
bim_klingel();
}
/*-----( MeetAndroid Funktion übergeben ENDE )-----*/
void setup() {
//Serial.begin(115200);
Serial.begin(57600);
Serial.print("drinks_gesamt = ");
Serial.print(drinks_gesamt);
//Zeugs für Telefon Controller
//pinMode(2, INPUT);
pinMode(tel_in, INPUT);
// register callback functions, which will be called when an associated event occurs.
meetAndroid.registerFunction(android_weiss_wein, 'f');
meetAndroid.registerFunction(android_bim_klingel, 'b');
meetAndroid.registerFunction(android_red_bull_sign, 'l');
meetAndroid.registerFunction(android_red_bull_sign, 'r');
/*-----( ports definieren )-----*/
// ausgänge definieren
pinMode(3, OUTPUT);
pinMode(4, OUTPUT);
pinMode(5, OUTPUT);
pinMode(6, OUTPUT);
//telefon pin auf input ??
pinMode(7, INPUT);
pinMode(8, OUTPUT);
pinMode(9, OUTPUT);
pinMode(10, OUTPUT);
pinMode(11, OUTPUT);
pinMode(12, OUTPUT);
pinMode(13, OUTPUT);
digitalWrite(3, HIGH);
digitalWrite(4, HIGH);
digitalWrite(5, HIGH);
digitalWrite(6, HIGH);
digitalWrite(7, HIGH);
digitalWrite(8, HIGH);
digitalWrite(9, HIGH);
digitalWrite(10, HIGH);
digitalWrite(11, HIGH);
digitalWrite(12, HIGH);
digitalWrite(13, HIGH);
/*-----( LCD initalisieren )-----*/
lcd.init(); // initialize the lcd
lcd.backlight();
// Print a message to the LCD.
//lcd.setCursor(0, 1);
lcd.clear();
lcd.print(" *** Mobile Bar *** leider geil!");
}
void loop() {
/*-----( Telefoncontroller auslesen )-----*/
int reading = digitalRead(tel_in);
if ((millis() - lastStateChangeTime) > dialHasFinishedRotatingAfterMs) {
// the dial isn't being dialed, or has just finished being dialed.
if (needToPrint) {
// if it's only just finished being dialed, we need to send the number down the serial
// line and reset the count. We mod the count by 10 because '0' will send 10 pulses.
//Serial.print(tel_count % 10, DEC);
// auswertung tel_count
if (tel_count == 1){
lcd.clear();
lcd.print(" *** Mobile Bar *** tel_1");
captain_cola();
}
else if (tel_count == 2){
lcd.clear();
lcd.print(" *** Mobile Bar *** tel_2");
havanna_cola();
}
else if (tel_count == 3){
lcd.clear();
lcd.print(" *** Mobile Bar *** tel_3");
wodka_weiss_bull();
}
else if (tel_count == 4){
lcd.clear();
lcd.print(" *** Mobile Bar *** tel_4");
wodka_rot_bull();
}
else if (tel_count == 5){
lcd.clear();
lcd.print(" *** Mobile Bar *** tel_5");
weiss_wein();
}
else if (tel_count == 6){
lcd.clear();
lcd.print(" *** Mobile Bar *** tel_6");
cola();
}
else if (tel_count == 7){
lcd.clear();
lcd.print(" *** Mobile Bar *** tel_7");
red_bull();
}
else if (tel_count == 8){
lcd.clear();
lcd.print(" *** Mobile Bar *** tel_8");
wodka_weiss();
}
else if (tel_count == 9){
lcd.clear();
lcd.print(" *** Mobile Bar *** tel_9");
bim_klingel();
}
else if (tel_count == 10){
lcd.clear();
lcd.print(" *** Mobile Bar *** tel_10");
red_bull_sign();
}
needToPrint = 0;
tel_count = 0;
tel_cleared = 0;
}
}
if (reading != lastState) {
lastStateChangeTime = millis();
}
if ((millis() - lastStateChangeTime) > debounceDelay) {
// debounce - this happens once it's stablized
if (reading != trueState) {
// this means that the switch has either just gone from closed->open or vice versa.
trueState = reading;
if (trueState == HIGH) {
// increment the count of pulses if it's gone high.
tel_count++;
needToPrint = 1; // we'll need to print this number (once the dial has finished rotating)
}
}
}
lastState = reading;
/*-----( Telefoncontroller ENDE )-----*/
meetAndroid.receive(); // you need to keep this in your loop() to receive events
/*-----( Alle Ventile sicherheitshalber zumachen )-----*/
/*
digitalWrite(3, HIGH);
//digitalWrite(4, HIGH); //red bull sign behält status
digitalWrite(5, HIGH);
digitalWrite(6, HIGH);
digitalWrite(7, HIGH);
digitalWrite(8, HIGH);
digitalWrite(9, HIGH);
digitalWrite(10, HIGH);
digitalWrite(11, HIGH);
digitalWrite(12, HIGH);
digitalWrite(13, HIGH);
*/
}