help whith sound sensor and ultrassonic sensor

I need help with a project using an ultrasonic sensor and a sound sensor, both work in separate functions but they do not work together, or just the sound sensor works or just the ultrasonic, what do I do?

energy_core_control_with_time_and_sound_sensor_and_voltimeter_a.ino (5.86 KB)

#define CUSTOM_SETTINGS
#define INCLUDE_TEXT_TO_SPEECH_SHIELD
#define INCLUDE_VOICE_RECOGNIZER_SHIELD
#define INCLUDE_CLOCK_SHIELD

/* Include 1Sheeld library. */
#include <OneSheeld.h>

#define loadPin 13
#define battery 12
#define mic 8
#define led 7
#define voltimeter A0
#define bright A1
#define echoPin 11
#define trigPin 10

#define tempoMaximoDeUmaPalma 150 //milisegundos
#define tempoMaximoEntrePalmas 500 //milisegundos

boolean load = false;

byte hour, minute, second, day, month, year;
byte contaPalmas = 0;
unsigned long tempoEspera = 0;
unsigned long tempoEsperaEntrePalmas = 0;

float Vo = 0.0, Vi = 0.0;
float value_aux = 0, value = 0;

//Valores dos Resistores//
float R1 = 1000000.0; //Resistência R1 (992K) -see text!
float R2 = 300000.0; //Resistência R2 (168K) - see text!

/* A command which will be compared. */
const char ONCommand=“ligar”;

/* A command which will be compared. */
const char OFFCommand=“desligar”;

/* A command which will be compared. */
const char timeCommand=“em que tempo estamos”;

/* A name for the LED on pin 13. */

const char energyCommand=“energia”;

/* A name for the LED on pin 13. */

const char distanceCommand=“teste”;

/* A name for the LED on pin 13. */

void palmas();
void relogio();
void voltimetro();
void aproximacao();

void setup()
{
/* Start communication. */
OneSheeld.begin();
Clock.queryDateAndTime();

pinMode(loadPin,OUTPUT);
pinMode(battery,OUTPUT);
pinMode(led,OUTPUT);
pinMode(trigPin, OUTPUT);
pinMode(mic, INPUT);
pinMode(voltimeter,INPUT);
pinMode(bright,INPUT);
pinMode(echoPin, INPUT);

digitalWrite(battery,HIGH);
digitalWrite(loadPin,LOW);
digitalWrite(led,LOW);
}

void loop()
{

palmas();

/* Always check if a new voice command received. */
if(VoiceRecognition.isNewCommandReceived())
{

/* Check if the voice command is the desired one. */
if(!strcmp(ONCommand,VoiceRecognition.getLastCommand()))
{
digitalWrite(battery,LOW);
delay(3500);
TextToSpeech.say(“gerador ativado”);
digitalWrite(loadPin,HIGH);
delay(300);
digitalWrite(loadPin,LOW);
load = true;
delay(200);
digitalWrite(led,LOW);

}

else if(!strcmp(OFFCommand,VoiceRecognition.getLastCommand()))
{
digitalWrite(loadPin,HIGH);
delay(300);
digitalWrite(loadPin,LOW);
TextToSpeech.say(“gerador desativado”);
delay(2000);
digitalWrite(battery,HIGH);
delay(200);
digitalWrite(led,LOW);
}

else if(!strcmp(energyCommand,VoiceRecognition.getLastCommand()))
{
voltimetro();

}

else if(!strcmp(timeCommand,VoiceRecognition.getLastCommand()))
{
relogio();

}
else if(!strcmp(distanceCommand,VoiceRecognition.getLastCommand()))
{
aproximacao();

}
}
}

void relogio()
{
String hora=String( Clock.getHours());
TextToSpeech.say(“agora”);
OneSheeld.delay(1000);
TextToSpeech.say(hora);
OneSheeld.delay(1000);
TextToSpeech.say(“horas”);
OneSheeld.delay(1000);
String minutos=String(Clock.getMinutes());
TextToSpeech.say(minutos);
OneSheeld.delay(1500);
TextToSpeech.say(“minutos”);
OneSheeld.delay(1000);
String segundos=String(second = Clock.getSeconds());
TextToSpeech.say(segundos);
OneSheeld.delay(1000);
TextToSpeech.say(“segundos”);
OneSheeld.delay(1000);
TextToSpeech.say(“hoje é”);
OneSheeld.delay(1000);
TextToSpeech.say(“dia”);
OneSheeld.delay(1000);
String dia=String(Clock.getDay());
TextToSpeech.say(dia);
OneSheeld.delay(1000);
TextToSpeech.say(“do mês”);
OneSheeld.delay(1000);
String mes=String(Clock.getMonth());
TextToSpeech.say(mes);
OneSheeld.delay(1000);
TextToSpeech.say(“do ano”);
OneSheeld.delay(1000);
String ano=String(Clock.getYear());
TextToSpeech.say(ano);
OneSheeld.delay(3000);
delay(200);
digitalWrite(led,LOW);
}

void voltimetro()
{
for(int i=60;i>0;i–){
value_aux = analogRead(voltimeter);
value += pow(value_aux,2);
}

value = sqrt(value/60);
Vo = (value * 5.0) / 1023.0;
Vi = Vo / (R2/(R1+R2))-0.48;
if (Vi<0.09) {Vi=0.0;} //Filtrando medições errôneas!
String stringone=String(Vi);
String stringtoo=String(Vo);

TextToSpeech.say(stringone);
delay(3000);
TextToSpeech.say(“volts”);

int porcentagem =(int)Vi;
int valor =map(porcentagem,11,13,0,100);
String string=String(valor);
TextToSpeech.say(string);
OneSheeld.delay(1000);
TextToSpeech.say(“por cento”);
delay(1000);
delay(200);
digitalWrite(led,LOW);
}

void palmas()
{
boolean sensorSom = digitalRead(mic);
//se o sensor detectou palmas
if (sensorSom == LOW) {

//espera um tempo para nao detectar a mesma palma mais de uma vez
if (tempoEspera == 0)
{
tempoEspera = tempoEsperaEntrePalmas = millis();
contaPalmas++;
}
else if ((millis() - tempoEspera) >= tempoMaximoDeUmaPalma)
{
tempoEspera = 0;
}
}

//caso exceda o tempo maximo entre palmas, zera o contador de palmas
if ( (contaPalmas != 0) && ((millis() - tempoEsperaEntrePalmas) > 500) )
{

switch (contaPalmas) {
case 2:
VoiceRecognition.start();
delay(200);
digitalWrite(led,HIGH);
break;
}
contaPalmas = 0;
tempoEsperaEntrePalmas = millis();
}
}

void aproximacao()
{
digitalWrite(trigPin, HIGH);
delay(10);
digitalWrite(trigPin, LOW);
long duration = pulseIn(echoPin,HIGH);
long distancia = duration /29 / 2 ;
if(distancia<40){
digitalWrite(led,HIGH);
delay(200);
TextToSpeech.say(“alerta de proximidade”);
delay(1000);
TextToSpeech.say(“recue imediatamente”);
delay(4000);
}
else
{
digitalWrite(led,LOW);
delay(200);
}
}

  1. please post links to the specific sensors you use
  2. please post circuit diagram showing how everything is wired
  3. please edit post #1 and add code tags (the </> icon) around your code to make it readable.
  4. please explain what you’re trying to do, what it does do, and what it does not do and in what circumstances.