Hi all ! I have this fuction in my loop "duration=pulseIn(pin,HIGH);" which needs time… and my proble is the receive SMS cant get it, because of the fuction. What can i do ?
i have arduino UNO and GSM SIM900 S2-1040S-Z0955
Hi all ! I have this fuction in my loop "duration=pulseIn(pin,HIGH);" which needs time… and my proble is the receive SMS cant get it, because of the fuction. What can i do ?
i have arduino UNO and GSM SIM900 S2-1040S-Z0955
You could timestamp one edge of your pulse, and timestamp the other edge.
The difference would give you the pulse duration
That's the problem the fuction need time ...
How can we reduce the number of pulses to gain time ? can i do something to fuction ?
orestis32:
That's the problem the fuction need time ...
I have no idea what that means.
Why don't your set out your problem, with numbers and specifications?
unsigned long duration;
voide setup
{}
void loop()
{
receiveSMS();
duration=pulseIn(pin,HIGH);
wind=96000/duration+1;
}
}
void receiveSMS()
{
if(SIM900.available() >0)
{
inchar=SIM900.read();
if (inchar=='#')
{
delay(10);
inchar=SIM900.read();
if (inchar=='i')
{
delay(10);
inchar=SIM900.read();
if (inchar=='n')
{
delay(10);
inchar=SIM900.read();
if (inchar=='f')
{
delay(10);
inchar=SIM900.read();
if (inchar=='o')
delay(10);
}
Serial.println("receiveSMS has been read");
SIM900.println("AT+CMGD=1,4");
sendSMS();
}
}
}
}
}
void send sms();
{}
This is a part. I dont have problame to send SMS only to receive it
thank you for the help ! and sorry for my english! is BAD !
voide setup
{}
Like, that's going to compile.
I dont want to show all the code and i dont think is necessary
check the commend ![]()
unsigned long duration;
int pin=4;
voide setup
{
pinMode(pin,INPUT);
}
void loop()
{
receiveSMS(); //
duration=pulseIn(pin,HIGH); // i think : when i send SMS from my phone and loop running this row lose the SMS becauase need time to find the value
wind=96000/duration+1;
}
}
void receiveSMS()
{
if(SIM900.available() >0)
{
inchar=SIM900.read();
if (inchar=='#')
{
delay(10);
inchar=SIM900.read();
if (inchar=='i')
{
delay(10);
inchar=SIM900.read();
if (inchar=='n')
{
delay(10);
inchar=SIM900.read();
if (inchar=='f')
{
delay(10);
inchar=SIM900.read();
if (inchar=='o')
delay(10);
}
Serial.println("receiveSMS has been read");
SIM900.println("AT+CMGD=1,4");
sendSMS();
}
}
}
}
}
void send sms();
{}
I dont want to show all the code and i dont think is necessary
OK.
Good luck - hope it goes well.
I dont want to show all the code and i dont think is necessary
So you don't know how to solve a problem but you know the information needed for others to solve it for you.
Also you ignore a soloution to your problem that has been given to you.
Not sure there is much point, do you?
?aybe you're right! but do not know if you understood my problem, (my english is one of the problems for sure) I can not post it because it is work for my school that's all.
Thanks for the try !
I can not post it because it is work for my school that's all.
I don't see how that stops you.
Your problem is that you are using the pulse in function. This type of function is a blocking function, just like the delay function. It is stopping you from receiving the message.
So what you do is to detect the edge of the pulse, that is when it changes from low to high and make a note of the time that occurred.
That is not a blocking function and you can receive your message if one comes in.
Then when you see the reverse transition, that is from a high to low, you make a note of the time. The pulse width is the time between the two transitions.
Note if you do receive a message between transitions then the timing will be invalid, so you need a bit of logic to ignore that.
Grumpy_Mike:
I can not post it because it is work for my school that's all.
I don't see how that stops you.
Your problem is that you are using the pulse in function. This type of function is a blocking function, just like the delay function. It is stopping you from receiving the message.
So what you do is to detect the edge of the pulse, that is when it changes from low to high and make a note of the time that occurred.
That is not a blocking function and you can receive your message if one comes in.
Then when you see the reverse transition, that is from a high to low, you make a note of the time. The pulse width is the time between the two transitions.Note if you do receive a message between transitions then the timing will be invalid, so you need a bit of logic to ignore that.
how can I do what you say ? i am using TCST2103 as anemometer, can you show me is something easy some tutorial ?
how can I do what you say ?
well there are some examples built into the IDE.
File -> Examples -> 02 Digital -> StateChangeDetection
will show you how to detect the rising and falling edges of pulses.
File -> Examples -> 02 Digital -> BlinkWithoutDelay
will show you how to use the millis timer. In your case you want to record the values given at the state change rather than using the timer to detect when to do something.
well there are some examples built into the IDE.
File -> Examples -> 02 Digital -> StateChangeDetection
will show you how to detect the rising and falling edges of pulses.File -> Examples -> 02 Digital -> BlinkWithoutDelay
will show you how to use the millis timer. In your case you want to record the values given at the state change rather than using the timer to detect when to do something.
I think I understand how it works, but do not understand how can make it work
const int buttonPin = 6; // the pin that the pushbutton is attached to
const int ledPin = 13; // the pin that the LED is attached to
int buttonPushCounter = 0; // counter for the number of button presses
int lastButtonState = 0; // previous state of the button
long previousMillis = 0;
int buttonState=0;
long interval = 1000;
void setup() {
pinMode(buttonPin, INPUT);
pinMode(ledPin, OUTPUT);
Serial.begin(9600);
}
void loop() {
unsigned long currentMillis = millis();
if(currentMillis - previousMillis > interval) {
previousMillis = currentMillis;
buttonPushCounter=0;
}
buttonState = digitalRead(buttonPin);
if (buttonState != lastButtonState) {
if (buttonState == HIGH) {
buttonPushCounter++;
Serial.print("number of button pushes: ");
Serial.println(buttonPushCounter);
}
else {}
}
lastButtonState = buttonPin;
}
i make this "shit" it doesnt work exactly, if the black lane of the disk stop on the LED doesnt stop the counting and something last the biggest value is 29 /sec this mean delay ?
I think I understand how it works, but do not understand how can make it work
You haven't got the idea yet.
Reas reply #11 again.
Yes you are detecting a state cha be but you are not using millis to make a note of the time when each transition occours. That fist part of the loop containing millis is not doing anything for you.
if the black lane of the disk stop on the LED doesnt stop the counting and something last the biggest value is 29 /sec this mean delay ?
First you mentioned of this. That will make the "what to do with this pulse number" part of the code a bit more complex but not much. Just decide on a value that if it exceeds you consider it stopped.