string = String(leftLight) + ", " + String(rightLight) + ", " + String(leftTemp) + ", " + String(rightTemp) + ", " + String(leftEmf) + ", " + String(rightEmf) + ", " + String(sonicData);
There is NO benefit in using one Serial.print() statement over using 13 Serial.print() statements. In fact, pissing away resources on all those String instances costs more time and memory.
lastSample = millis();
The last sample is not anything derived from millis(). The lastSampleTime is. Meaningful names are important.
sonic();
Good function names consist of a noun and a verb. digitalRead(), for instance. Crappy names consist of random letters. There is nothing in the name of this function that tells me what it does. The same holds true for datas() and movement().
void sonic()
{
int duration, distance;
digitalWrite(trigPin, HIGH);
delayMicroseconds(1000);
digitalWrite(trigPin, LOW);
duration = pulseIn(echoPin, HIGH);
distance = (duration/2) / 29.1;
sonicData = distance;
}
There is no excuse for this function not returning a value. Get off the dependence on global variables. digitalRead() doesn't store data in a global variable. Your function shouldn't, either. digitalRead() doesn't presume to know what pin to use. Your function shouldn't either.