Combining sketches

I NEED HELP COMBINING CODES FOR VOLTAGE, CURRENT, PROXIMITY, LEVEL, ELECTRIC MOTOR

//ACCELEROMETER

int x, y, z;

//CURRENT SENSOR
const int analogInPin = A2;
const int avgSamples = 10;
int sensorValue = 0;
float sensitivity = 100.0 / 500.0;
float Vref = 2500;

//VOLTAGE SENSOR
int value = 0;
float voltage;
float R1 = 47000.0;
float R2 = 33000.0;

//PROXIMITY SENSOR
#include <SharpIR.h>
#define ir A0
#define model 20150
SharpIR SharpIR(ir, model);

//FLOWRATE
int flowPin = 3; 
double flowRate; 
volatile int count; 

//ELECTRIC MOTOR
const int MotorPinA = 12;
const int MotorSpeedPinA = 3;
const int MotorBrakePinA = 9;


const int MotorPinB = 13;
const int MotorSpeedPinB = 11;
const int MotorBrakePinB = 8;

const int CW  = HIGH;
const int CCW = LOW;

const int showComments = 1;


void setup()
{

 //ACCELEROMETER
 Serial.begin(9600);
 
 //CURRENT SENSOR
 Serial.begin(19200);

 //VOLTAGE SENSOR
 Serial.begin(57600);

 //PROXIMITY SENSOR
 Serial.begin(74880); 
 pinMode(MotorPinA, OUTPUT);
 pinMode(MotorSpeedPinA, OUTPUT);
 pinMode(MotorBrakePinA, OUTPUT);

 //FLOWRATE METER
 pinMode(flowPin, INPUT);
 attachInterrupt(0, Flow, RISING);
 Serial.begin(115200);

 //ELECTRIC MOTOR
 pinMode(MotorPinA, OUTPUT);
 pinMode(MotorSpeedPinA, OUTPUT);
 pinMode(MotorBrakePinA, OUTPUT);

 pinMode(MotorPinB, OUTPUT);
 pinMode(MotorSpeedPinB, OUTPUT);
 pinMode(MotorBrakePinB, OUTPUT); 

 Serial.begin(230400);//  seial monitor initialized 
 
}

void loop()
{

 
 //ACCELEROMETER
 
 x = analogRead(0);
 y = analogRead(1);
 z = analogRead(2);
 Serial.print("accelerations are x, y, z: ");
 Serial.print(x, DEC);
 Serial.print(" ");
 Serial.print(y, DEC);
 Serial.print(" ");
 Serial.println(z, DEC);
 delay(1000);


 //CURRENT SENSOR
 for (int i = 0; i < avgSamples; i++)
 {
 sensorValue += analogRead(analogInPin);
 delay(50);
 } 
 sensorValue = sensorValue / avgSamples;
 float voltage = 4.88 * sensorValue;
 float current = (voltage - Vref) * sensitivity;
 Serial.print(voltage);
 Serial.print("\n");
 sensorValue = 0;

 
 //VOLTAGE SENSOR
 value = analogRead(A0);
 voltage = value * (5.0/1024)*((R1 + R2)/R2);
 Serial.print("Voltage =");
 Serial.println(voltage);
 delay(500);

 
 //PROXIMITY SENSOR
 delay(2000);   
 unsigned long pepe1=millis();  
 int dis=SharpIR.distance();  
 Serial.print("Mean distance: "); 
 Serial.println(dis);
 unsigned long pepe2=millis()-pepe1;  
 Serial.print("Time taken (ms): ");
 Serial.println(pepe2);  

 //FLOWRATE METER
 count = 0; 
 interrupts(); 
 delay (1000); 
 noInterrupts(); 
 flowRate = (count * 2.25); 
 flowRate = flowRate * 60; 
 flowRate = flowRate / 1000; 
 Serial.print(flowRate); 
 Serial.println("mL/Second");
 
 void Flow()
 {
 count++; 
 
 }

 //ELECTRIC MOTOR

 brake('A', 0); // release brake
   brake('B', 0); // release brake
 moveMotor('A', CCW, 100);// motot A rotate CCW at 100 PWM value
   moveMotor('B', CW, 145);// motot B rotate CW at 145 PWM value
 delay(3000);
 brake('A',1);
 brake('A',0);
   brake('B',1);
 brake('B',0);
 moveMotor('A', CW, 255);
     moveMotor('B', CCW, 145);  
 delay(5000);
 brake('A',1);

{
 void moveMotor(char motor, int dir, int speed)
{
 int motorPin;
 int motorSpeedPin;
 
 if(motor =='A')
 {
   motorPin      = MotorPinA;
   motorSpeedPin = MotorSpeedPinA;  
 }else{
   motorPin      = MotorPinB;
   motorSpeedPin = MotorSpeedPinB;     
 }
  digitalWrite(motorPin, dir);// set direction for motor
  analogWrite(motorSpeedPin, speed);// set speed of motor   
}//moveMotor end

void brake(char motor, int brk)
{
 if(motor =='A')
 {
   digitalWrite(MotorBrakePinA, brk);// brake
   delay(1000);
 }else{
   digitalWrite(MotorBrakePinB, brk);// brake
   delay(1000);
  
 }
}
 
}

@caosaretin

TOPIC SPLIT
DO NOT HIJACK / NECRO POST !

Could you take a few moments to Learn How To Use The Forum.
Other general help and troubleshooting advice can be found here.
It will help you get the best out of the forum in the future.

Copy the pre-setup() code from file 2 into file 1.
Copy the setup() code from file 2 into file 1.
Copy the loop() code from file 2 into file 1.
Copy any other functions from file 2 into file 1.

Now address any duplicate pin usages, any duplicates in setup(), perhaps both call out Serial.begin().
Fix any other duplicates.
Compile, and see how it looks.
Fix any logic errors that may have been introduced.

In this case tho, you just need to move 3 functions out of loop(); you can't have a function within a function:

void Flow()
{
  count++;
}
void moveMotor(char motor, int dir, int speed)
{
  int motorPin;
  int motorSpeedPin;


  if (motor == 'A')
  {
    motorPin      = MotorPinA;
    motorSpeedPin = MotorSpeedPinA;
  } else {
    motorPin      = MotorPinB;
    motorSpeedPin = MotorSpeedPinB;
  }
  digitalWrite(motorPin, dir);// set direction for motor
  analogWrite(motorSpeedPin, speed);// set speed of motor
}//moveMotor end


void brake(char motor, int brk)
{
  if (motor == 'A')
  {
    digitalWrite(MotorBrakePinA, brk);// brake
    delay(1000);
  } else {
    digitalWrite(MotorBrakePinB, brk);// brake
    delay(1000);
  }
}