You are hired as a part of a learn developing a machine interface Your specific
ID: 3829759 • Letter: Y
Question
You are hired as a part of a learn developing a machine interface Your specific job is to manage the audible tone the machine makes when a user makes a selection. The problem is that no one knows what sound the customer will want the machine to produce. Your job will be the following: Develop a program that will sound a buzzer when a button is pressed (only when pressed) Utilizing a potentiometer develop an input to the Arduino that will permit the user to select a frequency between 800 Hz and 2500 Hz over the full range of the sensor. We have done all of this in class: However in case you forgot here are a few tips A potentiometer is an analog device. It will have 3 terminals that together form a variable voltage divider. Where A and B form the high and low reference voltages and W connects to the input on the Arduino. There is no need for external resistors for the potentiometer Analog pins default to inputs so there is no need for "pinModef[)" stuff with the analog line. It can be read by calling "anatogRead()" but should be stored as a variable, e.g. X = analogRead(pin); The potentiometer will attain a max value of the high and a min value of the tow references connected to it. The Arduino utilizes a 10 bit ADC. The challenge with this problem is developing a simple algorithm to relate the value from the ADC to the desired range of the butter. First identify what the output of the sensor will be and then fit it to the desired window. There is no calculus or trig involved in this.Explanation / Answer
Hey heres the arduino sketches , for the first problem I used debouncy function which is need for any arduino project involving buttons, you can search about it. Post comments if any problems.
1.Arduino sketch :
const int BuzPin=9;
//Buzzer connected to pin 9
const int BUTTON=2;
//The Button is connected to pin 2
boolean lastButton = LOW;
//Variable containing the previous button state
boolean currentButton = LOW;
//Variable containing the current button state
boolean BuzOn = false;
//The present state of the Buzzer (on/off)
void setup()
{
pinMode (BuzPin, OUTPUT);
//Set the LED pin as an output
pinMode (BUTTON, INPUT);
//Set button as input (not required)
}
/* * Debouncing Function * Pass it the previous button state, * and get back the current debounced button state. */
boolean debounce(boolean last)
{
boolean current = digitalRead(BUTTON);
//Read the button state
if (last != current)
//if it's different…
{
delay(5);
//wait 5ms
current = digitalRead(BUTTON);
}
//read it again
return current;
//return the current value
}
void loop()
{
currentButton = debounce(lastButton);
//read deboucned state
if (lastButton == LOW && currentButton == HIGH)
//if it was pressed...
{
BuzOn = !BuzOn;
//toggle the LED value
}
lastButton = currentButton;
digitalWrite(BuzPin, BuzOn);
//change the LED state
}
2.Arduino sketch for sensing potentiometer and giving output buzzer sound
int sensorPin=0;
int BuzPin=13;
//we connect buzzer to pin 13 of arduino
//and potentiometer to pin 0
void setup()
{
pinMode(BuzPin,OUTPUT);
}
void loop()
{
int sensorValue=analogRead(sensorPin);
digitalWrite(BuzPin,HIGH);
delay(sensorValue);
digitalWrite(BuzPin,LOW);
delay(sensorValue);
}
Related Questions
drjack9650@gmail.com
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.