logo-mobile

ROHM

ROHM
Menu
  • Arduino –
  • Raspberry Pi –
  • Trending –
  • Others –
  • About –
  • Contact –

Arduino

How to control an Arduino from a Windows computer

DevicePlus Editorial Team
Published by DevicePlus Editorial Team at August 6, 2021
Categories
  • Arduino
Tags
How to control an Arduino from a Windows computer

Arduino projects make it possible to build your own custom electronics, but that doesn’t mean they can’t interact with your regular gadgets like your laptop or phone. With a simple module, you can add Bluetooth connectivity to your Arduino board and communicate with software you write yourself and make your projects even more advanced. In this guide, we’ll show how to connect your Arduino board to a Windows computer using a Bluetooth module.

How Bluetooth On Arduino Works

While a few Arduino boards come with Bluetooth modules built in—for example, the Arduino BT—most don’t. In order to add Bluetooth capability to an Arduino project, you’ll need a separate module like the HC-05 we’ll be using in this guide. With just a few wires, you can connect a Bluetooth module and control your Arduino wirelessly.

The module uses two lesser-used pins on the Arduino: the TX and RX pins. These pins are used for serial communication, with the TX pin being used for transmission, and the RX pin is used for receiving. You might’ve used serial communication when connected to the computer via USB, but these pins allow another way to communicate with the Arduino without being physically connected.

This lets you send commands wirelessly to your Arduino from the computer, either using the serial monitor in the Arduino IDE or your own applications if you want to code your own. For this guide, we’ll show how to turn an LED connected to the Arduino on and off using typed commands from a Windows computer.

What You’ll Need

To make a start on your Arduino Bluetooth project, you won’t need many products. A simple Bluetooth module will do. While there are a few varieties of Bluetooth modules and shields for the Arduino platform on the market, we’ll be using the HC-05. Here’s the full list of what you’ll need:

Arduino Uno Arduino Uno
Bluetooth HC-05 module Bluetooth HC-05 module
An LED LED
Wires & breadboard Wires & breadboard
USB cable USB cable
Arduino IDE Arduino IDE

Once you have everything you need, move on to the code section to get started.

The Code

