Play sound from pc

Hello

i’m new user for ardiuno and this is my first project

i built a small circuit of temp. sensor ( DHT22 ) , arduino UNO and xbee modules
all i need now to add code for beep or any sound ( as alarm )plays from PC when temperature readings become high .
this is my code :

    #include <SoftwareSerial.h>



#include "DHT.h"

#define DHTPIN 7    
#define DHTTYPE DHT22   


int maxHum = 60;
int maxTemp = 20;

SoftwareSerial XBee(2, 3);
DHT dht(DHTPIN, DHTTYPE);

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

}

void loop() {
      delay(2000);
  float h = dht.readHumidity();
    float t = dht.readTemperature();

  if (isnan(h) || isnan(t)) {
    XBee.println("Failed to read from DHT sensor!");
    return;
  }

  if (h > maxHum ) {
    XBee.println(" warrning hum.");
    Console.Beep();
  } 
if (t >  maxTemp ) {
  XBee.println( " warrning temp. ");
  Console.Beep();
}
  
  XBee.print("Humidity: ");
  XBee.print(h);
  XBee.print(" %\t");
  XBee.print("Temperature: ");
  XBee.print(t);
  XBee.println(" *C ");

 if (Serial.available())
  { 
    XBee.write(Serial.read());
  }
  if (XBee.available())
  { 
    Serial.write(XBee.read());

 
 }
}

Thank you…

all i need now to add code for beep or any sound ( as alarm )plays from PC when temperature readings become high

You need to write code in your PC to receive the command to make a sound and then make it.
You need to write this code in some language. Processing is popular for doing this sort of thing.

so, how i can write that code :slight_smile:
would you help me plz.

This is an Arduino forum not a PC code writing forum.
What language do you want to use?

i'm using Arduino software
so it should use c#

mrkuraz:
i'm using Arduino software
so it should use c#

That makes no sense. The language you use in the PC is independent of the Arduino software.

This is a lot of trouble just to get a PC to beep, why can you not use the Arduino and use the tone function?

sorry for taking your time , but how i can use tone function in my case ?
i need any thing could play sound from my pc .
thank you,,

i need any thing could play sound from my pc .

Why does it have to be the PC?

but how i can use tone function in my case ?

I said:-

why can you not use the Arduino and use the tone function?

You seem to be out of your depth and it seems to me that you are making things even more difficult for your self. It also does not help that you have not properly described you setup. Your description is very vague.
You just said:-

i built a small circuit of temp. sensor ( DHT22 ) , arduino UNO and xbee modules
all i need now to add code for beep or any sound ( as alarm )plays from PC when temperature readings become high .

So where is the connection to the PC coming from?
Do you have two Arduinos, or one Arduino with one xbee and then an xbee connected to your PC?
You know these things but we are not sat in front of your machine.
If you have a second xbee connected directly to your PC then you must have some code communicating with it. If so then use that code to make your sound. But all this is just guess work because despite what it may look like, there are no mind readers on this forum.

yes i have 2 Xbee , one installed on the arduino and the second connected directly to my computer

i made a communication between them and that was fine .

to be more clear .. i got temperature readings from the sensor and using Xbee this readings will transfer to my pc . now when temperature become more than 20 " for example " i want to play an alarm to take my attention

So if your PC is receiving the temperature, the code that is doing the receiving can include the detection of the threshold temperature and the triggering of the sound.

I can't see how this is an Arduino problem.

it's not a problem , as i said before i want the pc play sound when temperature become more than 20 as written in my arduino code

how i can do that ! what i should add to my arduino code !?

what i should add to my arduino code !?

Nothing, why should you add anything?

to make my pc plays sound when temperature become more than 20
how !?

Write a PC program that receives data from an Arduino with a temperature probe, then make noise when the
Arduino sends a message indicating the temperature has been reached.

Or just let the Arduino make the noise in case the PC goes to sleep from inactivity.

CrossRoads:
Write a PC program that receives data from an Arduino with a temperature probe,

He claims to have done that.

mrkuraz:
yes i have 2 Xbee , one installed on the arduino and the second connected directly to my computer

I am assuming that there is something actually reading the temperature on his computer from the Xbee. So it is that code that can be added to in order to monitor the incoming data and trigger a sound when it exceeds certain limits.

However, communications is very heavy going and he doesn't seem to understand much of what you say.

CrossRoads:
then make noise when the Arduino sends a message indicating the temperature has been reached.

How i can make that ?

Grumpy_Mike:
I am assuming that there is something actually reading the temperature on his computer from the Xbee

right , i receive data from Xbee using X-CTU

i receive data from Xbee using X-CTU

So that displays the data on a terminal.
Is the only thing you are doing with the data?

Will this terminal respond to the ASCII bell command?
Try it by sending it a value of 7 and see if it makes a noise.
So at the Arduino end you send it with a

Serial.write(7);

If you don’t get a sound then you need a terminal that does support the ASCII bell command.

Grumpy_Mike:

Serial.write(7);

it doesn't work :confused:

Grumpy_Mike:
If you don’t get a sound then you need a terminal that does support the ASCII bell command.

See:-