powered by TinkerSpace.in
Join free
TinkerPy Tutorial 📘 Part 2 · Coder · Chapter 24 of 24

GSM & GPS

Your project can now send an SMS to a parent’s phone when there is a fire, obey an SMS that says “ON”, and know exactly where on Earth it is from satellites high above. Time to build real safety and tracking gadgets!

📖Key words

GSM module (SIM800L)

A small mobile-phone board with a SIM card. It sends and receives SMS and makes calls. Tick GSM in Circuit Connections: import gsm.

GPS module

A receiver (like the NEO-6M) that listens to satellites and works out where it is, how fast it moves and the exact time. import gps.

Fix

When the GPS has heard enough satellites to know its position. gps_found() is 1 then. Outdoors it takes about a minute.

Latitude, longitude

Two numbers that mark any place on Earth: how far north and how far east. gps_location() gives them as text, like "12.91416,74.85603".

Serial pins

GPS and GSM talk over wires called serial. The GPS’s TX wire goes to a pin set as gps_rx; the GSM’s TX wire to gsm_rx and its RX wire to an output set as gsm_tx.

🎬See it work

An SMS on its way

Tap each step to follow a fire alert from the board to a parent’s phone and back.

Smart and safe SMS?

Sort each idea: a good habit or not OK?

🧠How it works

GSM: send SMS and make calls

  • gsm_send_sms("+919876543210", "Door open") — the number in quotes, then text, a number or a join like "Temp " + t (up to 30 letters).
  • To protect your money the board sends the same SMS only once in 5 minutes and at most one SMS every 10 seconds. Still: send on a change (a new alarm), never in every loop.
  • gsm_call("+919876543210") rings a phone (the same number not again for 30 seconds). gsm_hang_up() ends a call or stops a ringing one.
  • gsm_signal() gives the mobile signal, 0 (none) to 100 (full).

GSM: read SMS and calls

  • gsm_sms_received() is 1 for one loop when an SMS arrives. gsm_read_sms() gives its text — compare it in quotes, capitals count: "ON" is not "on".
  • gsm_sms_number() gives the sender’s number as text. Reply with gsm_send_sms(gsm_sms_number(), "Got it") — or check it, so only your family can switch things.
  • gsm_ringing() is 1 while someone is calling the board.
  • The SIM800L needs its own 4 V, 2 A power supply (not the board’s 3.3 V or 5 V pin), with the grounds joined — ask an adult to help. It uses the older 2G network, so check that the SIM works in your area.

GPS: where, how fast and what time

  • gps_found() is 1 when it has a fix; gps_satellites() says how many satellites it hears (4 or more is good). Take it outdoors.
  • gps_location(): "latitude,longitude" text — show it, store it or send it by SMS, and paste it into a map app. Empty (None) until there is a fix.
  • gps_speed() in km/h, gps_altitude() in metres, gps_hour(), gps_minute(), gps_second() in Indian time — no clock to set.
  • gps_save_home() in setup: remembers this place as home; gps_distance_home() gives the metres from home.

Pins, firmware and safety

  • GPS and GSM pins can be any pins: the editor adds gps_rx_1 = set_input(gps_rx), gsm_rx_1 = set_input(gsm_rx) and gsm_tx_1 = set_output(gsm_tx) — change them to where your wires really go.
  • They need board firmware 2.28 or newer. The Simulator has a GPS tile (walk N, S, E, W) and a GSM phone tile, so test there first — for free.
  • SMS and calls cost money: use a SIM only with a parent’s permission, send only to family who agreed, never spam, never prank-call and never test with an emergency number.
  • Location is private: share it only with your family.

💻Code

# Add the libraries you need
import buzzer
import gsm

# Give your pins easy-to-remember names
i1 = set_name("fire_eye")
o2 = set_name("siren")
i2 = set_name("gsm_rx_1")
o1 = set_name("gsm_tx_1")

# ===== SMS fire alert =====

# This code block executes only once
setup:
    fire_eye = set_input(flame, active_low)
    siren = set_output(buzzer)
    gsm_rx_1 = set_input(gsm_rx)
    gsm_tx_1 = set_output(gsm_tx)
    sent = 0  # set sent to 0

# This code block executes forever
loop:
    if fire_eye == ON:  # when fire_eye is ON
        siren = ON  # turn siren ON
        if sent == 0:  # when sent == 0
            gsm_send_sms("+919876543210", "FIRE alarm at home!")  # a parent’s number
            sent = 1  # only one SMS for this fire
    else:  # otherwise
        siren = OFF  # turn siren OFF
        sent = 0  # set sent to 0

An SMS fire alert: when the flame sensor sees fire, the siren sounds and ONE SMS goes to a parent’s number (put your family’s number in, with their permission). The flag sent is cleared when the fire is gone.

# Add the libraries you need
import oled_display
import gsm

# Give your pins easy-to-remember names
o2 = set_name("lamp")
i1 = set_name("gsm_rx_1")
o1 = set_name("gsm_tx_1")

# ===== SMS-controlled light =====

# This code block executes only once
setup:
    oled_begin()  # starts the OLED
    o7 = set_function(SDA)  # cannot be changed
    o8 = set_function(SCL)  # cannot be changed
    lamp = set_output(led)
    gsm_rx_1 = set_input(gsm_rx)
    gsm_tx_1 = set_output(gsm_tx)

# This code block executes forever
loop:
    oled_write(1, left, small, regular, "Signal " + gsm_signal())  # write "Signal " + gsm_signal() on OLED line 1 (small, from the left)
    if gsm_sms_received() == 1:  # when gsm_sms_received() == 1
        msg = gsm_read_sms()  # the text of the SMS
        who = gsm_sms_number()  # the number that sent it
        if who == "+919876543210":  # when who == "+919876543210"
            if msg == "ON":  # when msg == "ON"
                lamp = ON  # turn lamp ON
                gsm_send_sms(who, "Light is ON")  # send an SMS to who
            elif msg == "OFF":  # otherwise, when msg == "OFF"
                lamp = OFF  # turn lamp OFF
                gsm_send_sms(who, "Light is OFF")  # send an SMS to who
    if gsm_ringing() == 1:  # when gsm_ringing() == 1
        oled_write(3, left, small, bold, "Someone is calling")  # write "Someone is calling" on OLED line 3 (small bold, from the left)
        wait(3000)  # pause here for 3000 milliseconds before continuing
        gsm_hang_up()  # end the phone call
        oled_clear_line(3)  # clear line 3 of the OLED
    wait(200)  # pause here for 200 milliseconds before continuing

An SMS-controlled light: an SMS saying ON or OFF from the family number switches the lamp and gets a reply. SMS from other numbers are ignored. A call to the board is shown, then hung up after 3 seconds.

# Add the libraries you need
import oled_display
import gps

# Give your pins easy-to-remember names
o1 = set_name("fix_led")
i1 = set_name("gps_rx_1")

# ===== Bus GPS display =====

# This code block executes only once
setup:
    oled_begin()  # starts the OLED
    o7 = set_function(SDA)  # cannot be changed
    o8 = set_function(SCL)  # cannot be changed
    fix_led = set_output(led)
    gps_rx_1 = set_input(gps_rx)
    gps_save_home()  # the school gate = home

# This code block executes forever
loop:
    if gps_found() == 1:  # when gps_found() == 1
        fix_led = ON  # turn fix_led ON
        oled_write(1, left, small, regular, gps_location())  # write the value of gps_location() on OLED line 1 (small, from the left)
        oled_write(2, left, small, regular, "Speed " + gps_speed() + " km/h")  # write "Speed " + gps_speed() + " km/h" on OLED line 2 (small, from the left)
        oled_write(3, left, small, regular, "From school " + gps_distance_home() + " m")  # write "From school " + gps_distance_home() + " m" on OLED line 3 (small, from the left)
        oled_write(4, left, small, regular, gps_hour() + ":" + gps_minute() + ":" + gps_second() + " Height " + gps_altitude())  # write the value of gps_hour() + ":" + gps_minute() + ":" + gps_second() + " Height " + gps_altitude() on OLED line 4 (small, from the left)
    else:  # otherwise
        fix_led = OFF  # turn fix_led OFF
        oled_write(1, left, small, regular, "Finding satellites")  # write "Finding satellites" on OLED line 1 (small, from the left)
        oled_write(2, left, small, regular, "Can see " + gps_satellites())  # write "Can see " + gps_satellites() on OLED line 2 (small, from the left)
    wait(1000)  # pause here for 1000 milliseconds before continuing

