Hello to everyone.
i am using the following code .
#include <SoftwareSerial.h>
int sensorPin = A0; // select the input pin for the sensor
int sensorValue = A0; // variable to store the value coming from the sensor
int sensor1Pin = A1; // select the input pin for the sensor
int sensor1Value = A1; // variable to store the value coming from the sensor
int sensor2Pin = A2; // select the input pin for sensor
int sensor2Value = A2; // variable to store the value coming from the sensor
void setup()
{
Serial.begin(9600);
}
void loop()
{
int sensorValue = analogRead(A0);
Serial.println(sensorValue);
if (sensorValue <= 280)
{
dInfo();
}
delay(30000);
int sensor1Value = analogRead(A1); // read the value from the sensor2
Serial.println(sensor1Value);
if (sensor1Value <= 600)
{
dInfo();
}
}
void dInfo()
{
-------
-----
-----
}
My problem is the following: the data that comes from the A0 SENSOR when it is less than the value 280 cooperates with the void dInfo () as i expect . It is working fine !
But the data from A1, sensor when it is less than the value 280 or any other value that i had experiment DOSENT cooperate with the void dInfo () even if i see the data from this sensor A1 at the serial monitor. How i can make A1 sensor cooperate with the void dInfo () ?also ?
I must say thta the senors must occuring one after the other and not at the same time .
I have been stuck few days now.
I will appreciate any help.!
What is dInfo()? You have a bunch of lines there. How would anyone know what will solve your problem. First problem, delete the lines and put the code back in.
I am confused.
That script does not compile for me. Does it compile for you?
You appear to have syntax problems inside the dInfo() function.
void dInfo()
{
-------
-----
-----
}
That's not the real code. It won't compile.
Why include SoftwareSerial.h when you never use it? Also it makes no sense to have global variables of sensorValue, sensor1Value etc initialised to the pin numbers A0, A1 etc rather than a real value. Then you create different variables in loop() but with exactly the same names (that's what the 'int' on the front does). It's very confusing but it shouldn't stop your dInfo() function being called.
So I guess there's something different in the actual code that's causing a problem.
Steve
let me correct it .
#include <SoftwareSerial.h>
int sensorPin = A0; // select the input pin for the sensor
int sensorValue = A0; // variable to store the value coming from the sensor
int sensor1Pin = A1; // select the input pin for the sensor
int sensor1Value = A1; // variable to store the value coming from the sensor
int sensor2Pin = A2; // select the input pin for sensor
int sensor2Value = A2; // variable to store the value coming from the sensor
SoftwareSerial SIM900(7, 8);
void setup()
{
Serial.begin(9600);
Serial.begin(19200);
}
void loop()
{
int sensorValue = analogRead(A0);
Serial.println(sensorValue);
if (sensorValue <= 280)
{
dInfo();
}
delay(30000);
int sensor1Value = analogRead(A1); // read the value from the sensor2
Serial.println(sensor1Value);
if (sensor1Value <= 600)
{
dInfo();
}
}
void dInfo(){
// AT command to set SIM900 to SMS mode
SIM900.print("AT+CMGF=1\r");
delay(100);
// REPLACE THE X's WITH THE RECIPIENT'S MOBILE NUMBER
// USE INTERNATIONAL FORMAT CODE FOR MOBILE NUMBERS
SIM900.println("AT + CMGS = \"+XXXXXXXXXXXX\"");
delay(100);
// REPLACE WITH YOUR OWN SMS MESSAGE CONTENT
SIM900.println("Message example from Arduino Uno.");
delay(100);
// End AT command with a ^Z, ASCII code 26
SIM900.println((char)26);
delay(100);
SIM900.println();
// Give module time to send SMS
delay(5000);
}
I am going to make a wild guess here.
Did you really mean to wait 30 Seconds between the A0 and A1 reads?
You have delay(30000); between the two reads.
no i am just experiment .
It is clear you are new at programming the arduino. I took your code and removed everything that was not used and changed it to be less confusing. It doesn't change anything functionally and I see no reason for it not to work. I hope studying the changes helps you to learn a little.
If this still doesn't work, we need a better explanation of what is not working correctly.
#include <SoftwareSerial.h>
#define sensor0Pin A0 // sensor 0 is connected to A0 (use #define instead of int)
int sensor0Value; // variable for sensor 0 (compiler sets this to 0 initially)
#define sensor1Pin A1 // sensor 1 is connected to A1
int sensor1Value; // variable for sensor 1 (compiler sets this to 0 initially)
SoftwareSerial SIM900(7, 8); // SIM900 is connected to pins 7, and 8
void setup()
{
Serial.begin(19200); // start Serial communications at 19200 baud
}
void loop()
{
sensor0Value = analogRead(sensor0Pin); // read sensor 0 value
Serial.println(sensor0Value); // Send it to the serial monitor
if (sensor0Value <= 280)
{
dInfo();
}
delay(30000); // wait 30 seconds
sensor1Value = analogRead(sensor1Pin); // read sensor 1 value
Serial.println(sensor1Value); // Send it to the serial monitor
if (sensor1Value <= 600)
{
dInfo();
}
}
void dInfo()
{
// AT command to set SIM900 to SMS mode
SIM900.print("AT+CMGF=1\r");
delay(100);
// REPLACE THE X's WITH THE RECIPIENT'S MOBILE NUMBER
// USE INTERNATIONAL FORMAT CODE FOR MOBILE NUMBERS
SIM900.println("AT + CMGS = \"+XXXXXXXXXXXX\"");
delay(100);
// REPLACE WITH YOUR OWN SMS MESSAGE CONTENT
SIM900.println("Message example from Arduino Uno.");
delay(100);
// End AT command with a ^Z, ASCII code 26
SIM900.println((char)26);
delay(100);
SIM900.println();
// Give module time to send SMS
delay(5000);
}
Why include SoftwareSerial.h when you never use it?
SoftwareSerial SIM900(7, 8); // SIM900 is connected to pins 7, and 8
None of the codes from dataoikogarden or PickyBiker posted in this thread have
SIM900.begin(9600);
I find it hard to believe that dInfo() would send a message without the .begin() for the software serial instance whatever the sensor value.