Docs

Docs

  • Home
  • Docs
  • Features
  • Download
  • Subscribe
  • Roadmap
  • Live Demo
  • Sign In

›Quick Start Guides

Getting Started

  • Introduction

Quick Start Guides

  • Control Arduino via Serial Port
  • Measure temperature using DS18B20 sensor
  • Start an application programmatically
  • Publish and receive MQTT messages
  • Call REST API and parse response
  • Control lights using Zigbee

Extensions

  • 1-Wire
  • ANSI x3.28 Serial Communication
  • Application Runner
  • AutoBits Hardware
  • Automator
  • Computer Hardware Monitor
  • Computer Vision
  • Demo
  • Email Sender
  • GSM Communication
  • MQTT Broker
  • PID Controller
  • Pinger
  • REST Service Client
  • Serial Port
  • Sliding Average
  • SQLite Storage
  • Video Capture
  • Video Recorder
  • Web Interface
  • Zigbee
  • UI Automation

Control Arduino with AutoBits via Serial Port

How to add buttons to AutoBits dashboard to control an LED through Serial Port.

Test.

1. Connect an LED to an Arduino

Connect an LED with a 220 Ω resistor in series to pins 13 and GND.

Wiring diagram Wiring diagram: https://www.arduino.cc/en/tutorial/blink

2. Upload sketch

The sketch will control the LED when it receives a command over Serial Port.

void setup() {
  pinMode(13, OUTPUT);
  Serial.begin(9600);
}

String command;

void loop() {
  while (Serial.available()) {
    char incomingChar = (char)Serial.read();

    if (incomingChar != '\n') {
      command += incomingChar;
    }
    else
    {
      executeCommand(command);
      command = "";
    }
  }  
}

void executeCommand(String command) {
  if (command == "on") {
    digitalWrite(13, HIGH);
  }
  else if (command == "off") {
    digitalWrite(13, LOW);
  }
}

3. Add buttons to dashboard

When you install AutoBits and start it for the first time, you will see a demo dashboard.

  • On the dashboard: Right Click -> Add Panel -> Button.

  • Open panel settings (using gear icon) and rename the button to On.

  • Repeat the steps to add Off button.

  • Save the dashboard by clicking Save Changes.

  • Click both buttons, so that AutoBits can learn about them.

Adding buttons to dashboard Adding buttons to a dashboard.

4. Enable Serial Port extension

Define device name, port and baud rate to use to connect to your Arduino:

  • Open Configure Extensions page.

  • Select Serial Port extension from the list of extensions.

  • Define the COM port to which the Arduino is connected. Set baudRate to match the baud rate from the sketch.

autoStart = false

[Arduino]
portName = COM4
baudRate = 9600
  • Turn on the extension.

Configuring Serial Port extension Configuring Serial Port extension.

5. Set up a reaction to a button click

Configure Automator extension to send commands to the Arduino when the buttons are pressed.

  • Add the following configuration to Automator extension:
autoStart = true

[Turn LED on]
when = Web User Interface :: On :: Clicked
execute = Serial Port :: Send Message
deviceName = Arduino
message = on

[Turn LED off]
when = Web User Interface :: Off :: Clicked
execute = Serial Port :: Send Message
deviceName = Arduino
message = off

Configuring Automator extension Configuring Automator extension.

6. Test

Open the dashboard and press the buttons. LED should turn on and off.

Conclusion

This guide shows how to send commands to devices using Serial Port. AutoBits can talk to any device with a serial port.

An Arduino with an LED was used as an example. Consider adapting this example for controlling a relay module or sending different commands to an Arduino.

← IntroductionMeasure temperature using DS18B20 sensor →
  • 1. Connect an LED to an Arduino
  • 2. Upload sketch
  • 3. Add buttons to dashboard
  • 4. Enable Serial Port extension
  • 5. Set up a reaction to a button click
  • 6. Test
  • Conclusion
CONTACT US
Telegramteam@automationgarage.com
Send Feedback
Automation Garage © 2019