The full sketch for this project will let you send a text command from the serial monitor in the Arduino IDE to your project and turn on an LED. First, here’s the full code to get started:

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
#include
SoftwareSerial BT(1, 0);
void setup()
{
  pinMode(8, OUTPUT);
  BT.begin(9600);
}
char cmd;
void loop()
{
  if (BT.available())
  {
    cmd=(BT.read());
    if (cmd=='1')
    {
      digitalWrite(8, HIGH);
      BT.println(" LED on");
    }
    if (cmd=='2')
    {
      digitalWrite(8, LOW);
      BT.println(" LED off");
    }
  }

Copy this code into your IDE and upload it to your Arduino board. Next, let’s look at some of the key points of this sketch line by line.

C
1
2
#include
SoftwareSerial BT(1, 0);

These two lines will include the SoftwareSerial.h library that makes it a little easier to communicate over the serial port. The second line will create a Bluetooth serial object named BT, that we’ll use later.

1
2
3
4
5
void setup()
{
  pinMode(8, OUTPUT);
  BT.begin(9600);
}

In the setup section, we’ll assign the LED to pin 8, which we can use to turn the LED on and off. We’ll also start the BT object on the serial port.

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
char cmd;
void loop()
{
  if (BT.available())
  {
    cmd=(BT.read());
    if (cmd=='1')
    {
      digitalWrite(8, HIGH);
      BT.println(" LED on");
    }
    if (cmd=='2')
    {
      digitalWrite(8, LOW);
      BT.println(" LED off");
    }
  }
}

The main loop of this sketch consists of a single conditional IF statement. If the Arduino detects the serial monitor, it will listen for commands. If you type “1” in the monitor, it will turn the LED on pin 8 on. If you type “2” in the monitor, it will turn the LED off. In both cases, it will also print a message to the serial monitor letting you know the code worked.

The Wiring (and Wireless Connection)

Wiring

Connecting the HC-05 Bluetooth module is relatively straightforward. To connect the Bluetooth module to Arduino, follow these steps:

  • Connect RXD on the HC-05 to the RX pin on the Arduino.
  • Connect TXD on the HC-05 to the TX pin on the Arduino.
  • Connect VCC on the HC-05 to the 5V pin on the Arduino.
  • Connect GND on the HC-05 to the GND pin on the Arduino.

Once the wiring is connected, your HC-05 should be blinking rapidly, which indicates it’s discoverable by your computer. Now you’ll need to pair it with your computer.

To do this, open your computer’s Bluetooth settings page and search for available devices. You should be able to find an HC-05 device in the list. When you try to pair it, you’ll be asked for a pin. In most cases this should be either “1234” (as is the case for the HC-05) or “0000” but check the documentation for your module if you used something different.

Once that’s done, you’ll need to switch the serial monitor in the IDE to the correct COM port. You can find out which one is the correct one by opening the Bluetooth settings page in Windows 10, clicking “More Bluetooth options,” and selecting the “COM ports” tab. If the Bluetooth module and Arduino are successfully paired, you should see it here with the proper COM port listed next to it.

Go back to your Arduino IDE and under Tools > Port, select the COM port your Bluetooth module is connected to. Then, select Tools > Serial Monitor, and start typing commands. You can now control your Arduino remotely, completing this Arduino Bluetooth project. Try adding more LEDs and controlling them from different pins with additional commands next.

 

DevicePlus Editorial Team
DevicePlus Editorial Team

Check us out on Social Media

  • Facebook
  • Twitter

Recommended Posts

  • Building DIY Drone from Scratch Part 3: Making GPS Follow-Me DroneBuilding DIY Drone from Scratch Part 3: Making GPS Follow-Me Drone
  • ESP-WROOM-02 Setup GuideESP-WROOM-02 Setup Guide
  • How To Finally Get The Most Out Of Those Smart Home DevicesHow To Finally Get The Most Out Of Those Smart Home Devices
  • Let’s Play with ESP-WROOM-32 on Arduino (Environment Construction Setup – LED Blinking)Let’s Play with ESP-WROOM-32 on Arduino (Environment Construction Setup – LED Blinking)
  • How to Read Your Arduino’s MindHow to Read Your Arduino’s Mind
  • How To Make Smart Home Electronics: A Smart MailboxHow To Make Smart Home Electronics: A Smart Mailbox
Receive update on new postsPrivacy Policy

Recommended Tutorials

  • How to integrate an RFID module with Raspberry Pi How to integrate an RFID module with Raspberry Pi
  • How to Use the NRF24l01+ Module with Arduino How to Use the NRF24l01+ Module with Arduino
  • How to Run Arduino Sketches on Raspberry Pi How to Run Arduino Sketches on Raspberry Pi
  • Setting Up Raspberry Pi as a Home Media Server Setting Up Raspberry Pi as a Home Media Server

Recommended Trends

  • SewBot Is Revolutionizing the Clothing Manufacturing Industry SewBot Is Revolutionizing the Clothing Manufacturing Industry
  • All About The Sumo Robot Competition And Technology All About The Sumo Robot Competition And Technology
  • 5 Interesting Tips to Calculating the Forward Kinematics of a Robot 5 Interesting Tips to Calculating the Forward Kinematics of a Robot
  • Go Inside the Drones That Are Changing Food Delivery Go Inside the Drones That Are Changing Food Delivery
Menu
  • Arduino –
    Arduino Beginner’s Guide
  • Raspberry Pi –
    Raspberry Pi Beginner's Guide
  • Trending –
    Updates on New Technologies
  • Others –
    Interviews / Events / Others

Check us out on Social Media

  • Facebook
  • Twitter
  • About
  • Company
  • Privacy Policy
  • Terms of Service
  • Contact
  • Japanese
  • 简体中文
  • 繁體中文
Don’t Forget to Follow Us!
© Copyright 2016-2023. Device Plus - Powered by ROHM
© 2023 Device Plus. All Rights Reserved. Muffin group

istanbul escort istanbul escort istanbul escort