Hey guys
Am new into Arduino and still developing my programming skills, I have this thing am working on
am trying to use an ultrasonic sensor to detect once an object has been detected. Once the object is detected I then have an FSR sensor to detect if an object is there or not (weight ) so this is what am trying to do:
-The ultrasonic sensor detects object then checks the FSR status, if the Fsr voltage is more than or equal to 1300 mv then an object is detected (this is a threshold I chose) and if its less than 1300 then no object is detected. If the Fsr voltage is more than or equal to 1300 mv then an alarm would go off
-Ofc if the ultrasonic doesn’t detect anything then nothing happens (The ultrasonic will act as the system initiator)
The below code is for when the Fsr detects an object and gives an alarm
int fsrPin = A0;
int fsrVoltage; // the analog reading converted to voltage
int fsrReading; // the analog reading from the FSR resistor divider
int const buzzPin = 6;
void setup(void) {
pinMode(buzzPin, OUTPUT); // buzz pin is output to control buzzering
// We’ll send debugging information via the Serial monitor
Serial.begin(9600);
}
void loop(void) {
fsrReading = analogRead(fsrPin);
Serial.println("Analog reading = ");
Serial.println(fsrReading);
// We’ll have a few threshholds, qualitatively determined
fsrVoltage = map(fsrReading, 0, 1023, 0, 5000);
Serial.print(“Voltage reading in mV = “);
Serial.println(fsrVoltage);
if (fsrVoltage >=1300)
{
Serial.println(“OBJECT DETECTED”);
digitalWrite(buzzPin, HIGH);
}
else {
Serial.println(” NO OBJECT DETECTED !!”);
digitalWrite(buzzPin, LOW);
}
delay(1000);
}
I also have the code for the ultrasonic sensor
*/
// Define pins for ultrasonic and buzzer
int const trigPin = 10;
int const echoPin = 9;
int const buzzPin = 2;
void setup()
{
pinMode(trigPin, OUTPUT); // trig pin will have pulses output
pinMode(echoPin, INPUT); // echo pin should be input to get pulse width
pinMode(buzzPin, OUTPUT); // buzz pin is output to control buzzering
}
void loop()
{
// Duration will be the input pulse width and distance will be the distance to the obstacle in centimeters
int duration, distance;
// Output pulse with 1ms width on trigPin
digitalWrite(trigPin, HIGH);
delay(1);
digitalWrite(trigPin, LOW);
// Measure the pulse input in echo pin
duration = pulseIn(echoPin, HIGH);
// Distance is half the duration devided by 29.1 (from datasheet)
distance = (duration/2) / 29.1;
// if distance less than 0.5 meter and more than 0 (0 or less means over range)
if (distance <= 10 && distance >= 0) {
// Buzz
digitalWrite(buzzPin, HIGH);
} else {
// Don’t buzz
digitalWrite(buzzPin, LOW);
}
// Waiting 60 ms won’t hurt any one
delay(60);
}
NOW since am still a beginner to programming I would like to integrate the last ultrasonic sensor code to the first code to do the function mentioned at the beginning of the post but am not sure how to do so
Would appreciate any help
Thnx