A bus GPS display: home is saved at the school gate. With a fix it shows the location, speed, distance from school, time and height; without one it shows how many satellites it can hear. Test it outdoors.

# Add the libraries you need
import gps
import gsm

# Give your pins easy-to-remember names
i3 = set_name("sos_btn")
o2 = set_name("sent_led")
i1 = set_name("gps_rx_1")
i2 = set_name("gsm_rx_1")
o1 = set_name("gsm_tx_1")

# ===== SOS button with location =====

# This code block executes only once
setup:
    sos_btn = set_input(push_button, active_low)
    sent_led = set_output(led)
    gps_rx_1 = set_input(gps_rx)
    gsm_rx_1 = set_input(gsm_rx)
    gsm_tx_1 = set_output(gsm_tx)

# This code block executes forever
loop:
    if sos_btn == ON:  # when sos_btn is ON
        if gps_found() == 1:  # when gps_found() == 1
            gsm_send_sms("+919876543210", "SOS at " + gps_location())  # send an SMS to "+919876543210"
        else:  # otherwise
            gsm_send_sms("+919876543210", "SOS - no GPS fix yet")  # send an SMS to "+919876543210"
        sent_led = ON  # turn sent_led ON
        wait(5000)  # pause here for 5000 milliseconds before continuing
        gsm_call("+919876543210")  # then ring the same phone
        wait(5000)  # pause here for 5000 milliseconds before continuing
        sent_led = OFF  # turn sent_led OFF

An SOS button for TinkerPy Mega (it uses i3): one press sends an SMS with the location, then rings the same phone. The editor put the GPS and GSM pins on i1, i2 and o1.

Open TinkerPy Code

🎉Fun examples

🇮🇳India’s own navigation

Besides GPS, India has its own satellite navigation system called NavIC, built by ISRO.

🚌Where is my bus?

A GPS on the school bus can send its location every few minutes, so nobody waits in the rain for a late bus.

🌾Missed-call pump

Many farmers switch pumps with an SMS or a call. With gsm_ringing() your board can do it too.

🌍Where it’s used

🛠️Project ideas

SMS fire alert

Build the fire alert with a flame sensor and a buzzer. Add a second SMS that says “Fire is out” when the sensor is safe again for 30 seconds. Test it in the Simulator before you use a real SIM.

🧰 You need: TinkerPy board, flame sensor, buzzer, SIM800L with its own 4 V supply, SIM card (with a parent’s permission)
Bus location tracker

Show the GPS location, speed and distance from school on the OLED. When the bus is 500 m from school, send one SMS “Bus arriving” to the class teacher’s number (with permission).

🧰 You need: TinkerPy board, GPS module, OLED display, SIM800L (optional)

⭐Points to remember

  1. import gsm for SMS and calls; import gps for location.
  2. GSM pins: module TX → gsm_rx, module RX → gsm_tx (an output).
  3. The SIM800L needs its own 4 V, 2 A supply with the grounds joined.
  4. gsm_send_sms("number", text) — up to 30 letters.
  5. Send an SMS on a change, never in every loop — SMS cost money.
  6. gsm_sms_received() is 1 for one loop; gsm_read_sms() gives the text.
  7. Capitals count: "ON" is not "on".
  8. gsm_sms_number() gives the sender — reply or check it.
  9. gsm_call(), gsm_hang_up(), gsm_ringing(), gsm_signal() for calls and signal.
  10. gps_found() is 1 with a fix — take the GPS outdoors.
  11. gps_location() gives "latitude,longitude" text.
  12. gps_speed() km/h, gps_altitude() m, gps_hour/minute/second in Indian time.
  13. gps_save_home() in setup:, then gps_distance_home() in metres.
  14. GPS and GSM need board firmware 2.28; test in the Simulator first.
  15. Parent’s permission, no spam, no pranks, location only for family.
🤯
Did you know?

GPS satellites fly about 20,000 km above the Earth and carry very exact atomic clocks. Your GPS module finds its position from tiny differences in the time their signals take to arrive.

❓Mini quiz

🔑
Log in to try the mini quiz

5 quick questions to check yourself — free with your TinkerPy account.

Log in