Rate of Rise Threshold

hi All

I'm working on a project that includes a arduino, potentiometer, and a buzzer i need help figuring out how to build the code so when the pot is turned up rapidly like %10 in 500 milliseconds it will set off the buzzer for 1 second. i don't know what other application would use this circuit. Rate of Rise Threshold
What's the potentiometer for? If you're measuring temperature change, you're going to need a thermometer.

To test rate of change:
Keep two variables: oldTemp and newTemp.
Each time your code loops, set oldTemp to newTemp, and set newTemp to whatever the thermometer reads.
100*(oldTemp-newTemp)/oldTemp = % change in temperature
If you have a 500ms pause in your loop, this % change will be the % change in 500ms.
It is going to be a thermometer. I was just using a pot as a point to test from. Do you know of any sources I can find this code from. I'm a newbie at programing and would like to check out a project that someone has close to the same idea.
I don't know of any, but you might find something if you Google it. What is it you're having trouble with? Have you written any code yet?
Ive tried goggling it and haven found something close enough for me to figure out. the part I'm struggling with is getting the old value and comparing it to the new one i don't know how to formulate that in a loop with a time delay.


buzzer = 9,

void setup() {
pinMode(pot, INPUT);

void loop()
{
for (int i=255;i>180;i--)
{
digitalWrite(buzzer, i);
delay(30);
}

for (int i=180;i<255;i++)
{
digitalWrite(buzzer, i);
delay(30);
}

digitalWrite(buzzzer, 255);

Can you post your full code? I already see a few potential problems, but I want to see everything so I know what you're doing. Use code blocks (the button to the right that looks like <>) to format it properly.
i made my own code and im not trying to mod on anyone else stuff can you make sentence of this and sorry i cant post code wort any thing

[code]

int sensorpin = A0;
int buzzer =9;

void loop() {

sencorvalue = analogRead(sencorpin);
delay(200)
100* (oldtemp - sencorpin) / oldtemp = %
digiitalWright (9, % > 5) = HIGH
delay(500)
digitalWright(buzzer, LOW)
delay(1)
}

[code]

You have quite a few misspellings in that code, and it wouldn't run anyways.


Arduino code is very similar to C++, except it doesn't have the Standard Template Library, and it does have a few special functions for interacting with your Arduino board.

The first thing you want to do in an Arduino program is set the pin numbers that you will be using. I recommend using #define for this. In your code for example you would want:
1
2
#define sensorPin 0
#define buzzerPin 9 

This acts the same way as #define in C++. All it does is tell the compiler to replace every instance of "buzzer" with the number 9. The pin numbers you want to use will be different depending on what type of Arduino board you have, so make sure you're using the right ones.

After you have defined the numbers for the pins you are going to use, you have to initialize those pins. This goes before the main function and looks as so:
1
2
3
4
5
void setup ( )
{
    pinMode ( sensorPin, INPUT );
    pinMode ( buzzerPin, OUTPUT );
}


The main function in Arduino is not main(), but loop(). It is a void function, and as its name implies, its contents will loop forever. This is where things get more complicated and I can't be much help. With C++, everyone has the same code to use. With Arduino, the code you use depends on the physical components you have. A potentiometer I used once had a range of 0 to 1023, but yours may be completely different. The way yours works should be detailed somewhere, and you'll have to figure that out yourself.

To get data from your devices you need to use either analogRead() or digitalRead().
To send data to your devices you need to use either analogWrite() or digitalWrite().
Variables are defined the same way as in C++.
Loops and if..else statements are the same as well.
To make your code pause for 500 milliseconds, use: delay ( 500 );

If you need help on how to use any of these functions, it's all described on the Arduino website: http://arduino.cc/en/Reference/HomePage
Last edited on
Topic archived. No new replies allowed.