Coding for flex sensor and buzzer on arduino

Can anyone tell me how to do my project which is connect the flex sensor and the buzzer on Arduino uno , when it get curve it make a sound and then send sms using gsm shield
It will be in a jacket so the flex sensor should measure the curve then beep and send report .

:bangbang:Coding and doing It on Arduino :bangbang:

Hello Mrule. An interesting project. Make a list of the devices you will use, similar to this...

  1. Flex sensor
  2. Buzzer
  3. Arduino Uno
  4. GSM shield
  5. more?

Then write what you need for each -board, wires, power, pins, connections... and draw an interconnect diagram. After you have the equipment, write a sketch to test each device alone. And when that is done, merge the code so none of the code breaks, and everything talks and listens. Every step, when you need help, revisit your thread (here) and show what you have.

Thanks xfpd

  1. Flex sensor
  2. Buzzer
  3. Arduino Uno
  4. GSM shield

These are the only materials that I will use in my project and I need help with doing the project because I don’t know much about coding and electric

Okay. Start by loading FILE >> EXAMPLES >> "Blink" sketch, and get that running. Then, learn what the parts of the code do. Then make the code do other blinks. Then you can work on making other stuff in your project. (Hey, I must be offline for a day. Others can help)

Here is the BLINK tutorial.

Okay thank you

If you get stuck, ask your questions until you understand. Then move to the next step; the buzzer...

1 Like

Hi,

  • I found the code for flex and buzzer
    But I want it to make sound when the jacket curve just for atleast 1 minute then stop not when the flex sensor get straight , so it’s not make noises.

  • do you know how to coding for gsm shield so when the flex sensor bend and the buzzer make a sound it’s send a sms directly

Please I need help

And this is the code for flex sensor and buzzer:

int flexs = A0; // flex sensor is connected with pin A0 of the arduino
int flexdata = 0;

int buzzer = 5; // a buzzer is connected with pin 5 of arduino which is the pwm pin.

void setup()
{
Serial.begin(9600);

pinMode(flexs, INPUT); 

pinMode(buzzer, OUTPUT);

}

void loop()
{

flexdata = analogRead(flexs);
Serial.print("flex value;");
Serial.print(flexdata);
Serial.println("");
if( flexdata < 220)
{
analogWrite(buzzer, 150);
}

if( flexdata > 220)
{
analogWrite(buzzer, 0);
}

delay(1000);

}

Be sure to format and paste your code inside the code tag (</>) so it looks like this:

int flexs = A0;  // flex sensor is connected with pin A0 of the arduino
int flexdata = 0;
int buzzer = 5;  // a buzzer is connected with pin 5 of arduino which is the pwm pin.

void setup() {
  Serial.begin(9600);
  pinMode(flexs, INPUT);
  pinMode(buzzer, OUTPUT);
}

void loop() {
  flexdata = analogRead(flexs);
  Serial.print("flex value;");
  Serial.print(flexdata);
  Serial.println("");
  if (flexdata < 220) {
    analogWrite(buzzer, 150);
  }
  if (flexdata > 220) {
    analogWrite(buzzer, 0);
  }
  delay(1000);
}

You have a buzzer if the flex value is greater than 220, so put a delay inside the if() statement to keep the buzzer on (analogWrite(buzzer, 150)) for the length of time you want before turning the buzzer off ('analogWrite(buzzer, 0)`).

This topic was automatically closed 180 days after the last reply. New replies are no longer allowed.