Bonjour Artouste
Merci pour ton aide
Le problème est bien là, il réagi à un stimuli, mais je n’arrive pas à récupérer le code pour le faire agir en fonction du code
Pour moi, le code ne doit pas être très long, un ou deux chiffres ou lettres
Voici le code , merci d’être indulgent par rapport à la qualité de la programmation car je n’en suis qu’à mes débuts
Il y à certainement des lignes qui ne servent à rien , et des choses qui manque, mais à force d’essayer différentes choses, c’est un peu le bazar
//Ce programme consiste en une automatisation d'un système de pompage en site isolé alimenté par un panneau solaire
//réalisation: version 09 avril 2012
#include <SoftwareSerial.h>
#define maxLength 200
#include "Wire.h"
unsigned long start1 ,fin1 ,start2,start3 ,fin2 ,fin3,tempo1 ,tempoS1, tempo2 ,tempoS2 ,compt,tempo3 ,tempoS3;
long previousMillis = 0;
int analogPin10 = 10;//Flotteur 1
int analogPin11 = 11;//Flotteur 2
int analogPin12 = 12;// boucle anti-vol
const int ledPin = 13;// sirene
boolean ArretSMS = 0;
String inString = String(maxLength);
const int relais1 = 8;
const int relais2 = 9;
////////////////
//partie gestion SMS
//////////////////
//SoftwareSerial phone(0,1); // phone connected to pins 2,3
int onModulePin = 2; // the pin to switch on the module (without press on button)
int CompteurSMS = 1; // Numbers of SMS to send
int count1 = 0;
int count2 = 0;
int count3 = 0;
int count4 = 0;
int count5 = 0;
int count6 = 0;
String input; // phones response is saved into this string
int state = 0; // current state of the LED
char phone_number[]="**********"; // ********* Numero à réaliser pour envoi SMS
void switchModule()
{
digitalWrite(onModulePin,HIGH);
digitalWrite(13,HIGH); // ledR
delay(5000);
digitalWrite(onModulePin,LOW);
digitalWrite(13,LOW); // ledR
}
void connectmodule()
{
Serial.println("Arduino connected.");
delay(100);
Serial.println("AT+CMGF=1"); // sets the SMS mode to text
delay(100);
//phone connection
Serial.begin(9600);
Serial.println("modem.");
delay(500);
// phone init
Serial.println("Start of phone init...");
Serial.println("AT+CPMS=\"ME\",\"ME\",\"ME\""); // phone memory used for SMS storage
delay(2000);
Serial.println("AT+CNMI=2,1,2,1,1"); // forward all received stuff into terminal window
delay(2000);
Serial.flush();
Serial.println("End of init. Waiting for command SMS...\n");
}
void getSerialChars()
{
while (Serial.available() > 0)
{
char inChar = Serial.read();
}
}
///////////////////////////////////////////////
//////////////////////////////////////////////////
void setup()
{
Serial.begin(9600);
pinMode(8,OUTPUT); // relais1
pinMode(9,OUTPUT); // relais2
pinMode(10,INPUT);// flotteur 1
pinMode(11,INPUT); // flotteur 2
pinMode(12,INPUT); // Boucle anti-vol
pinMode(ledPin, OUTPUT);
pinMode(onModulePin, OUTPUT);
switchModule();// switches the module ON
connectmodule();
}
////////////////////////////////
///////////////////////////////
void displayResult1()//affichage de la tempo du flotteur 1 en secondes
{
tempo1=fin1-start1;
tempoS1=tempo1/1000;
}
void displayResult2()//affichage de la tempo flotteur 2 en secondes
{
tempo2=fin2-start2;
tempoS2=tempo2/1000;
}
void displayResult3()//affichage de la tempo flotteur 2 en secondes
{
//tempo3=fin3-start3;
tempoS3=start3/1000;
//tempoS3=tempo3/1000;
}
void loop()
{
delay(1000); // temps d'attente
int relais1= digitalRead(8);
int relais2= digitalRead(9);
int FLOTTEUR1 = digitalRead(10);
int FLOTTEUR2 = digitalRead(11);
int BoucleAV = digitalRead(12);
//Serial.print("\ttempoS1\t ");
//Serial.print(tempoS1);
//Serial.print("\ttempoS2\t ");
//Serial.print(tempoS2);
Serial.print("\ttempoS3\t ");
Serial.print(tempoS3);
//Serial.print("\tFLOTTEUR1:\t");
//Serial.print(FLOTTEUR1);
//Serial.print("\tFLOTTEUR2:\t");
//Serial.print(FLOTTEUR2);
//Serial.print("\tBoucleAV:\t");
//Serial.print(BoucleAV);
//Serial.print("\trelais1:\t");
//Serial.print(relais1);
//Serial.print("\trelais2:\t");
//Serial.print(relais2);
//Serial.print("\tcount1:\t");
//Serial.print(count1);
//Serial.print("\tcount2:\t");
//Serial.print(count2);
//Serial.print("\tcount3:\t");
//Serial.print(count3);
Serial.print("\tArretSMS:\t");
Serial.println(ArretSMS);
//Serial.print("\tcount4:\t");
//Serial.print(count4);
//Serial.print("\tcount5:\t");
//Serial.println(count5);
//////////////////////////
//partie réception SMS
/////////////////////////
if (Serial.available() > 0)
{
inString = "";
delay(500);
getSerialChars();
if (inString==("12")) // contenu message
{
digitalWrite(13,HIGH);
delay(1000);
ArretSMS=1; //désactivation des envoi de SMS
delay(1000);
digitalWrite(13,LOW);
delay(1000);
digitalWrite(13,HIGH);
delay(100);
digitalWrite(13,LOW);
delay(1000);
digitalWrite(13,HIGH);
}
}
///////////////////////////////
//gestion tempo flotteur 1
//////////////////////////////
if (digitalRead(10)==LOW)
{
start1=millis();
delay(200); // for debounce
}
if (digitalRead(10)==HIGH)
{
fin1=millis();
delay(200); // for debounce
displayResult1();
}
////////////////////////////
//fin gestion tempo1
////////////////////////////
///////////////////////////////
//gestion tempo flotteur 2
//////////////////////////////
if (digitalRead(11)==LOW)
{
start2=millis();
delay(200); // for debounce
}
if (digitalRead(11)==HIGH)
{
fin2=millis();
delay(200); // for debounce
displayResult2();
}
////////////////////////////
//fin gestion tempo2
////////////////////////////
///////////////////////////////
//gestion tempo sonnerie
//////////////////////////////
if (Serial.available() > 0)
{
start3=millis();
delay(200); // for debounce
}
if (Serial.available() ==0)
{
fin3=millis();
delay(200); // for debounce
displayResult3();
}
////////////////////////////
//fin gestion sonnerie
////////////////////////////
////////////////////////
//début gestion bacs 1
//////////////////////////
if (tempoS1 > 5&FLOTTEUR1==1)//temps d'attente de NH + flotteur 1 en niv bas
{
digitalWrite(8,HIGH); // relais pompe bac 1
delay(100); // for debounce
}
else
{
digitalWrite(8,LOW); // relais pompe bac 1
}
////////////////////////
//début gestion bacs 2
//////////////////////////
if (tempoS2 > 5&FLOTTEUR2==1)//temps d'attente de NH + flotteur 2 en niv bas
{
digitalWrite(9,HIGH); // relais pompe bac 2
delay(100); // for debounce
}
else
{
digitalWrite(9,LOW); // relais pompe bac 2
}
////////////////////////
//début gestion boucle anti-vol
//////////////////////////
if (BoucleAV==1)//boucle antivol = 1
{
digitalWrite(13,HIGH); // relais pompe bac 2
delay(100); // for debounce
}
else
{
digitalWrite(13,LOW); // relais pompe bac 2
}
/////////////////////////////
//envois SMS BAc 1
///////////////////////////
if (ArretSMS==0)
if (tempoS1 > 15& FLOTTEUR1==1 & count1<CompteurSMS)//temps d'attente avant envoi alarme de temps niveau bas trop long
{
delay(5000);
Serial.print("AT+CMGS=\"");// send the SMS number
Serial.print(phone_number);
Serial.println("\"");
delay(1500);
Serial.print("alarme niveau bas trop long sur bac 1"); // message à envoyer
delay(500);
Serial.write(0x1A); //sends ++
Serial.write(0x0D);
Serial.write(0x0A);
count1++;
ArretSMS=0;
delay(5000);
}
if (FLOTTEUR1==0)
count1=0;
/////////////////////////////
//envois SMS Arret SMS
///////////////////////////
if (ArretSMS==1 & count6<CompteurSMS)//envoi message pour signaler que la surveillance est à l'arrêt
{
delay(1000);
Serial.print("AT+CMGS=\""); // send the SMS number
Serial.print(phone_number);
Serial.println("\"");
delay(500);
Serial.print("surveillance pompage arretee"); //message à envoyer
delay(500);
Serial.write(0x1A); //sends ++
Serial.write(0x0D);
Serial.write(0x0A);
count6++;
}
}