analogRead plot in RoboRemo

Plot a signal from Arduino analog pin

analogRead plot in RoboRemo

This project is about reading an analog pin of the Arduino and plotting the value in real time using RoboRemo.

Materials needed:
- Arduino UNO (or similar) + USB cable for it
- USB OTG adapter
- breadboard
- wires
- potentiometer
- Android device with OTG support and RoboRemo app installed

Introduction

Plotting analog signal is very useful for debugging a sensor, to see if it works, find the signal variation range, check liniarity, etc. In this project I use a potentiometer for the demo, which I rotate to variate the analog output. The potentiometer cursor (middle pin / output) is connected to pin A0 of the Arduino.

Steps:

1.
Upload the code to your Arduino.

// Reading analog signal from pin A0
// and plotting the data in RoboRemo

// www.roboremo.com

// Hardware setup:
// Arduino <---USB cable --- OTG adapter ---> Tablet

// input ----- A0

// NOTE: Tablet must have USB OTG & API
//   Alternatively, you can use a HC-05 or similar
//   to connect via Bluetooth,
//   or https://github.com/roboremo/ESP8266-WiFi-UART-Bridge
//   to connect via WiFi
//   Connect it to the Arduino Serial pins 0 and 1,
//   and use DC Power adapter (NOT USB !!!)

// MAKE SURE the module uses SAME BAUDRATE as the Arduino !!!

int on = 0; // OFF

char cmd[100];
int cmdIndex;

boolean cmdStartsWith(char *st) {
  for(int i=0; ; i++) {
    if(st[i]==0) return true;
    if(cmd[i]==0) return false;
    if(cmd[i]!=st[i]) return false;;
  }
  return false;
}

void exeCmd() {
  if( cmdStartsWith("on") ) on = 1;
  if( cmdStartsWith("off") ) on = 0;
}

void setup() {
  
  delay(500); 

  Serial.begin(115200);
  
  //analogReference(INTERNAL); // 1.1V on UNO/NANO
  
  cmdIndex = 0;
}

void loop() {
  
  while(Serial.available()) {
    
    char c = (char)Serial.read();
    
    if(c=='\n') {
      cmd[cmdIndex] = 0;
      exeCmd();  // execute the command
      cmdIndex = 0; // reset the cmdIndex
    } else {      
      cmd[cmdIndex] = c;
      if(cmdIndex<99) cmdIndex++;
    }
  }
  
  if(on) {
    int val = analogRead(A0);
    String st = (String)"v " + val + "\n";
    Serial.print( st );
    delay(10);
  }
}

2.
Connect the potentiometer to the Arduino using wires and breadboard:
Potentiometer end pins - connect to GND and +5V
Potentiometer cursor (middle pin) - connect to Arduino pin A0

3.
Download the RoboRemo interface file:

analogRead-plot.interface

Copy the interface file to your Android device, then import in RoboRemo using menu -> interface -> import.

4.
Connect your Arduino to the Android device, using the OTG cable.
Open RoboRemo and connect (menu -> connect -> USB Serial -> 115200).

5.
Enjoy :)