GSM Shield, PubSub and MicroServo

Hi all,

I working on a project that will use PubSub client (MQTT) and GSM Shield to control Micro Servo. Now, I have code in place that will connect to GPRS via GSM Shield and I have PubSub client in place and these to things work perfectly. Connecting to GSM and MQTT is inside setup() function, so first I connect to GSM, then I connect to GPRS and after those connections are done, I'm connecting to MQTT. Now, after these connections in setup() function, I'm attaching Servo to pin 5 or 6 with myservo.attach(6). In loop, I'm publishing on every second some message, but every time when message is published, my Servo i moved. Basically, its like every time GSM shield send singnal to MQTT it also write something on pin 5 or 6 which is moving my Servo for some small value.

I'm using arduino uno, GSM Shield ( and TinkerKit MicroServo. I'm also having a 9V power supply. Can anyone help me or just explain what is going on here, because I'm trying to figure out what is happening for 2 days now?


Could be something due power? Maybe GSM needs more power or something like that?

Perhaps the GSM interface is doing something involving interrupts, which is affecting the timing of interrupts used to implement the Servo signal timing.

If this is a big deal for you, it would be possible to get a dedicated Servo controller to deal with the signal timing for you instead of having the Arduino generate it directly.

I tried with motor shield attached as well, and I added servo on motor shield. but it has same effect. So, when I have GSM shield connected to the internet, when GSM shield interact with web or when signal is sent, it seems like servo is pinged somehow. I tried with every available pin.

It might conceivably be an electrical noise issue. A capacitor across the power supply at the servo would eliminate that.

Seems more likely to me that it’s an interrupt contention i.e. the interrupt handler that generates the Servo signal is being delayed because some other interrupt handler associated with your GSM shield is already running.

There have also been some historical bugs in the Arduino runtime which caused incorrect behaviour when output ports were used by interrupt context code and main context code concurrently (e.g. I don’t know whether they’re all fixed.

Thanks Peter,

It definitely have something to do with interrupts. Because, each time GSM shield send some data, servo is moving. Will try to dig into this a little bit more, but if someone else had a same issue, please let me know.

I had the same issue when trying to connect a GPS receiver to the GSM Shield and the solution was to use a library called AltSoftSerial. The library was updated recently and seems to be working without issue. I was able to get up and running by following this example-