• Six easy ways to connect Arduino to Android. Possibility of connecting Wi-Fi module esp8266 to arduino

    Machine on arduino and Bluetooth without code editing. We will use a specialized free software to create a sketch. In addition, there is no need to buy a chassis for our craft; almost any faulty one will do. radio controlled model car or tank.

    I suggest watching an overview video about the Bluetooth-controlled machine and its contents.

    So, let's look at a live example of how to make a remote control via bluetooth c with your own hands. android tablet or a smartphone typewriter. The article, oddly enough, is intended for entry level knowledge. There is no guide to editing the code in Arduino IDE, and we will only use it to fill our code. And we will compose the control algorithm in a program called FLProg. Control program from a smartphone - HmiKaskada_free. But first, about the hardware we need.

    Machine on arduino and Bluetooth - hardware.

    The first thing you need is chassis, that is, a body with wheels and motors, which will drive for the joy of us and those around us. In my case, I used a case from a radio-controlled toy in which the power part burned out. The prospect of renovation seemed dull to me, and I wanted something new for my children. That's how this project was born. The body contains two engines that drive the wheels on the sides of the machine, like a tank. All electronic components were sent for spare parts.

    To control the electric motors of our future creation we will need H-bridge on L298N chip Link to Ali, I took this one from. The picture is clickable.

    H-bridge for arduino

    Can control two motors in the voltage range 5 - 35 volts. Supports PWM, that is, you can adjust the engine speed. The board has a stabilized voltage output of 5 volts to power the Arduino.

    The connection diagram is simple and unpretentious:

    The next integral part of the electronic filling of our project is bluetooth module HC-06. The most common module for Arduino, it is so popular that it does not need any additional description.

    HC-06 bluetooth for arduino

    The main element and brain in my case is arduino nano, I won’t even post a photo here because everyone knows about it and knows how to work with it. By the way, any Arduino board will do, as long as it fits in the case 😀

    Batteries and soldering wires do not require specification. The choice of batteries depends on the operating voltage of the electric motors.

    Machine on arduino and Bluetooth - drawing up a sketch.

    I repeat - there will be no digging in the code here. We will use popular program FLProg. Download it latest version can be found on the official website. The program's interface is simple and unpretentious, but it has enormous functionality and support for almost all popular modules. I won’t write how to use it because it would take a couple of articles. Let me just say that I have never met a more convenient and available program for making sketches for arduino and its clones. Interface screen:

    FLProg interface

    The site is full of text and video manuals, I think you’ll figure it out.

    My project for a remote-controlled car can be downloaded from Yandex disk via the link shortening service.

    Machine on arduino and Bluetooth - control interface on an Android tablet.

    Due to numerous requests, I wrote detailed instructions for developing a control interface based on HmiKaskada android in the article. The link is clickable.

    For devices under android control there is a program HmiKaskada (link to YandexDisk). It was initially developed as an alternative to expensive industrial HMI panels. But inquisitive minds quickly realized that she could control anything. In our case, a typewriter. It supports Wi-Fi and Bluetooth wireless interfaces, and you can also connect the device directly via USB.

    There are paid and free versions of the program. I have both, but I basically made the project in the free version to show you and once again make sure it works absolutely free versions. The main difference between free and PRO versions This works only via bluetooth.

    There is a giant thread on the FLProg forum regarding compatibility with KaScada, and the developer is active and sociable. I don’t see any point in posting a screenshot of the control panel - it’s in the video.

    Ever thought about managing any electronic devices using a smartphone? Agree, it would be very cool to control a robot or any other devices from your smartphone. We offer a simple lesson for beginners and dummies on how to using Arduino Control your smartphone via Bluetooth. If after this lesson you want to get to know Arduino better, you can find books about it.

    Devices

    Module - Bluetooth Module HC 05/06
    Board - Arduino
    Light Emitting Diode (LED)
    Resistor - 220Ω
    Android device

    Software

    Arduino IDE
    Android Studio(actually not necessary, because you will find the Android application below)

    Step 2. How it works

    Usually we do this step at the end, but so that you understand what we have to achieve, look at the result at this intermediate step. We have also published a step-by-step video tutorial below.

    Step 3. We begin to assemble the circuit

    The circuit in our tutorial is so simple and small that we only need to make a few connections:

    Arduino Pins___________Bluetooth Module Pins
    RX (Pin 0)___________________________TX
    TX (Pin 1)___________________________RX
    5V__________________________VCC
    GND_______________________GND

    Connect the negative of the LED to GND on the Arduino, and the positive to pin 13 through a resistance of 220 Ohm - 1 kOhm. In general, in our figure below everything is quite clear.

    Do not connect RX to RX and TX to TX Bluetooth outputs to Arduino outputs, you will not receive any data, here TX means transmit, RX means receive.

    Now we need to write a program and upload it to our Arduino. If you don’t know how to do this yet, download books. The code below is exactly what we need to load into the Arduino.

    /* Bluetooh Basic: LED ON OFF * Coder - Mayoogh Girish * Website - http://bit.do/Avishkar * Download the App: https://github.com/Mayoogh/Arduino-Bluetooth-Basic * This program lets you to control a LED on pin 13 of arduino using a bluetooth module */ char data = 0; //Variable for storing received data void setup() ( Serial.begin(9600); //Sets the baud for serial data transmission pinMode(13, OUTPUT); //Sets digital pin 13 as output pin ) void loop() ( if(Serial.available() > 0) // Send data only when you receive data: ( data = Serial.read(); //Read the incoming data and store it into variable data Serial.print(data); // Print Value inside data in Serial monitor Serial.print("\n"); //New line if(data == "1") // Checks whether value of data is equal to 1 digitalWrite(13, HIGH); If value is 1 then LED turns ON else if(data == "0") // Checks whether value of data is equal to 0 digitalWrite(13, LOW); //If value is 0 then LED turns OFF ) )

    Step 5. How the process works

    The HC 05/06 module operates via a serial communication channel. The Android application sequentially sends data to bluetooth module when you press a specific key. The Bluetooth on the other end receives the data and sends it to the Arduino via the Bluetooth module's TX connection (Arduino RX connection).

    The code loaded into the Arduino checks the received data and compares it. If a "1" is received, the LED turns on and turns off when a "0" is received. Open your monitor serial port and observe the data obtained.

    Step 6. Application for Android devices

    In this tutorial we will not touch on creating applications for Android devices. You can download the application on GitHub.

    How to use the application?

    After we have connected via Bluetooth, we need to download and install an application that, using a smartphone :) will control our LED from a distance. You can download the application for free on Amazon.com. We connect the smartphone to the Bluetooth module HC 05/06:

    1. Turn on the HC 05/0 module
    2. Looking for a device
    3. We connect to HC 05/06 by entering the default password “1234” or “0000” (four zeros).

    After that we install the application on our smartphone. Let's open it. Select a device - select the Bluetooth module from the list (HC 05/06). After successful connection, press the ON button to turn on the LED and the OFF button to turn off the LED. Then you can click the “Disconnect” button to disconnect from the Bluetooth module.

    This was a guide for dummies and beginners on how to connect a Bluetooth module with Arduino. This project can be improved and raised to more high level for, for example, home automation through smartphone control, controlled robot and much more.

    Arduino boards and similar microcontrollers make creativity more accessible than ever, they write. Regardless of the purpose of use - to automate your home or control LED strips, or even to protect your property, these amazing little technical devices are the core of most DIY electronic devices.

    If you need to command your Arduino to change the position of the pin jumpers (for example, turn on the light), then the Arduino will require the user to press physical button or use a sensor. For many projects, using human finger pressure or similar methods to control devices is fine, but what should you do if you just wanted to build a circuit that could be remotely accessed?

    This article gives brief description six ways to connect your Android device to any compatible Arduino board.

    1. ArduinoDroid allows you to create sketches

    The first device on our list is ArduinoDroid. This app works via USB On The Go (OTG) connecting your mobile device from Arduino via USB cable. One of benefits of USB cable means there is no need to connect to the Internet or Bluetooth for the device to function.

    The application is a full-featured IDE that allows the user to write code on a smartphone, download previously written sketches that are stored in Dropbox or Google drive and then begin the compilation process.

    The benefits of using the ArduinoDroid app are obvious. Having an IDE at your fingertips allows you to quickly make changes to fields, and the process of attaching an Android device is less complicated and time-consuming than trying to balance a bulky laptop in your arms!

    The obvious disadvantage of the ArduinoDroid application is that writing code on your device may not be a very comfortable experience, especially if you use a smartphone for this purpose. At the same time, this weak point of the application is not so pronounced when on one side of the scale is the convenience of having an ultra-portable method of programming on your board at hand without the need for an Internet connection, and on the other side of the scale is the not very comfortable method of writing code .

    On the other hand, having an ArduinoDroid is an inexpensive way to learn Arduino basics, because clone Arduino boards and USB On The Go cost a few dollars. For those who rarely have access to a computer, the ArduinoDroid app is a great alternative!

    2. Arduino Bluetooth Controller

    The next program on our list is the aptly named Arduino Bluetooth Controller. This application is of greater significance in relation to triggers for changes in uploaded sketches, and less significance for Arduino programming. Arduino controller Bluetooth sends data to your board via Bluetooth, giving you the ability to send serial data with the press of a button. You will need bluetooth module for your board, although the module HC-06 widely used and available for as little as $3.

    Worth mentioning is the fact that the program is loaded on English, although in the pictures Play Store Italian language is specified!

    3. Blynk application for developing projects

    The Blynk application is an excellent development for creating projects. The application's flexibility and simplicity provide an intuitive approach to triggering events on your board. Working with Blynk requires an Internet connection, as the application uses its own own server. You can use either Wi-Fi or mobile data to access the Blynk app, and this feature works great on smartphones.

    One of the strongest points of the application is the variability of connections to the device. With support for almost all development boards, you can connect to the server wirelessly, or using ethernet and even a computer via USB. The service is well documented, and its intuitive application makes it easy to integrate customized control over your project. The Blynk library for the Arduino IDE monitors all communications.

    If you prefer to turn on your coffee machine using your smartphone before getting out of bed early in the morning, this app is truly for you!

    Blynk is not the only service in this category. It is also worth paying attention to such an extremely customized service as Thinger.io and the almost unlimited, albeit extremely difficult OpenHAB. Of the three services, Blynk is the fastest to get up and running, although learning OpenHAB is a great idea in the long run.

    4. Communication from scratch

    The applications described above assume the use of already existing services, which assist you in providing various connection options. What steps do you need to take to have complete and total control over every aspect of your Android apps? Why don't you solve this issue yourself and from scratch?

    The problem of maintaining control over a package of applications is solved simply by opening USB connection and back-and-forth serial data transfer between applications and the Arduino board. This control option is one of the best for getting started with Android Studio and app creation in general.

    It should be noted that if there are methods and methods for creating applications for devices on the Android platform without code, learning the basics of coding is also worth attention software in Java.

    5. Turn your Arduino into a server

    An alternative way to communicate with your board is to turn it into a tiny server. Key Advantage This transformation of the board into a server is the emergence of the ability to communicate with the boards from any device that can navigate by IP address or send a web request. This will require attachment Ethernet shield to your board to your home network.

    If you don't have an Ethernet shield , then a similar effect can be achieved through a Wi-Fi shield or through a board connected to Wi-Fi, like NodeMCU.

    If node.js code is your jam, it might make sense to take a look at the arduino-android github project. Once again, we repeat that Android applications are developed based on open source, and all you need to do is install the node.js server on the Arduino board of your choice.

    6. Infrared control

    If you are looking for a universal communication tool with your Arduino or you would like to play the role of the legendary secret agent MacGyver, then remove infrared receiver(IT) from your old stereo or VHS player and use it to communicate with your Arduino board!

    AND HTC Desire with firmware cyanogen 7.1.0 RC1 (Android 2.3.4). Just in case, let me remind you that everything that will be described below only works starting from Android 2.3.4 for phones and Android 3.1 for tablets.

    It is worth noting here that this USB Host Shield is not entirely successful, especially in combination with Arduino Mega 2560. The first problem was that this expansion board was made for Arduino UNO, and it differs from Mega in the positions of the SPI contacts, so I had to add jumpers (see photo). The second problem, although quite expected, was the need for an external power source to operate this expansion card. USB Host Shield 2.0 from Circuits@Home is considered more successful, but it is also more expensive.

    Board with interconnected SPI contacts

    Setting up Arduino software

    1. If not already installed, then download and install software for Arduino.
    2. Download and unpack the ADK package (contains the DemoKit application). The app, firmware, and hardware folders should appear.
    3. Download the CapSense library
    4. Copy firmware/arduino_libs/AndroidAccessory and firmware/arduino_libs/USB_Host_Shield to /libraries/ .
    5. Create a CapSense directory in /libraries/ and copy CapSense.cpp and CapSense.h from the CapSense archive into it.

    Firmware download

    Google kindly provides its DemoKit sketch for Arduino. All you need to do is open it from firmware/demokit/demokit.pde, compile it and upload it to the board.

    Test Android application

    The DemoKit package also contains the sources of the Android application to demonstrate the capabilities. Google invites us to create an Android project ourselves and assemble this application. First, we will need to install API Level 10. Then everything is simple - we create an Android project and specify the path to the app folder, in the Build Target we specify Google APIs (Platform 2.3.3 , API Level 10). We assemble the application and install it on the phone. Those who don’t want to bother with the assembly can download the ready-made APK.

    Launch

    We simply connect our phone to the USB Host Shield. If we did everything correctly, a request to launch the DemoKit application will appear on the screen.

    The application itself contains two tabs - In (buttons, joystick and sensors) and Out (LEDs, relays and servos).

    I decided that a couple of LEDs and a button were enough for the demonstration. You can see how this miracle works in the video.

    Some code

    In this example, messages transmitted via USB consist of three bytes:
    The 1st byte defines a command or device group, for example LEDs - 0x2
    2nd byte indicates specific device, for example green LED - 0x1
    The 3rd byte contains the value passed to the device, for example maximum brightness - 0xff

    Arduino

    ... /* initialization */ AndroidAccessory acc("Google, Inc.", "DemoKit", "DemoKit Arduino Board", "1.0", "http://www.android.com", "0000000012345678"); void setup() ( .... acc.powerOn(); ) void loop() ( byte msg; /* check connection */ if (acc.isConnected()) ( /* receive message from Android device */ int len = acc.read(msg, sizeof(msg), 1); if (len > 0) ( /* message for LEDs */ if (msg == 0x2) ( if (msg == 0x0) analogWrite(LED3_RED, msg) ; else if (msg == 0x1) analogWrite(LED3_GREEN, msg); else if (msg == 0x2) analogWrite(LED3_BLUE, msg) ) msg ​​= 0x1; ) ( msg = 0; msg = b ? 1: 0; /* send button state */ acc.write(msg, 3); b1 = b; ) ) )

    Android

    import com.android.future.usb.UsbAccessory; import com.android.future.usb.UsbManager; ... Public Class Demokitactivity Extitions Implements Runnable (Private USBManager Musbmanager; USBACCESSORY MACCCESSORY; FileinPutstream MinPuSTREAM; Utputstream; ... Private Void Openaccessory (USBACCESSORY) ) ( mAccessory = accessory; FileDescriptor fd = mFileDescriptor.getFileDescriptor(); mInputStream = new FileInputStream(fd); mOutputStream = new FileOutputStream(fd); Thread thread = new Thread(null, this, "AccessoryThread"); thread.start( ); ) ) public void run() ( int ret = 0; byte buffer = new byte; int i; while (ret >= 0) ( // receiving incoming messages ret = mInputStream.read(buffer); i = 0; while(i< ret) { int len = ret - i; switch (buffer[i]) { case 0x1: // сообщение от кнопки if (len >= 3) ( Message m = Message.obtain(mHandler, MESSAGE_SWITCH); m.obj = new SwitchMsg(buffer, buffer); mHandler.sendMessage(m); ) i += 3; break; ) ) ) ) // example of use - turn on the red LED at full brightness: // mActivity.sendCommand((byte)2, (byte)0, (byte)255) public void sendCommand(byte command, byte target, int value) ( byte buffer = new byte; if (value > 255) value = 255; buffer = command; buffer = target; buffer = (byte) value; if (mOutputStream != null && buffer != -1) ( try ( mOutputStream. write(buffer) catch (IOException e) ( ... ) ) ) )

    Conclusions

    Opening such Google features first of all, of course, he hopes for the appearance of a large number of active Android accessories, but not least of all is the fact that in essence we get a convenient device for interacting with various sensors, sensors and actuators. Such a device could easily become the brain of something robotic.

    Also, we must not forget that Android device for Arduino can act as an expansion board that has GPS, Bluetooth, WiFi, accelerometer and much more.

    With Wi-Fi module.

    On Arduino Uno WiFi is provided for everything comfortable work with microcontroller: 14 digital inputs/outputs (6 of them can be used as PWM outputs), 6 analog inputs, USB connector, power connector, ICSP connector and microcontroller reset button.

    The highlight of the board is the ESP8266 WiFi module, which allows Arduino to exchange information with other modules via wireless networks 802.11 b/g/n standards.

    ESP8266 allows you to flash an Arduino board without using a USB cable in OTA (Firmware Over The Air) mode.

    Video review of the board

    Connection and setup

    To get started with the Arduino Uno WiFi board, operating system Windows download and install the integrated environment on your computer Arduino development- Arduino IDE.

    Did something go wrong?

    Setting up the WiFi module

    Arduino firmware via WiFi

    Arduino Uno WiFi has one more in stock nice bonus- the ability to upload sketches without using a USB cable in OTA (Firmware Over The Air) mode. Let's take a closer look at how to do this.


    To do this you need to enter the menu: Tools Port and select the desired port.

    Since we are flashing Arduino via WiFi, the board will be determined as remote device with IP address

    The environment is configured, the board is connected. You can proceed to uploading the sketch. Arduino IDE contains a large list of ready-made examples in which you can see the solution to any problem. Let's choose among the examples of LED blinking - the “Blink” sketch.
    Flash the board by clicking on the program download icon.
    After booting, the LED will start blinking once per second. This means that everything worked out.

    Now you can move on to examples of use.

    Examples of use

    Web server

    Let's set up a simple web server that will display a page with the current values ​​of the analog inputs.

    web-server.ino /* An example of a simple web server running on Arduino Uno WiFi. The server displays the values ​​on the analog inputs and updates the information every two seconds. Contact the server at http:// /arduino/webserver/ Please note: the example only works with the Arduino Uno WiFi Developer Edition. */#include #include void setup() ( Wifi.begin () ; Wifi.println ( "Web Server is up" ) ; // Display a message about the server start in the wifi console) void loop() ( while (Wifi.available () ) ( process(Wifi) ; ) delay(50 ) ; ) void process(WifiData client) ( String command = client.readStringUntil ("/" ) ; if (command = = "webserver" ) ( WebServer(client) ; ) ) void WebServer(WifiData client) ( client.println("HTTP/1.1 200 OK" ) ; client.println("Content-Type: text/html" ) ; client. println ("Connection: close" ) ; client.println ( "Refresh: 2" ) ; // Header that specifies the page refresh period in seconds client.println(); client.println(" " ) ; // Form the page client.println( " UNO WIFI Web-server " ) ; client.print( "

    Example of outputting values ​​from analog pins

    "
    ) ; client.print("
      " ); for (int analogChannel = 0 ; analogChannel< 4 ; analogChannel++ ) { int sensorReading = analogRead(analogChannel) ; client.print ("
    • on the analog input") ; client.print(analogChannel) ; client.print(": " ) ; client.print (sensorReading) ; client.print ("
    • " ) ; ) client.println ( "
    " ) ; client.print (DELIMITER) ; // Don't forget to close the connection! }

    Board elements

    Microcontroller ATmega328P

    The heart of the Arduino Uno WiFi platform is the 8-bit microcontroller of the AVR family - ATmega328P.

    Microcontroller ATmega16U2

    The ATmega16U2 microcontroller provides communication between the ATmega328P microcontroller and the computer's USB port. When connected to a PC, the Arduino Uno WiFi is detected as a virtual COM port. The 16U2 chip's firmware uses standard USB-COM drivers, so no external driver installation is required.

    Power pins

      VIN: Voltage from external power supply (not related to 5V from USB or other regulated voltage). Through this pin you can both supply external power and consume current if an external adapter is connected to the device.

      5V: The pin receives a voltage of 5 V from the board's stabilizer. This stabilizer provides power to the ATmega328 microcontroller. It is not recommended to power the device through the 5V pin - in this case, a voltage stabilizer is not used, which can lead to board failure.

      3.3V: 3.3 V from the board stabilizer. The maximum output current is 1 A.

      GND: Conclusions of the earth.

      IOREF: The pin provides expansion boards with information about the operating voltage of the microcontroller. Depending on the voltage, the expansion board can switch to the appropriate power supply or use level converters, allowing it to work with both 5V and 3.3V devices.

    I/O Ports

      Digital inputs/outputs: pins 0 – 13
      The logical level of one is 5 V, zero is 0 V. The maximum output current is 40 mA. Pull-up resistors are connected to the contacts, which are disabled by default, but can be enabled by software.

      PWM: pins 3, 5, 6, 9, 10 and 11
      Allows you to output 8-bit analog values ​​as a PWM signal.

      ADC: pins A0 – A5
      6 analog inputs, each of which can represent analog voltage as a 10-bit number (1024 values). The ADC capacity is 10 bits.

      TWI/I²C: SDA and SCL pins
      For communication with peripherals using a synchronous protocol, via 2 wires. For work - use Wire library.

      SPI: pins 10(SS), 11(MOSI), 12(MISO), 13(SCK).
      Communication via the SPI interface is carried out through these pins. To work, use the SPI library.

      UART: pins 0(RX) and 1(TX)
      These pins are connected to the corresponding pins of the ATmega16U2 microcontroller, which acts as a USB-UART converter. Used to communicate between the Arduino board and a computer or other devices via the Serial class.

    LED indication

    USB Type-B connector

    The USB Type-B connector is designed for flashing the Arduino Uno WiFi platform using a computer.

    External power connector

    Connector for connecting external power from 7 V to 12 V.

    5V voltage regulator

    When the board is connected to external source power supply, the voltage passes through the MPM3610 stabilizer. The stabilizer output is connected to the 5V pin. The maximum output current is 1A.

    3.3V voltage regulator

    MPM3810GQB-33 stabilizer with 3.3 volt output. Provides nutrition WiFi module ESP8266 and connected to the 3.3V pin. The maximum output current is 1A.

    ICSP connector for ATmega328P

    The ICSP connector is designed for in-circuit programming of the ATmega328P microcontroller. Using the SPI library, these pins can communicate with expansion boards via the SPI interface. The SPI lines are routed to a 6-pin connector, and are also duplicated on digital pins 10(SS), 11(MOSI), 12(MISO) and 13(SCK).

    ICSP connector for ATmega16U2

    The ICSP connector is designed for in-circuit programming of the ATmega16U2 microcontroller.