Problem in running servo motor using arduino uno and bolt iot

Hello,

I had this simple idea, to control the servo motor using Bolt app and arduino uno i.e., to rotate a certain way when we click the button in the app.
The cloud html code I have used is almost same as the LED monitoring system we have done using API.
The Bolt wifi module sends the output(high or low) to one of the arduino digital pins.
Accordingly servo motor is operated.

However I am a beginner and facing issues to figure out where I am wrong and how can I better the project I’m building as I am not able to get the output.

Kindly suggest

Here is the arduino code:

#include <Servo.h> 

int servoPin = 9;
int readfrom = 2;
int val = digitalRead(readfrom);
int state;
int laststate;
Servo servo;  
 
int angle = 0;   // servo position in degrees 
 
void setup() 
{ 
  servo.attach(servoPin); 
  pinMode(readfrom,INPUT);
  pinMode(servoPin,OUTPUT);
} 
 

void loop() 
{ 
    state=val;
    if(state!=laststate)
    {
      // scan from 0 to 180 degrees
      if(state==1)
      {
            for(angle = 0; angle < 180; angle++)  
            {                                  
              servo.write(angle);               
              delay(15);
            }
    
      }
    
      // now scan back from 180 to 0 degrees
      else
      {
            for(angle = 180; angle > 0; angle--)    
            {                                
              servo.write(angle);           
              delay(15);       
            }
          
      } 
   
    }
    laststate=state;
}

I will point out few things that should help you -

  1. To use servoWrite functions, you require Bolt Cloud Pro plan. Once subscribed, you can use servo motor over the internet using remote APIs - https://cloud.boltiot.com/remote/44b2de6b-7e68-40e7-a27f-814b58afe008/servoWrite?pin=1&value=90&deviceName=BOLT1257632
  2. To be able to use arduino using bolt, you have to use the bolt library on Arduino and code accordingly. Reference - https://docs.boltiot.com/docs/arduino-library
  3. For Arduino-boltiot commands go through the readme.md in https://github.com/Inventrom/boltiot-arduino-helper
1 Like

Thank you for your useful input.

I wanted to know if both Tx and Rx of both devices need to be connected mutually for UART communication or only Tx pin of Bolt module can be connected to the Rx pin of arduino. If my requirement is only to transmit data.

Also can we code in the Bolt cloud using html to pass 1 or 0 through the Tx port ?

For serial communication, this rule is UNIVERSAL.
Rx -> Tx and Tx-> Rx
Both are necessary to be connected.

Why do you want to pass 1 and 0 through Tx port? How will you manually interrupt the microcontroller where to send the data?

Idea: There will be two buttons in the bolt iot android app. When I press “rotate to 180” in my mobile, say 1 is transmitted to Bolt wifi module using API key.
The value 1 is accessed by any Arduino Rx pin, from Wifi module Tx pin and we use separate Arduino code to run servo motor using other pins.

So I need only one set of tx and rx connection, and I manually interrupt using the bolt Android app(using API key)

It can be done easily using Bolt cloud pro plan and wifi module only. I was just curious in trying to run servo motor with the help of Arduino Uno and bolt wifi module, learn how to network and pass the signals.

I am not sure if my idea can actually work, or I’m missing out something.

Do you know how Rx and Tx works? Serial Communication between master and Slave?
I recommend you to first understand the purpose of Rx and Tx.

You are missing out the whole concept of how serial communication works.

Yes, it is possible to control the servo from the bolt app,
you need to make 2 buttons that send the data to the arduino using html.
then using JS you can send an API request to send “1” or “0” via UART to the arduino
then the arduino can wait for any serial communiccation, when it recieves and command,it will check if its “0” or “1”, from where you can execute the desired function(of sweeping the servo 180*).

The same can be accomplised by upgrading to Bolt cloud pro plan and connecting the servo directly to bolt.

A few tips:
since the data is only being send from the bolt modult to arduino, the Tx from bolt should be connected to the Rx on the arduino.the other pair need not be connected

be careful with the data types during UART transmission.

if you run into problems in the UART transmission try debugging it by using a software serial passthrough

@sonalsurendra2000, Hope this helps you,

Have you done a simplex communication between bolt and arduino previously? Do share any project link.

If you want to deliberately use one pin, i.e. transmit. I suggest you to use a Modbus. Maybe the RS485 module to implement the simplex communication.

Again, Instead of this haphazard, you can use ANY of the pin instead of doing a serial communication.

Use the pins of bolt as OUTPUT and connect that pin to any of the digital pin (INPUT) in Arduino. Write the program, so that it performs a task when the arduino receives a HIGH in the input pin. Like, if (pin2 ==HIGH){ servoWrite(5, 180)}

Much sensible and easier to implement than using 2 extra components for the sake of serial communication with 1 pin.

That is what I had done, I have even pasted the arduino code but somehow it didn’t work. My initial question was to help me find out where I have gone wrong since I’m a beginner (Check the first post of this thread).

Thank you for the information, I will try this.

I have answered to your first post. Your arduino code is using servoMotor without the bolt module.

To my solution, you had another query if you need to use both the pins for serial communication.

I suggest you again, to do a basic serial communication between 2 Arduino on tinkercad.
Or if you want to know about serial communication, it is VERY IMPORTANT to know about the serial monitor. Which shows you everything going on in the serial communication.

In the arduino code, input is received from the Bolt module from pin 2 and then it works independently. Like you have mentioned here

"Use the pins of bolt as OUTPUT and connect that pin to any of the digital pin (INPUT) in Arduino. Write the program, so that it performs a task when the arduino receives a HIGH in the input pin. Like, if (pin2 ==HIGH){ servoWrite(5, 180)} "

Hence My arduino code is using servoMotor without the bolt module.

I have mentioned about using bolt with arduino.

I didn’t understand this part. What do you mean “hence… without the bolt module?”

Have you used the same trick as I mentioned? Is your servo running fine?