Creating Your First BLE Project: A Step-by-Step Tutorial — BLE Guide 2023

Ghayoor Zafar, Marketing Manager

Published
Feb 22, 2024
Read Time
10 Min Read

Hello, BLEthusiasts! 🎉 By now, you’ve got your BLE basics and your development environment ready to go. It’s time to get your hands dirty with some actual coding. Today, we’ll walk you through a simple project to control an LED light using BLE and a Raspbe

01 What You’ll Need

  • Raspberry Pi (any model with BLE support)
  • An LED light
  • A 220-ohm resistor
  • Breadboard and jumper wires

02 Step 1: Set Up Your Hardware

  1. Connect the LED to the breadboard: Insert the LED into the breadboard.
  2. Connect the Resistor: Insert a 220-ohm resistor next to the LED’s longer leg (anode).
  3. Wire it Up: Connect a jumper wire from the Raspberry Pi’s GPIO pin 17 to the resistor. Connect another jumper wire from the LED’s shorter leg (cathode) to the Raspberry Pi’s ground (GND) pin.

03 Step 2: Install Required Software

Open your Raspberry Pi terminal and run:

sudo apt-get update
sudo apt-get install python3-pip
pip3 install pybleno

This will update your package list, install pip for Python 3, and install the pybleno library.

04 Step 3: Write the Code

Create a new Python file:

nano my_ble_led.py

Copy and paste the following code:

from pybleno import Bleno
import RPi.GPIO as GPIO

# Initialize GPIO
GPIO.setmode(GPIO.BCM)
GPIO.setup(17, GPIO.OUT)

# Initialize BLE
bleno = Bleno()

def onStateChange(state):
    if state == 'poweredOn':
        bleno.startAdvertising('LEDController', ['ec00'])
    else:
        bleno.stopAdvertising()

def onAdvertisingStart(error):
    print('BLE advertising started.')

bleno.on('stateChange', onStateChange)
bleno.on('advertisingStart', onAdvertisingStart)

bleno.start()

Save the file and exit the editor.

05 Step 4: Run the Code

In your Raspberry Pi terminal, run:

python3 my_ble_led.py

You should see a message saying “BLE advertising started.”

06 Step 5: Test Your Project

Use a BLE scanner app on your smartphone to look for a device named “LEDController.” If you see it, congratulations! Your BLE project is up and running.

07 Troubleshooting

  • If the LED doesn’t light up, double-check your wiring.
  • If “LEDController” doesn’t appear on your BLE scanner, make sure your Raspberry Pi’s Bluetooth is enabled.

08 Conclusion

You did it! You’ve successfully created your first BLE project. Stay tuned for more advanced tutorials.

09 What’s Next?

Our next article will focus on “BLE Security Protocols: Locking Down Your BLE Projects.”

Want to get ble development done by experts? Contact Sparkleo and get an IoT & BLE app developed by the best!!!

Was This Article Helpful?

Keep reading

More From The Blog

Contact us

Ready To Connect?

Choose the route that matches your stage.

01 · Fastest first response

Say Hello On WhatsApp

Best for a first hello, a basic question, or checking whether we're the right fit before going further.

Suggested first message

Hi! I'm working on [your product] and have a quick question about [topic].

or message +358 41 7432390