GSM sending constant messages

Hi, I’m trying to program my arduino to send an SMS whenever my float switch is HIGH. I have successfully done this; however when the float switch goes HIGH, the GSM sends constant messages, even after I have released the float switch to LOW. I know I could probably use in if/else statement, but I’m not sure what to put in it. Any help or feedback is greatly appreciated. My code is attached, but I’ll be replacing my phone number with “x’s”.

power_up.ino (639 Bytes)

How do you know the switch is reading LOW? Unless you have a pulldown resistor on the switch, it might be floating HIGH. (Not the same floating as your float switch is doing :wink: but floating randomly electrically speaking.) Best way is to use the internal pullup resistors pinMode(S1, INPUT_PULLUP); and then reverse your logic. So look for it to go LOW. Use of pullups rather than pulldowns is SOP, and the internal ones make life muuuuuuch easier.

Put a Serial print in your loop to see what the actual value is.

You should also look at the StateChangeDetection example in the IDE, since as it is, once the switch is HIGH (or if you use pullups, LOW) it will continue to send since each time through loop() (even with the delay) it will see it HIGH still and has no way of knowing if this is a new HIGH or has been HIGH for a week. You need to save the reading from last time round, and see if it changed, the you know it's a new flood not an old one.

I added the serial print like you suggested and it was always reading on. When I use the internal pull-up resistor, do I need to change my circuit? In other words, right now I have one end of the float switch connected to power, and the other end connected to a 10k resistor going to ground. Thanks again for your help!

That's odd: if your 10k to ground is a pulldown resistor, then the switch should read low when unpressed. So perhaps check that wiring?- post a schematic for us to look at, maybe something's hinky there. Let's see where the Arduino pin is connected to.

Yep if you use the internal pullup you need to lose the external pulldown, but either way's cool, just more common to use pullup. But it should work your way if the pulldown's connected correctly.

Btw, it's also common not to talk about "reading on", since that's a bit subjective: high and low are more explicit.

Okay, I’m attaching the schematic. The only difference is that I am connected to D3 instead of D2. It is odd though. Whenever I remove the 10k resistor, and just use the internal pull-up resistor, my GSM shuts off as if it is being directly grounded.

With the pullup the switch needs to take the pin to ground.

Have you checked that the switch actually works?- that circuit should indeed take the pin low when the switch is open. Simulate the switch with a bit of wire from the digital pin to 5V and see what happens.