Control buzzer


#1

Please how can I change the frequency of the buzzer , I’m using Potentiometer


#2

can you provide a bit more information about this.


#3

i want to vary the frequency of the buzzer using the potiemeter


#4

on cayenne dashboard as a slider?


#5

hye, can anyone help me on how to stop the buzzer remotely by using widget? btw, im newbie. this is my coding.

#define CAYENNE_DEBUG       // Uncomment to show debug messages
#define CAYENNE_PRINT Serial  // Comment this out to disable prints and save space
#include <CayenneMQTTEthernet.h>
#define VIRTUAL_CHANNEL V1
#define SENSOR_PIN 5
#define VIRTUAL_CHANNEL 1

// Cayenne authentication info. This should be obtained from the Cayenne Dashboard.
char username[] = "";
char password[] = "";
char clientID[] = "";
int sensorValue = A5;
int mq3_analogPin = 5; // connected to the output pin of MQ3
byte red=4, green=5, yellow=6; // pins for leds
// remember 100 to 1000 ohm resistor in series with each LED
const int buzzerPin = 9;

void setup()
{
  pinMode(red,OUTPUT);
  pinMode(yellow,OUTPUT);
  pinMode(green,OUTPUT);
  Serial.print("Alcohol value:");
  Serial.begin(9600);
  Cayenne.begin(username, password, clientID);
}

void loop() 
{
  Cayenne.loop();
  // give ample warmup time for readings to stabilize
  int mq3_value = analogRead(5);
  float voltage = mq3_value* (5.0/1023.0);
  Serial.print("Alcohol value:");
  Serial.println(mq3_value);
  Serial.print("Voltage(V)");
  Serial.println(voltage); 
  if (mq3_value<400)
  {
    Serial.print("\nPass. Safe drive!");
    digitalWrite(green,HIGH);
    delay(100);
    digitalWrite(green,LOW);
    
  }
  else if(mq3_value>800)
  {
    Serial.print("\nWARNING! You can't drive.");
    digitalWrite(red,HIGH);
    delay(100);
    digitalWrite(red,LOW);
    pinMode(buzzerPin, OUTPUT); //addigning pin to Output mode</p><p>}</p><p>void loop() {
  tone(buzzerPin, 50);
  delay(50);
  noTone(buzzerPin);
  delay(100);
  }
  else
  {
    Serial.print("\nYou're still under control. But be careful!");
    digitalWrite(yellow,HIGH);
    delay(100);
    digitalWrite(yellow,LOW);
  }
  delay(300); //Just here to slow down the output.
}

CAYENNE_OUT (VIRTUAL_CHANNEL)
{
  Cayenne.virtualWrite (VIRTUAL_CHANNEL, map(analogRead(5), 0, 1023, 0, 1023));
}

#6

add a button widget with channel 2.

CAYENNE_IN(2)
{
	if (getValue.asInt() == 1) {
	  noTone(buzzerPin);
}
}

#7

im sorry. but where to put the code that you gave? because it doesnt work


#8

add after this.

where did you put?


#9

just like you said huhuhu


#10
#define CAYENNE_DEBUG       // Uncomment to show debug messages
#define CAYENNE_PRINT Serial  // Comment this out to disable prints and save space
#include <CayenneMQTTEthernet.h>
#define SENSOR_PIN 5
#define VIRTUAL_CHANNEL V3
#define VIRTUAL_CHANNEL 3
#define VIRTUAL_CHANNEL 2


char username[] = "";
char password[] = "";
char clientID[] = "";

int sensorValue = A5;
int mq3_analogPin = 5; 

byte red=4, green=5, yellow=6; 

const int buzzerPin = 9;


void setup()
{
  pinMode(red,OUTPUT);
  pinMode(yellow,OUTPUT);
  pinMode(green,OUTPUT);
  Serial.print("Alcohol value:");
  Serial.begin(9600);
  Cayenne.begin(username, password, clientID);
}

void loop() 
{
  Cayenne.loop();
  int mq3_value = analogRead(5);
  float voltage = mq3_value* (5.0/1023.0);
  Serial.print("Alcohol value:");
  Serial.println(mq3_value);
  Serial.print("Voltage(V)");
  Serial.println(voltage); 
  
  if (mq3_value<400)
  {
    Serial.print("\nPass. Safe drive!");
    digitalWrite(green,HIGH);
    delay(100);
    digitalWrite(green,LOW);
    }
    
  else if(mq3_value>800)
  {
  Serial.print("\nWARNING! You can't drive.");
  digitalWrite(red,HIGH);
  delay(100);
  digitalWrite(red,LOW);
  pinMode(buzzerPin, OUTPUT); //addigning pin to Output mode</p><p>}</p><p>void loop() {
  tone(buzzerPin, 50);
  delay(50);
  noTone(buzzerPin);
  delay(100);
  }
  
  else
  {
    Serial.print("\nYou're still under control. But be careful!");
    digitalWrite(yellow,HIGH);
    delay(100);
    digitalWrite(yellow,LOW);
  
  delay(300); //Just here to slow down the output.
}

CAYENNE_OUT (VIRTUAL_CHANNEL)
{
  Cayenne.virtualWrite (VIRTUAL_CHANNEL, map(analogRead(5), 0, 1023, 0, 100));
}

CAYENNE_IN(2)
{
  if (getValue.asInt() == 1) 
  {
    noTone(buzzerPin);
}
}

why is my button do not functioning? is my coding correct? the buzzer will on when the alcohol value reach 800 but how can i stop the buzzer remotely?


#11

change this :

to

#define VIRTUAL_CHANNEL 3

add } after