How to send sms when LED bulb is on without using light sensor?

I am using my bulb as an indicator. The bulb will be switched on with the help of on/off button on mobile or computer. When the bulb is switched on, I want to send an SMS to the user.

@sakshidoshi3 you have to make account on Twilio(it is third party app), with the help of twilio you able to send sms to the user.

Yes, yes that is not my question though. For eg if you want to send an sms when the light is on, you just check the value of the light sensor right. And if it’s exceeding a particular limit then you send an sms. But what if I want to do it without a sensor? How will my code be?

I think you need to get an Sms when your GPIO pin is HIGH .
So you need to change the code by getting an sms which checks the condition of exceeding the maximum limit (light) to check when the digital pin is high. So simply change by that.
I think it works. Try it and I hope the result after.

import conf,json,time
from boltiot import Sms, Bolt
import json, time
mybolt = Bolt(conf.API_KEY, conf.DEVICE_ID)
sms = Sms(conf.SSID, conf.AUTH_TOKEN, conf.TO_NUMBER, conf.FROM_NUMBER)
while True:
    check_status = mybolt.digitalRead('2')
    data = json.loads(check_status)
    print("THE LED IS" + str(data['value']))
    status = str(data['value'])
    #if status == '1':
	    #response = sms.send_sms('LED is on')

This is my code. Over here, the digitalRead function is controlling the LED and making it LOW. I don’t want to control anything. I just want to print if LED is on or not. How do we resolve this? Thankyou…

Here actually we are creating buttons using javascript right? And if we are sending a Twilio message in python… How is it possible!!! I am totally confused. Anyway you also check.

Yes exactly. I am creating buttons in html. I need a connection between my html and python. Just do not know how to. Thank you though.

I found out something.Please go through the below attached link.I hope this will be very was quite interesting for me.

I really hope the result after.
Thank you…

alright… Thank you so much :))

Hey @sakshidoshi3 , I am also using my bulb as an indicator. I need to send a Twilio SMS if my bulb turns ON. I am using my VMware and ubuntu server iso on my pc. Can you send the code for the above statement.

Does this code worked? Did it send SMS?

I am still working on it. But I will surely let you know once i figure it out :))

from flask import Flask, request
import conf
import json
import time
from boltiot import Sms, Bolt
import json
import time

mybolt = Bolt(conf.API_KEY, conf.DEVICE_ID)
sms = Sms(conf.SSID, conf.AUTH_TOKEN, conf.TO_NUMBER, conf.FROM_NUMBER)

app = Flask(__name__)

@app.route("/sendSMS", methods=['GET'])
def sendSMS():
    if request.method == 'GET':
        ledstatus = request.args.get('ledstatus')

    print(ledstatus == '1')

    res = {
        'code': "400",
        'data': "Bad request",
    if ledstatus == '1':
        print(sms.send_sms('LED is on!'))
        res = {
            'code': 200,
            'data': "SMS sent"

    elif ledstatus == '0':
        print("led off")

    return json.dumps(res)

So this is my python backend code. I have used Flask in it because that seemed to be the easiest way out. Now, this bulb will glow everytime the LED is made on via the html code and also send an sms. Here is my html code

    <title>Bolt IoT Platform</title>
    <script type="text/javascript" src=""></script>
    <button onclick="switchLEDoN()">ON</button>
    <button onclick="switchLEDoFF()">OFF</button>
        let status = 0;
        function switchLEDoN() {
            if(status == 0) {
                digitalWrite(2, 'HIGH');
        function switchLEDoFF() {
            if(status == 1){
                status = 0;
                digitalWrite(2, 'LOW');
Make sure you run the python file in backend before experimenting with the HTML to receive a sms