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: