• 0Shopping Cart
Robots in Architecture Research
  • Home
  • About
    • Who We Are
    • Industrial Partners
    • Academic Partners
    • News / Gallery
  • KUKA | prc
    • Commercial Licenses
    • Tutorials
    • Software Download
  • KUKA | crc Workshops
    • Program
    • Calendar
  • Consultancy
    • Industrial Training
    • Custom Software Development
    • KUKA | prc Embedded
  • Contact
  • Menu Menu
Blog - Latest News

2.1.1 – Basics – Basic Limit Switch IoT

Table of Content

Intro
Demo Video
Downloadables
Used Hardware
Wiring Diagram
Code Explanation
Helpful Links

Intro

In this tutorial, we will explore the development of a prototype that harnesses the power of Node-RED and MQTT to control the movement of a linear axis over a specified distance. From serving as a torch height controller in welding or plasma cutting operations to acting as a mount for a line scanner, the adaptability of this modified linear axis is quite useful.

If you don´t have the hardware but still want to try IoT ideas out you can use Wokwi and/or TinkerCAD to simulate the basic hardware with ESP32 and Arduino boards.

Demo Video

Downloadables

  • Arduino IDE Code File
  • Node-RED Flow

Used Hardware

    • Linear Axis
    • NEMA 23-02: Bipolar Stepper Motor
    • 2H Microstep Driver DM420
  • Power Supply MW RT-65D
  • Limit Switch
  • NodeMCU – ESP8266

Linear Axis

A linear axis refers to the straight-line path along which an object can move or be moved. In the context of machinery, it’s a component that allows movement in a straight line, providing precise positioning in applications like welding or scanning.

NEMA 23-02: Bipolar Stepper Motor

A bipolar stepper motor is a type of motor with one winding per phase and no center tap. It can produce more torque than a unipolar stepper motor of the same size, but requires a more complex driver circuit that can reverse the current direction in each winding.

  • 1.2 Nm
  • 2.5A 3 V
  • Shaft diameter: 6.35 mm
  • Connection: 4 pin Female (JST male)
  • Steps per revolution : 200
  • 56 x 56 x 56 mm
  • Angle: 1,8 °
  • More detail at: Link

2H Microstep Driver DM420

A microstep driver is a device that controls stepper motors to achieve higher resolution or smoother motion at low speeds. It allows intermediate step locations by energizing the coils with intermediate current levels.

  • DM420 is a two-phase hybrid stepper motor driver.
  • Between 12VDC and 36V DC
  • Output current: 0.44 – 2.83 A
  • Input current: < 2.0 A
  • More detail at: Link

One of the key features of electrical microstep drivers is their ability to adjust the pulse and current sent to the motor. These settings are typically displayed on the driver itself in the form of a printed table, as well as in the datasheet. They are controlled by small DIP switches. The table indicates which switches should be turned on or off, depending on the desired settings.

Here’s a breakdown of our settings:

  • Current Settings (SW1 to SW3): These switches control the current sent to the motor. In your case, “SW1” OFF, “SW2” OFF, “SW3” ON corresponds to a peak current of 0.86A and an RMS (Root Mean Square) current of 0.61A.
  • Half/Full Current (SW4): This switch determines whether the driver outputs half or full current. In your case, “SW4” ON means that the driver is set to output half current. Therefore, the peak current will be 0.43A and the RMS current will be 0.305A.
  • Microstep Settings (SW5 to SW7): These switches set the microstep resolution, which determines the number of pulses per revolution. In your case, “SW5” ON, “SW6” OFF, “SW7” ON corresponds to 800 pulses per revolution and a microstep size of 4.

Power Supply MW RT-65D

A power supply is a hardware component that supplies power to an electrical device. It receives power from an electrical outlet and converts the current from AC (alternating current) to DC (direct current), which is what the most IoT components require.

  • Cased
  • Screw connections
  • Long Life 105°C electrolytic capacitors
  • Output voltage: CH1: 5V / CH2: 24V / CH3: 12V
  • Output current: CH1: 4A / CH2: 1.5A / CH3: 1A
  • Power: 68 W
  • 129 x 98 x 38 mm
  • Protected against short circuit, overload, overvoltage
  • More detail at: Link

Limit Switch

A limit switch is an electro-mechanical device operated by the motion of a machine part or the presence of an object. It can be used for controlling machinery as part of a control system, as a safety interlock, or as a counter enumerating objects passing a point.

NodeMCU – ESP8266

The NodeMCU ESP8266 board is an open-source Lua based firmware and development board specially targeted for IoT based Applications. It includes firmware that runs on the ESP8266 Wi-Fi SoC from Espressif Systems, and hardware which is based on the ESP-12 module.

  • Type: ESP-8266
  • Clock Frequency: 80 – 160 MHz
  • 49 x 26 x 13 mm
  • Wi-Fi Chip
  • Wireless Standard: 802.11 b/g/n
  • Frequency: 2,4 GHz
  • More detail at: Link

Wiring Diagram

In this section, we have provided the wiring details for the IoT-enabled linear axis setup. The gallery below presents an overview diagram, along with detailed images of the wiring for each complex component. (The images can be clicked on to see in detail.)

Code Explanation

The Declarations

To utilize the libraries, they must first be included in your code. With the EspMQTTClient library, an MQTT publisher client is created. This requires the WiFi name and password to enable the NodeMCU board to connect to the WiFi network and establish a connection with the MQTT server.

Once the client is set up, you can define the pins to be used (in this case, we used D5 (GPIO 14) for the limit switch and D6(GPIO 12) and D7(GPIO 13)). Additionally, you can set the maximum speed and acceleration of your stepper motor, as well as the steps and distance in millimeters.

The Setup Function

The setup function initializes the serial communication, enables MQTT client debugging, and sets the stepper motor’s maximum speed and acceleration. The switch pin is also set as an input with the pull-up resistor enabled. Finally, the home function is invoked to set the initial position of the stepper motor. The home function establishes a reference point for the linear axis by moving it to the limit switch and setting a new home position. This is done each time the linear axis starts to ensure correct calibration and operation within its defined range of motion.

The Loop Function

The loop() function, a fundamental part of Arduino programming, executes continuously until the device is reset or powered off. It repeatedly performs tasks such as reading sensors and controlling outputs. In this code, the loop function uses the MQTT client’s loop function to maintain a connection to the MQTT server and publishes a message to the “devices” topic with the device name every 500ms to ensure visibility on the MCU when connected.

The Home Function

The home function moves the motor towards a limit switch until it is pressed, indicating that the motor has reached its initial position. Once the switch is pressed, the motor’s current position is set as the new zero position, and it is moved away from the switch by a specific number of steps.

The onConnectionEstablished and onMessageReceived Functions

These two functions, onConnectionEstablished and onMessageReceived, work together to handle incoming commands from a Node-RED dashboard using JSON formatting. The former function subscribes to the device command input, while the latter function processes received messages. If the “Home” command is received, the home function is invoked, causing the motor to move towards the limit switch again. If the “SetValue” command is received with a specified value, the motor moves to the desired distance in millimeters. If the distance is less than zero, it is set to zero, and if it is greater than 280mm, it is capped at 280mm. This ensures that the limit switch never attempts to exceed its limits.

Node-Red – UI

As illustrated in the videos and gifs, the system is quite straightforward. It comprises three interactive components that enhance user interaction. The first component allows the user to adjust the target distance in millimeters. This adjustment can be made either by manually entering the value or by using the up and down buttons situated next to the text field. However, the system imposes pre-set limits on the linear axis, preventing the user from issuing commands beyond 280mm and below 0mm.

The second component is the command initiation button. This button must be pressed to transmit the value as a command. Without this action, the linear axis remains stationary.

The third component is the home button, which returns the linear axis to its initial position.

Finally, the ‘CMD’ section is located at the bottom of the group. This section displays the specific command sent to the MQTT server, as well as the information read by the pre-existing script. This feature enhances the system’s transparency, ensuring that the correct commands are sent and executed properly.

Node-Red – Flow

The Node-RED flow provided is divided into four specific sections. The initial section, known as the ‘info group’, encompasses details such as the name of the flow, its version, the date of the last update to the script, and the original author of the script. The second section consists of UI elements that will be used for CMD creation. Third part is responsible for the JSON Objects creation and sending the CMD to the device´s cmd topic. Last section is for checking the state of the device.

The process of command creation is uncomplicated and yields a JSON format that we explored in the basics lecture. It usually includes components such as “id”, “cmd”, “dev”, “sync”, and “state”. For a more in-depth understanding of JSON formatting, I recommend revisiting the basics section of the tutorials. In this instance, to mirror the code in the NodeMCU, we are utilizing “id”, “dev”, and “cmd”, “state” and “value”.

For the MoveDistance and HomeButton functions the JSON formatting from our lectures were used. The script used for these functions to generate the JSON format as follows:

//HomeButton
msg.payload = {};

msg.payload.id = "noderedcmd";
msg.payload.dev = "linaxis1";
msg.payload.cmd = "Home";

msg.payload.state = true;

return msg;
//MoveDistance
msg.payload = {};

msg.payload.id = "noderedcmd";
msg.payload.dev = "linaxis1";
msg.payload.cmd = "SetValue";

msg.payload.value = flow.get("distance");

return msg;

Please remember to modify the Broker Server of the MQTT in and out node when testing the script.

Helpful Links

  • Simple Node-RED and MQTT Tutorial – Learn Robotics YouTube
  • Simulating IoT projects in Wokwi | MQTT in ESP32 – High Voltages YouTube
May 31, 2024/by Görkem Can Ertemli
Share this entry
  • Share on Facebook
  • Share on Twitter
  • Share on WhatsApp
  • Share on Pinterest
  • Share on LinkedIn
  • Share on Tumblr
  • Share on Vk
  • Share on Reddit
  • Share by Mail
/wordpress/wp-content/uploads/2023/08/Robots-in-Architecture-Research-Logo-1-1030x491.png 0 0 Görkem Can Ertemli /wordpress/wp-content/uploads/2023/08/Robots-in-Architecture-Research-Logo-1-1030x491.png Görkem Can Ertemli2024-05-31 09:44:162024-05-31 09:48:002.1.1 – Basics – Basic Limit Switch IoT

Wiki Home

0 - Installations

0.0 - Setup - Introduction

0.1 - Setup - MQTT
    • 0.1.1 - HiveMQ
    • 0.1.2 - Mosquitto
    • 0.1.3 - Python-Paho-MQTT
    • 0.1.4 -Android-MQTT
    • 0.1.5 - IOS-MQTT

0.2 - Setup - Node-RED
    • 0.2.1 - Node-RED
    • 0.2.2 - Node-RED-Palettes

0.3 - Setup - Grasshopper
    • 0.3.1 - KukaPRC
    • 0.3.2 - Echo-MQTT (WIP)

0.4 - Setup - NodeMCU
    • 0.4.1 - Arduino IDE
    • 0.4.2 - ESP8266-Library
    • 0.4.3 - EspMQTTClient

0.5 - Setup - Raspberry
    • 0.5.1 - Raspberry Pi Flashing

0.6 - Setup - SQL
    • 0.6.1 - MySQL

1 - Basics

1.1 - Basics - IoT
    • 1.1.1 - Introduction to IoT
    • 1.1.2 - Introduction to PRC.IoT (WIP)

1.2 - Basics - MQTT
    • 1.2.1 - Understanding MQTT
    • 1.2.2 - Simple MQTT Demo

1.3 - Basics - Node-RED
    • 1.3.1 - Node-RED Basics
    • 1.3.2 - Node-RED Dashboard
    • 1.3.3 - Node-RED MQTT
    • 1.3.4 - Phone MQTT Publisher

1.4 - Basics - JSON
    • 1.4.1 - JSON Formatting
    • 1.4.2 - Robot Commands
    • 1.4.3 - Gripper Activate Button
    • 1.4.4 - Robot States
    • 1.4.5 - Robot State Visualizer

1.5 - Basics - Grasshopper

