i have a problem with my code, i basically move a motor with the help of 3 relays, when a sensor does not detect the presence of an object part of a call, everything works perfectly, if it was after having called the function CHIAMATA() the arduino loop() stop unexplains, i certainly made a mistake, but i do not understand which.
thanks for your help this is the code....
#include <swRTC.h>
#include <SoftwareSerial.h>
#include <String.h>
swRTC rtc; //create a new istance of the lib
SoftwareSerial mySerial(3, 2);
const int buttonPin = 19;
const int sensorPin = 9;
const int allarmPin = 13;
int buttonState = 0;
int sensorState = 0;
int relay1 = 8;
int relay2 = 7;
int relay3 = 6;
int var = 0;
// initialize the stepper library on pins 8 through 11:
void setup() {
rtc.stopRTC(); //stop the RTC
rtc.setTime(12,0,0); //set the time here
rtc.setDate(4,6,2012); //set the date here
rtc.startRTC(); //start the RTC
Serial.begin(19200); //choose the serial speed here
mySerial.begin(19200);
pinMode(allarmPin, OUTPUT);
}
void loop() {
while(mySerial.available()!=0);{}delay(10);
Serial.print(rtc.getHours(), DEC);
Serial.print(":");
Serial.print(rtc.getMinutes(), DEC);
Serial.print(":");
Serial.print(rtc.getSeconds(), DEC);
Serial.println(" ");
//stato riserva croccantini
sensorState = digitalRead(sensorPin);
if (sensorState == HIGH) {
// turn LED on:
digitalWrite(allarmPin, HIGH);
Serial.println("Croccantini esauriti");
Serial.println("Spia allarme ACCESA");
Serial.println("Tramoggia DISABILITATA");
Serial.println("Imposto la chiamata");
while(sensorState == HIGH) {CHIAMATA(); break;}
} else {
// turn LED off:
digitalWrite(allarmPin, LOW);
Serial.println("Croccantini OK");
}
if (sensorState == LOW && rtc.getHours()== 12 && rtc.getMinutes()== 00 && rtc.getSeconds()== 5) {startmotor();}
//start manuale carico/scarico
// read the state of the pushbutton value:
buttonState = digitalRead(buttonPin);
// check if the pushbutton is pressed.
// if it is, the buttonState is HIGH:
if (buttonState == 1) {
Serial.print("Pulsante alimentazione manuale ATTIVO");
// turn on:
// singlestartmotor();
}
}
void startmotor(){
//numero di cicli di carico da eseguire (5)
while(var < 5){
pinMode(relay1, OUTPUT);
pinMode(relay2, OUTPUT);
pinMode(relay3, OUTPUT);
digitalWrite(relay3, LOW); //ABILITA TUTTO
//AVANTI
digitalWrite(relay1, LOW);
digitalWrite(relay2, LOW);
Serial.print("AVANTI");
delay(1000); // wait 2 seconds
digitalWrite(relay3, HIGH);//STOP TUTTO
digitalWrite(relay1, HIGH);
digitalWrite(relay2, HIGH);
delay(1000); //ATTESA PER INVERSIONE MARCIA
//INDIETRO
digitalWrite(relay3, LOW);//ABILITA TUTTO
digitalWrite(relay1, HIGH);
digitalWrite(relay2, HIGH);
Serial.print("INDIETRO");
delay(1000); // wait 2 seconds
digitalWrite(relay3, HIGH);//STOP TUTTO
delay(5000); // wait 2 seconds
var++;
}}
void CHIAMATA() {
mySerial.println("ATD329xxxxx135;");//dial the number, xxxx ix the phone number.
delay(100);
Serial.print("Chiamata in corso..."); return loop();}
return loop();doesn't do what you think it does...