I have a project where we need to create a virtual cane for blind people and it will have 3 functions:
Pressure button when pressed will connect to an android phone through HC-06 Bluetooth modulo to an app that I developed and will can to someone that I defined
Temperature sensor that is attached to a buzzer that will buzz if the temperature is higher than 40 Degrees
Ultrasonic sensor attached to and vibration motor that will vibrate if there is any object less than 70 cm from the person.
When I combine the code from the ultrasonic and the temperature sensor, everything works fine, when I add the bluetooth code, nothing works, anyone see the problem? Or could you show me the problem and solveit?
Code without Bluetooth:
int DHT11_PIN=8;
dht DHT;
int buzzer=6;
int trigPin=3;
int echoPin=2;
int motor=7;
void setup(){
Serial.begin(115200);
pinMode(DHT11_PIN,INPUT);
pinMode(buzzer, OUTPUT);
delay(5000);
Serial.begin(9600);
pinMode(trigPin, OUTPUT);
pinMode(echoPin, INPUT);
pinMode(motor, OUTPUT);
delay(5000);
}
void loop(){
Stemperature();
Sultrassom();
}
// sensor de tempratura e Buzzer-------------------------------
void Stemperature(){
digitalWrite(buzzer,LOW);
DHT.read11(DHT11_PIN);
float t=DHT.temperature;
Serial.print("Temperature = ");
Serial.println(t);
if (t>40){
digitalWrite(buzzer,HIGH);
{tone(6,100,20);
delay(1);
noTone(1);
delay(1);
}
delay(1000);
Serial.print("ON T=");
}else{
digitalWrite(buzzer,LOW);
Serial.print("OF T=");
}
}
//Sensor de Ultrassom e Motor vibração-----------------
void Sultrassom(){
long duration, distance;
digitalWrite(trigPin, LOW);
delayMicroseconds(2);
digitalWrite(trigPin, HIGH);
delayMicroseconds(10);
digitalWrite(trigPin, LOW);
duration = pulseIn(echoPin, HIGH);
distance = (duration/2) * 0.0340;
Serial.println(distance);
if (distance < 70){ // se a distância for menor que 70 cm o motor vibra
digitalWrite(motor,HIGH);// quando a distância for menor que 70 cm
Serial.print("MOTOR ON=");
}else{
digitalWrite(motor,LOW);// quando a distância for maior que 70 cm
Serial.print("MOTOR OFF=");
}
delay(5);
}
Bluetooth Code:
const int buttonPin = 4; // the number of the pushbutton pin
boolean buttonState; // variable for reading the pushbutton status
void setup(){
Serial.begin(9600);
// initialize the pushbutton pin as an input:
pinMode(buttonPin, INPUT);
buttonState = LOW;
}
void loop(){
// read the state of the pushbutton value:
buttonState = digitalRead(buttonPin);
// check if the pushbutton is pressed. If it is, the buttonState is HIGH:
if(buttonState == HIGH) {
// send char 1 via Bluetooth:
Serial.println("1");
delay(20000);
while (0);
}
}