1.5.1 - GH PRC
      • Basic Components (WIP)
      • Send to Robot (WIP)
      • Translate (WIP)

1.5.2 - GH Metadata
      • 1.5.2.1 - Metadata / JSwan
      • 1.5.2.2 - Sub-Devices (WIP)

1.5.3 - GH SQL
      • 1.5.3.1 - What is SQL
      • 1.5.3.2 - SQL Query in Grasshopper (WIP)

1.5.4 - GH PRC.IoT
      • WIP

1.6 - Basics - Robots
    • 1.6.1 - MCU (WIP)
    • 1.6.2 - RCU (WIP)
    • 1.6.3 - DCU (WIP)

2 - Intermediate

2.1 - Example IoT Projects w Hardware
    • 2.1.1 - Basic Limit Switch IoT
    • 2.1.2 - Basic Relay IoT
    • 2.1.3 - Basic Linear Axis IoT
    • 2.1.4 - Basic Cooling System IoT
    • 2.1.5 - Basic Schunk Gripper IoT

2.2 - Example IoT Projects Software
    • 2.2.1 - Wait for User Button (WIP)
    • 2.2.2 - Python CRC CMD
    • 2.2.3 - Python SQL Pull (WIP)
    • 2.2.4 - Python SQL Pull Sequence (WIP)
    • 2.2.5 - Python GUI Example (WIP)

3 - General
    • FAQ (WIP)
    • Helpful Links (WIP)

Internal Wiki

Robots in Architecture Research logo
Stay in the Loop

Get updates on robotics software developments, conferences, upcoming workshops and the latest updates in parametric controls.

Newsletter
Contact Us

Impressum | Privacy

KUKA|prc Terms & Conditions

external links are marked with the symbol ↵

© 2022 All rights reserved. | 1 Day Website by Bizzy Bizzy
Protected: 0.0 – Setup – Setup Intro
Scroll to top

This site uses cookies. By continuing to browse the site, you are agreeing to our use of cookies.

OKLearn more×

Cookie and Privacy Settings



How we use cookies

We may request cookies to be set on your device. We use cookies to let us know when you visit our websites, how you interact with us, to enrich your user experience, and to customize your relationship with our website.

Click on the different category headings to find out more. You can also change some of your preferences. Note that blocking some types of cookies may impact your experience on our websites and the services we are able to offer.

Essential Website Cookies

These cookies are strictly necessary to provide you with services available through our website and to use some of its features.

Because these cookies are strictly necessary to deliver the website, refusing them will have impact how our site functions. You always can block or delete cookies by changing your browser settings and force blocking all cookies on this website. But this will always prompt you to accept/refuse cookies when revisiting our site.

We fully respect if you want to refuse cookies but to avoid asking you again and again kindly allow us to store a cookie for that. You are free to opt out any time or opt in for other cookies to get a better experience. If you refuse cookies we will remove all set cookies in our domain.

We provide you with a list of stored cookies on your computer in our domain so you can check what we stored. Due to security reasons we are not able to show or modify cookies from other domains. You can check these in your browser security settings.

Google Analytics Cookies

These cookies collect information that is used either in aggregate form to help us understand how our website is being used or how effective our marketing campaigns are, or to help us customize our website and application for you in order to enhance your experience.

If you do not want that we track your visit to our site you can disable tracking in your browser here:

Other external services

We also use different external services like Google Webfonts, Google Maps, and external Video providers. Since these providers may collect personal data like your IP address we allow you to block them here. Please be aware that this might heavily reduce the functionality and appearance of our site. Changes will take effect once you reload the page.

Google Webfont Settings:

Google Map Settings:

Google reCaptcha Settings:

Vimeo and Youtube video embeds:

Other cookies

The following cookies are also needed - You can choose if you want to allow them:

Privacy Policy

You can read about our cookies and privacy settings in detail on our Privacy Policy Page.

Privacy
Accept settingsHide notification only

Stay in the Loop

Get updates on robotics software developments, conferences, upcoming workshops, latest updates in parametric controls.

This field is for validation purposes and should be left unchanged.