Flex Sensor with Buzzer

Hi guys,

While making a project that uses a flex sensor to determine bend angle and beeps a buzzer when the flex sensor gets bent.

If I just test the flex on the breadboard it works fine. Above 700 I get an alarm and normally it reads 640-645. I connect the sensor to a nano with a 10k R from the 5V of the nano and another line from A1 and I use this code to get the readings:

int flexSensorPin = A1;
void setup(){
  Serial.begin(9600);
}
void loop(){
  int flexSensorReading = analogRead(flexSensorPin); 
  Serial.println(flexSensorReading);
  delay(250); 
}

Even with this code I get the alarm printed to the serial monitor:

int flexSensorPin = A1;//analog pin 7= tiny2=A1
const int Piezo = 0; //digital pin 2 = tiny0
void setup(){
  pinMode (Piezo, OUTPUT);
  Serial.begin(9600);
}
void loop(){
  int flexSensorReading = analogRead(flexSensorPin); 
  Serial.println(flexSensorReading);
  if (flexSensorReading>700) {
    Serial.println("Alarma Caracola!");
    digitalWrite(Piezo, HIGH);
    delay(100);
    digitalWrite(Piezo, LOW);
  }
  delay(250); 
}

But when I move it to the attiny and add the buzzer using the same code as above (but without the serial.print lines of course), I get a constant repetitive beeping as expected by the code if the sensor was giving a > 700 reading. Here is my schematic:

Hi,
Can you post your code and a proper schematic, not a Fritzy picture please?

Thanks.. Tom... :slight_smile:

I modified the original post to make it simpler. I added the code and my hand schematic.

I dont know how to debug what is happening because I cant see the serial monitor. Any tricks?

Hi,

First measure the A1 voltage with a DMM, see if it is moving when you flex.

If you put the Pin2, A1 to gnd does the it stop?

If so, replace the flex sensor and 10K resistor with a 10K pot and adjust it to find the A1 voltage that makes it buzz.

Tom... :slight_smile: