Home Python and Arduino via Smartphones
Post
Cancel

Python and Arduino via Smartphones

Summary

Run python code on a smartphone to see LED turn on.

DEMO

Motivation

  • Wirelessly run python programs that control Arduino
  • Control android without rooting
  • Access sensors available in smartphone i.e. camera, GPS

Usage

Follow Setup instructions then run the following on python ssh terminal to control LED.

1
2
tn.write('1'.encode('ascii')) # on
tn.write('0'.encode('ascii')) # off

Requirements

Hardware
  1. Android phone (tested on 7.0 and 8.1)
  2. Arduino UNO
  3. LED
  4. USB Cable Type A/B
  5. OTG cable USB to micro-USB
Software
  1. Arduino IDE
  2. Termux (F-Droid version)
  3. Server Bridge X

Setup

All code is available on github

  1. On the PC, install Arduino IDE.
  2. Connect Arduino UNO to PC using USB Cable Type A/B.
  3. Upload sketch.ino to your Ardunio board using the Upload button in the Arduino IDE.

  4. On the android smartphone, install Server Bridge X and Termux via F-Droid marketplace.
  5. Open Android app Server Bridge X.
  6. Attach OTG cable USB to micro-USB to Arduino. Press ‘ok’ when asked to Allow the app ServerBridgeX to access the USB device.
  7. Press play in Server Bridge X.

  8. Open Android app Termux.
  9. Connect smartphone to same network as PC.
  10. On Termux, install SSH tools and python via commands in script.sh.
  11. On the PC command line, access the smartphone terminal using SSH.

  12. On PC command line, run Python.
  13. On Python, run send.py commands. LED should turn on/off based on the command sent (1 or 0).

References

This post is licensed under CC BY 4.0 by the author.