Using Bolt API in Python Code to trigger various Pins!

So I had been researching a lot on Bolt API and i realized that throughout the training we have been taught to send sms and emails if a condition is met in python code. I’m making this post so that we can also trigger events like lighting a LED or triggering a buzzer from the code it self. I’ll assume you know the basics of python like creating a file and running some code.

Step 1:
for this we need the following things:

  1. Bolt API Key
    which can be found at

  2. Device ID
    which can be found at

after you have obtained the two we need to make a python file and save the data in that file. the contents of the file should look like:


save it as

Create a new file as or whatever you want to name it as.
now we need to import certain modules namely boltiot and requests.
you may not have requests installed so you can do that by using pip3

sudo pip3 install requests

after installing the module write the following code

import conf
from boltiot import Bolt
import json, requests

mybolt = Bolt(conf.API_KEY, conf.DEVICE_ID)

url = ""+conf.API_KEY+"/digitalWrite"
urldata = {"pin":0,
comm = requests.request("GET",

save this file now.

Hardware Connections:

Connect the negative pin of the buzzer to the GND pin and the positive terminal to the 0 PIN (do not confuse with A0 that’s analog input)
Turn on the bolt module now.

Run the code
the buzzer should buzz (xD) about in 1 second. The output of the code will be something like
{"value": "1", "success": 1}

the requests function is used to make a web request using get method. notice that we have certain parameters defined in urldata variable that are

  • pin
  • state
  • deviceName (this will remain the same for one particular board )
    The pin corresponds to the pin number of the board to which you have connect the LED or buzzer. You can change it between 0-4 to access different pins on board.

You would have noticed in url variable we have used digitalWrite therefore we have only 2 state

1. HIGH (turn on the device connected/ high voltage/ ON state)
2. LOW (turn off the device connected/ low voltage/ OFF state)

please remember to enclose the keywords in ’ ’ else the requests function will return an error.

You can switch digitalWrite with analogWrite and then use value instead of state ranging from 0 to 254 to set desired voltages to increase or decrease intensity.


Nice post!
Another tip, the Bolt library already provides you the functionality for doing the above steps without you having to do the additional steps. You have import Bolt in your code but haven’t used it. I will post a sample below for your reference.

import conf
from boltiot import Bolt

mybolt = Bolt(conf.API_KEY, conf.DEVICE_ID)
pin = 0
state = "HIGH"
data = mybolt.digitalWrite(pin, state)
print (data)

You can check out the rest of the library here:

Let me know in case of any queries.


Sir in my case I have to send a value generated by the python script (decision tree algo) to the digital pin of arduino (Servo attached to arduino)

Please Help!
@ pranav.kundaikar