Hey there.
We're making a project at school, and I chose a little car RX12 (a toy for kids). The goal was to study the car, its acceleration (to integer and get its maximum velocity which is told to be 28km/h) and how much time could the battery work (it is told to be 12min).
We had to use Arduino that we never really used up to now but we managed to make 3 programs : one for the acceleration sensor ADXL335, one for the acceleration sensor MMA776 and one for Current and Voltage with Phidgets 1135 for voltage and MR003-006.1 for current. In our case, we used Arduino Uno R3 and a SD Card Shield v4.1 on it.
Here are the 3 programs :
//Acceleration with ADXL335
#include <SD.h>
File Fichier;
boolean test;
int increment = 50; //Increment en ms
int xpin = 0.; // Variable numérique de l'accélération
float temps = 0.; //Timer en s
float AcX = 0.; // Variable de l'accélération
float Somme_acc = 0. ; //Somme de Acx / 10ms
float Ax = 0. ; // Valeur de l'accélération
void setup() {
// Initialisation
Serial.begin(9600);
pinMode(10, OUTPUT); // laisser la broche SS en sortie - obligatoire avec librairie SD
test=SD.begin(4); // initialisation de la carte SD avec broche 4 en tant que CS - renvoie true/false
if (test!=true)
{
while(1);
}
Fichier = SD.open("Valeurs2.txt", FILE_WRITE);
Fichier.println("--------------Nouvelle mesure---------------");
}
void loop() {
//Loop
//Timer
Fichier.print(temps);
Serial.print(temps);
//Accélération
for ( int i=0 ; i<=4 ; i++) {
xpin = analogRead(A3);
AcX = -0.0568*xpin + 25.05;
Somme_acc = AcX + Somme_acc;
delay(10);
}
Ax = Somme_acc/5.;
Fichier.print(" ");
Fichier.println(Ax);
Serial.print(" ");
Serial.println(Ax);
delay(increment);
Somme_acc = 0. ;
temps = temps + increment*0.002 ;
if(temps > 20.)
//Fin des mesures
{Fichier.println("---------------Fin des mesures---------------");
{Fichier.close();
}
}
}
//Acceleration with MMA776
#include <Wire.h>
#include "MMA7660.h"
MMA7660 accelemeter;
#include <SD.h>
File fichier;
boolean test;
char touche;
float temps = 0.;
int increment = 100;
float ax,ay,az;
void setup()
{
accelemeter.init();
Serial.begin(9600);
pinMode(10, OUTPUT); // laisser la broche SS en sortie - obligatoire avec librairie SD
test=SD.begin(4); // initialisation de la carte SD avec broche 4 en tant que CS - renvoie true/false
if (test!=true)
{
while(1);
}
fichier = SD.open("/MMA7660",FILE_WRITE);
fichier.seek(fichier.size());
fichier.println();
fichier.println("+++++++++++++ Nouvelles valeurs +++++++++++++");
fichier.println();
fichier.println("Duree (s) ; Ax (m/s2) ; Ay (m/s2) ; Az (m/s2)");
fichier.println();
}
void loop()
{
fichier.print(temps);
fichier.print(" ; ");
accelemeter.getAcceleration(&ax,&ay,&az);
fichier.print(ax*9.81); fichier.print(" ; "); fichier.print(ay*9.81); fichier.print(" ; "); fichier.println(az*9.81);
temps = temps + increment*0.001;
delay(increment);
if (temps >= 60)
{
fichier.println();
fichier.println("+++++++++++++ Arret des mesures +++++++++++++");
fichier.close();
temps = 0.;
while(1);
}
}
//Current with MR003-006-1 and Voltage with Phidgets 1135
#include <SD.h>
File Fichier;
boolean test;
int increment = 1000;
int nI = 0.; // Variable numérique de l'intensité
int nU = 0.; // Variable numérique de la tension
float temps = 0.; // Timer
float I = 0.; // Variable de l'intensité
float U = 0.; // Variable de la tension
void setup() {
// Initialisation
Serial.begin(9600);
pinMode(10, OUTPUT); // laisser la broche SS en sortie - obligatoire avec librairie SD
test=SD.begin(4); // initialisation de la carte SD avec broche 4 en tant que CS - renvoie true/false
if (test!=true)
{
while(1);
}
Fichier = SD.open("Valeurs2.txt", FILE_WRITE);
Serial.println("--------------Nouvelle mesure---------------");
}
void loop() {
//Timer
Serial.print(temps);
Fichier.print(temps);
//Intensité
nI = analogRead(A0);
// I=0.0489*nI + 0.0589;
I= 0,0403*nI - 13,668;
Serial.print(" ");
Fichier.print(" ");
Serial.print(I);
Fichier.print(I);
//Tension
int nU = analogRead(A1);
U= 0.0713*nU - 36.634;
Serial.print(" ");
Fichier.print(" ");
Serial.println(U);
Fichier.println(U);
//delay
delay(increment);
temps = temps + increment*0.001 ;
//Fin des mesures
if(temps > 40.)
{Serial.println("--------------Fin des mesures---------------");
Fichier.close();}
}
However, we got late as the time would go on and went on an issue with acceleration. Whenever we would try to measure acceleration with either of the 2 sensors, the acceleration would be positive then negative, and alternate like this continuously until the car stops.
Here is the acceleration when MMA776 wasn't mooving :
Here is the acceleration when MMA776 was mooving (2 series of measures) :
There we go with ADXL335 while mooving (2 series of measures) :
Here we have the latest serie (previous picture of the seconde measure of ADXL335) with all the values negative put in positive :
(It's always acceleration in function of the time in ms, before we improved the programme to get the time in second (s) )
We told this to the teacher in charge of the project but he couldn't really help us. We tought that it was due to the car that was moving too much and that it would have an influence on the acceleration sensor. This car doesn't hold the road well too. So we tried to make the car accelerate between a wall and another wall-like-linked-boxes so that the car stays in one direction and doesn't move too much. It didn't really work, the problem was still there.
That put aside, there is a problem with the calibration of the acceleration sensor ADXL335 (going from N, a numeric number to an acceleration in m.s-2) as we had to recalibrate it pretty often (but it was a problem that could be handled pretty fast)
So it was a real mess for acceleration.
We tried to make something of current and voltage. We calibrated both Phidgets1135 and MR003-006.1.
Our goal there was to measure current and voltage that was getting out of the battery while the car was moving and accelerating. However, even though the programs seemed ok (we calibreted for the equations in the programs and made them with the teacher by our side) we had a constant value around 25 for current and values between -1 and 1 for voltage. We changed the program a bit and the electrical circuit, then the voltage was working. However, when we changed it again, everything was going back to 25 for current and between -1 and 1 for voltage.
Here is what looked like the circuits :
So, it was wasn't really better for current and voltage.
In the end, we made all that we could in these 3 past days but we went out of time. The teacher tried as he could to help us but we're in pretty bad shape. He gave me the car and the arduino card with the sensors (even though he's not allowed to as it's from the high school). We have until May 9. And I have 2 weeks of holidays which I would like to use to get everything working... This project is evaluated fort the bac (a diploma in France).
So, if I can say, we're in deep shit, me and my team (we're 4).
I tried to be the most complete as possible. I'm new to Arduino and to this website, thank you to those who will to help.
P.S : Excuse me if my english is bad, I'm french.
P.S² : I tried to be complete but if I forgot something, don't hesitate to ask.


