Code Help! [Piezo Speaker and Fire Sensor]

I have the code for the fire sensor which is listed below. I want this to happen:
When fire detected (close long or medium) i want a piezo to ring.

Fire sensor code:

/* Flame Sensor analog example.
Code by Reichenstein7 (

Flame Sensor Ordered from DX (
detection-blue-dc-3-3-5v-118075?tc=USD&gclid=CPX6sYCRrMACFZJr7AodewsA-Q#.U_n5jWOrjfU )

To test view the output, point a serial monitor such as Putty at your arduino.

// lowest and highest sensor readings:
const int sensorMin = 0; // sensor minimum
const int sensorMax = 1024; // sensor maximum

void setup() {
// initialize serial communication @ 9600 baud:
void loop() {
// read the sensor on analog A0:
int sensorReading = analogRead(A0);
// map the sensor range (four options):
// ex: 'long int map(long int, long int, long int, long int, long int)'
int range = map(sensorReading, sensorMin, sensorMax, 0, 3);

// range value:
switch (range) {
case 0: // A fire closer than 1.5 feet away.
Serial.println("** Close Fire ");
case 1: // A fire between 1-3 feet away.
Distant Fire **");
case 2: // No fire detected.
Serial.println("No Fire");
delay(1); // delay between reads

Here is the code for the piezo speaker:

void setup() {
// declare pin 9 to be an output:
pinMode(9, OUTPUT);

void loop() {

void beep(unsigned char delayms){
analogWrite(9, 20); // Almost any value can be used except 0 and 255
// experiment to get the best tone
delay(delayms); // wait for a delayms ms
analogWrite(9, 0); // 0 turns it off
delay(delayms); // wait for a delayms ms

Thank you very much!

Please put your code in its own window as seen in other posts. This can be done by placing     [code] and [/code]  around the code. This makes it easier for others to read.


move this to the programming section ?