Push Data from GY61 on Arduino Uno via USB

Hi,
I’m trying to display push data from a GY 61 accelerometer on an Arduino Uno board to Blynk (android version) via USB onto a super chart and value display widget. So far, the time that I have been online is being displayed in seconds on my widgets and not any values from the x, y or z axis.
I’m trying to display the movement of the accelerometer onto the widgets on Blynk…

#define BLYNK_PRINT SwSerial


#include <SoftwareSerial.h>
SoftwareSerial SwSerial(10, 11); // RX, TX
    
#include <BlynkSimpleStream.h>

// You should get Auth Token in the Blynk App.
// Go to the Project Settings (nut icon).
char auth[] = "xxxxxxxxxxxxxxxxxxxxxxx";

BlynkTimer timer;

// This function sends Arduino's up time every second to Virtual Pin (5).
// In the app, Widget's reading frequency should be set to PUSH. This means
// that you define how often to send data to Blynk App.
void myTimerEvent()
{
  // You can send any value at any time.
  // Please don't send more that 10 values per second.
  Blynk.virtualWrite(V5, millis() / 1000);
}

/*
ADXL335
note:vcc-->5v ,but ADXL335 Vs is 3.3V
The circuit:
      5V: VCC
analog 1: x-axis
analog 2: y-axis
analog 3: z-axis
*/
const int xpin = 1;                  // x-axis of the accelerometer
const int ypin = 2;                  // y-axis
const int zpin = 3;                  // z-axis (only on 3-axis models)


void setup()
{
  // Debug console
  SwSerial.begin(9600);

  // Blynk will work through Serial
  // Do not read or write this serial manually in your sketch
  Serial.begin(9600);
  Blynk.begin(Serial, auth);

  // Setup a function to be called every second
  timer.setInterval(1000L, myTimerEvent);
}

void loop()
{

 int x = analogRead(xpin);  //read from xpin
 
 int y = analogRead(ypin);  //read from ypin
 
 int z = analogRead(zpin);  //read from zpin
 
float zero_G = 512.0; //ADC is 0~1023  the zero g output equal to Vs/2
                      //ADXL335 power supply by Vs 3.3V
float scale = 102.3;  //ADXL335330 Sensitivity is 330mv/g
                       //330 * 1024/3.3/1000  

/*Serial.print(x); 
Serial.print("\t");
Serial.print(y);
Serial.print("\t");
Serial.print(z);  
Serial.print("\n");*/
/*Serial.print(((float)x - 331.5)/65*9.8);  //print x value on serial monitor
Serial.print("\t");
Serial.print(((float)y - 329.5)/68.5*9.8);  //print y value on serial monitor
Serial.print("\t");
Serial.print(((float)z - 340)/68*9.8);  //print z value on serial monitor*/
int v = sqrt((sq(x))+(sq(y))+(sq(z)));
//int val = analogRead(x);
//val = map(val,0,1023,0,180);




  Blynk.run();
  timer.run(); // Initiates BlynkTimer
}

You only have one Blynk.virtualWrite command, which sends the current millis value (divided by 1000) to Blynk.
So, I’m assuming that you mean that these commented-out lines aren’t sending the x-y-z data to your serial monitor:

/*Serial.print(x); 
Serial.print("\t");
Serial.print(y);
Serial.print("\t");
Serial.print(z);  
Serial.print("\n");*/
/*Serial.print(((float)x - 331.5)/65*9.8);  //print x value on serial monitor
Serial.print("\t");
Serial.print(((float)y - 329.5)/68.5*9.8);  //print y value on serial monitor
Serial.print("\t");
Serial.print(((float)z - 340)/68*9.8);  //print z value on serial monitor*/

You have two serial interfaces set-up:

  • Serial - this is used for Blynk communication
  • SwSerial - this is used for debug output to your serial monitor

You’re trying to send your serial monitor data to the wrong serial port.

However, you should also read this:

Pete.

Thank you, you have been a great help :slight_smile: