Jesus Soriano
Published

Motorbike Telemetry System | Arduino Nano 33 IoT

Using an Arduino Nano 33 IoT combined with a GPS module and a battery enable motorbike riders to monitor and track their behavior on track.

IntermediateFull instructions providedOver 2 days4,606
Motorbike Telemetry System | Arduino Nano 33 IoT

Things used in this project

Story

Read more

Schematics

Telemetry System Schematic

Micro SD Adapter:

MOSI - D11

MISO - D12

SCK - D13

CS - D9

GPS Module:

TX - D0

RX - D1

Code

Arduino Cloud | Telemetry System | Main

Arduino
#include "arduino_secrets.h"
#include "TinyGPS++.h"
#include "thingProperties.h"
#include <Arduino_LSM6DS3.h>
TinyGPSPlus gps;


void setup() {
  // Initialize serial and wait for port to open:
  
  Serial1.begin(9600);
  

  if (!IMU.begin()) {
    

    while (1);
  }

 
  // This delay gives the chance to wait for a Serial Monitor without blocking if none is found
  delay(1500); 

  // Defined in thingProperties.h
  initProperties();

  // Connect to Arduino IoT Cloud
  ArduinoCloud.begin(ArduinoIoTPreferredConnection);
  
  /*
     The following function allows you to obtain more information
     related to the state of network and IoT Cloud connection and errors
     the higher number the more granular information you’ll get.
     The default is 0 (only errors).
     Maximum is 4
 */
  setDebugMessageLevel(2);
  ArduinoCloud.printDebugInfo();
}

void loop() {
  
  ArduinoCloud.update();
  // Your code here 
  float x, x1, y, y1,z;

    
     gps.encode(Serial1.read());
  
    float lat= (gps.location.lat());
    float lng= (gps.location.lng());
    float speedi=(gps.speed.kmph());
     velocidad=speedi;
     loc=Location(lat, lng);
     
      
      
      
  
  
      
  
      

   
    IMU.readAcceleration(x, y, z);
  x1= RAD_TO_DEG * (atan2(-y, -z)+PI);
  if(x1>180)
    inclinacion=x1-360;
  else
    inclinacion=x1;
    
  y1= RAD_TO_DEG * (atan2(-x, -z)+PI);
    if(y1>180)
  roll=y1-360;
  else
    roll=y1;
  
  
  

  
    
  
  delay(50);
  

  
}

Arduino Cloud | Telemetry System | arduino_secrets.h

Arduino
#define SECRET_SSID "YOUR-SSID"
#define SECRET_PASS "YOUR-PASS"

Arduino Cloud | Telemetry System | thingProperties.h

Arduino
#include <ArduinoIoTCloud.h>
#include <Arduino_ConnectionHandler.h>


const char THING_ID[] = "YOUR-ARDUINO-ID";

const char SSID[]     = SECRET_SSID;    // Network SSID (name)
const char PASS[]     = SECRET_PASS;    // Network password (use for WPA, or use as key for WEP)


int inclinacion;
CloudLocation loc;
int roll;
float velocidad;

void initProperties(){

  ArduinoCloud.setThingId(THING_ID);
  ArduinoCloud.addProperty(inclinacion, READ, ON_CHANGE, NULL);
  ArduinoCloud.addProperty(loc, READ, ON_CHANGE, NULL);
  ArduinoCloud.addProperty(roll, READ, ON_CHANGE, NULL);
  ArduinoCloud.addProperty(velocidad, READ, ON_CHANGE, NULL);

}

WiFiConnectionHandler ArduinoIoTPreferredConnection(SSID, PASS);

Micro SD Storage | Telemetry System | Main

Arduino
#include "TinyGPS++.h"
#include <Arduino_LSM6DS3.h>
#include <SD.h>
 
File logFile;
TinyGPSPlus gps;


void setup() {
  // Initialize serial and wait for port to open:
  Serial.begin(9600);
  Serial1.begin(9600);
  SD.begin(9);
  
  
  if (!IMU.begin()) {
    

    while (1);
  }

 
  // This delay gives the chance to wait for a Serial Monitor without blocking if none is found
  delay(1500); 


void loop() {
  
  


    float x, x1, y, y1,z;
    float lati,lngi,speedi;
    
     gps.encode(Serial1.read());
  
     lati= (gps.location.lat());
     lngi= (gps.location.lng());
     speedi=(gps.speed.kmph());
     velocidad=speedi;
     loc=Location(lati, lngi);
    
  
      
  
      

   
    IMU.readAcceleration(x, y, z);
  x1= RAD_TO_DEG * (atan2(-y, -z)+PI);
  if(x1>180)
    inclinacion=x1-360;
  else
    inclinacion=x1;
    
  y1= RAD_TO_DEG * (atan2(-x, -z)+PI);
    if(y1>180)
  roll=y1-360;
  else
    roll=y1;





  logFile = SD.open("datalog.txt", FILE_WRITE);
    if (logFile) { 
        
        
        logFile.print(millis());
        logFile.print("; ");
        logFile.print(inclinacion);
        logFile.print("; ");
        logFile.print(roll);
        logFile.print("; ");
        logFile.print(velocidad);
        logFile.print("; ");
        logFile.print(lati);
        logFile.print(",");
        logFile.print(lngi);
       
        logFile.println();
        
        
        logFile.close();
  
  
  
    }
  
    
  
  delay(200);
    

  
}

Credits

Jesus Soriano

Jesus Soriano

3 projects • 11 followers

Comments