Introduction: Arduino CommandLine

Picture of Arduino CommandLine

This instructable shows how to use serial monitor like terminal or command-line to control the Arduino. Serial monitor can be replaced with any program that can communicate using usb, bluetooth or any other technology over serial port. The sketch in this instructable can control multiple modules as shown in second image, but for simplicity, let's stick to simple LED. Example for Ultrasonic sensor HC-SR04 can be found at the end.

Step 1: Requirements

Picture of Requirements
  • Arduino Uno or Nano (Tested with only these two)
  • Arduino IDE.
  • USB cable for connecting Arduino to computer or laptop.
  • 5mm LED

Step 2: Code

Download the code from https://github.com/vikas-jha/Sermonics/blob/master/v0.1/sermonics.ino and upload it to Arduino.

Step 3: Connection

  • Connect positive of LED (longer pin) to any of the GPIO pins of Arduino (D03 to D13 or A0 to A5/A7). Let's connect it to D6. (Connect to PWM output pin of Arduino)
  • Connect negative of LED (shorter pin) to GND of Arduino.

Step 4: Commands

Picture of Commands

    Open serial monitor, make sure that 9600 baud rate is selected and type (bold-italics text including semi-colons and it is case-insensitive but space sensitive.)

    • Set pin D06 in output mode
      • spm d06 1;
    • To turn ON the LED
      • sdv d06 1;
    • Now LED should be turned on. To turn OFF the LED type following:
      • sdv d06 0;
    • Type following to turn on led for 5 seconds
      • sdv d06 1; dly 5000; sdv d06 0;
    • To light LED dimly
      • sav d06 100;
    • To again turn off
      • sav d06 0;

    Step 5: Thank You

    Thank you for reading.

    Let me know

    • If you want any related information.
    • If you find this useful.
    • If you have any suggestion.

    Edit: Control the HC-SR04 Ultrasonic Sensor using the same sketch,

    Connect, Vcc to 5v, GND to GND, Trig pin to D5 and Echo pin to D4.

    Type following commands

    • To prepare the Arduino
      • SPM D05 1; SPM D04 0; SDV D05 0;
    • To get the distance data
      • SDV D05 1;DLU 10; SDV D05 0; GPI D04;

    This will return the length of pulseIn like GPI D04 = like GPI D04 = 3134. Multiplying the value by 0.017 will give the distance in centimeters i.e. 3134 * 0.017 = 53 (approx).

    More examples at https://github.com/vikas-jha/Sermonics/tree/master/v0.1/examples

    Comments

    TheThinker (author)2017-07-02

    Great idea!

    Vikas KumarJ (author)TheThinker2017-07-03

    Thanks

    About This Instructable

    206views

    7favorites

    License:

    More by Vikas KumarJ:Arduino CommandLine
    Add instructable to: