Ozeki 10
Stepper Motors Stepper Motors | Arduino Mega Arduino Mega

How to use an Arduino switch

This guide is about to demonstrate how you can create a switch to control Arduino devices. With a switch, you can turn other devices on or off or adjust the signal level, that changes the behavior of the connected device. The guide shows you how to do that with a simple example, and provides a step by step guide also which demonstrates how you can manage the switch with your computer using Ozeki 10.

What is a switch?

By creating a switch, you will be able to control several Arduino devices with the dedicated control unit. The control unit can be a button or an analog sensor as well. By adjusting the controlling module you can change the behavior of the connected device.

How to use an Arduino switch?

To create a switch, you need two Arduino modules to be connected to the same Arduino board. In this example, a button, and an RGB LED will be wired to the Arduino Board. The way you need to wire these devices is demonstrated in the wiring diagram below (Figure 1). With the connected button, you can send a signal to the other connected device (in this case is to the RGB LED), and this will change the behavior of that module like turning it on or off.

Arduino Switch wiring diagram

wiring diagram of arduino switch
Figure 1 - Wiring diagram of Arduino Switch

How to use an Arduino switch in Ozeki

The Switch Controllers can be used to turn devices on or off. These switches can operate as a relay or they can also generate PWM signal. As a relay, it can turn devices on or off by using the ON/Off state. By using PWM signal, you will be able to adjust the signal level, for example, you can set the speed of a motor or the brightness of an RGB LED. In Ozeki 10, PWM can be adjusted in absolute numbers or as a percentage. To use the Switch in Ozeki, you first need to download Ozeki Robot Developer. Ozeki Robot Developer will install the Arduino libraries needed to use this sensor efficiently.

Download Ozeki Robot Developer

Download Ozeki Robot Developer

After Ozeki Robot developer is installed, you need to upload the Switch control code to your Arduino. You can find the code and download instructions on the following pages. The upload process includes two steps: first you need to format the EEPROM of the arduino, then you need to upload the control code. The procedure is very simple, it only takes a few seconds.

Upload the Switch code to Arduino Uno
Upload the Switch code to Arduino Mega 2560
Upload the Switch code to Arduino Nano
Upload the Switch code to Raspberry Pi
Upload the Switch code to Ozeki Relay Module

The arduino sensors and Ozeki will communicate over the USB port using the Ozeki Switch protocol. This protocol makes it possible for you to use the sensor directly on your PC. You will be able to control this sensor through the web based user interface or you will be able to communicate with it using Ozeki Chat. You can read more about chat control on the following page.

How to communicate with the Switch using chat

It is important to understand chat control, because when you build a robot, the way you wish to control this sensor is by sending and receiving messages. If you open the Ozeki Robot Developer app, you will see, who you can write a C#.Net program to work with this sensor.

Connection steps

  1. Connect the Switch to your Arduino using the wiring diagram
  2. Plug the Arduino board into the PC
  3. Check the COM ports to see if your Arduino is connected successfully
  4. Open the Arduino application on your computer
  5. Upload example code to the Arduino
  6. Type https://localhost:9515 in your browser to open Ozeki 10
  7. Choose Switch from the list of connections
  8. Press the button to test the Switch

System overview

The system we suggest consists of a button and a RGB LED, both wired to the analog port of your Arduino. The Arduino will be responsible for reading data from this device in real-time. The brain of the system will be running on a PC (Figure 2). On the PC, Ozeki 10 will be able to manage the communication. You can easily run Ozeki 10 using a webbrowser

setup switch to pc using arduino
Figure 2 - System configuration of switch connecting to PC using Arduino

Prerequisites

  • Controlled device
    • with stable digital states (e.g. Relay)
    • with PWM signals (e.g. LED with resistor)
  • Ozeki installed on a computer
  • Programmable board (Arduino Mega/Nano/Uno or Raspberry Pi)
  • USB cable is needed between Arduino Mega/Nano/Uno and computer

Step 1 - Wire the switch to your Arduino

You can see how to wire controlled device (such as Relay) to a programmable board. Please choose your board:

Step 2 - Upload code to the microcontroller

(Here is the code to upload)

The following step is to upload a code to the microcontroller that will operate on the switch. To do that, you need to open the Arduino application on your computer. Here, first you have to check the port, that the switch is properly connected to your computer. Then, you just need to go the link above, copy the code and paste it in the Arduino application. Lastly, just click on Upload in Arduino and the code will be uploaded to the microcontroller.

Step 3 - Start Ozeki 10 to try the switch

After that you connected your Arduino to your Raspberry Pi, now you can try out the switch. For that, you need to open the GUI (Graphical User Interface) of Ozeki 10. That can be done by typing localhost:9513 to your webbrowser and hit Enter. Here, Ozeki 10 automatically detects the connected devices, so once you connected the switch, you will be able to see it in the list of connections. All you have to do here, is to open the connection, and try the switch.

Step 4 - Configure the switch in Ozeki 10

To configure your switch (attached to your Arduino) in Ozeki 10, that is installed on your computer, you need to open the graphical user interface (GUI) of Ozeki 10. You can open the GUI by entering the URL of the computer into your webbrowser. For example, if our PC has an IP address of 192.168.1.5, we would enter http://192.168.1.5:9513 into our webbrowser.

Copyright © 2000- - Ozeki Ltd | info@ozeki.hu
Home > Products > Ozeki 10 > Connections > Arduino > Switch Controller
Legal | Privacy | Terms of use | 3041
18.204.229.70 | 92.118.27.157 | Login