# Mini Project Arduino Code help

**URL:** <https://forum.arduino.cc/t/mini-project-arduino-code-help/894352>\
**Category:** General Guidance\
**Created:** [August 10, 2021, 7:14pm UTC](https://forum.arduino.cc/t/mini-project-arduino-code-help/894352 "2021-08-10T19:14:33Z")\
**Posts on this page:** 12\
**Page:** 1

<div class="post-metadata">

**Author:** ![JennYoung](https://dub1.discourse-cdn.com/arduino/user_avatar/forum.arduino.cc/jennyoung/32/643794_2.png) [@JennYoung](https://forum.arduino.cc/u/JennYoung)\
**Post date:** [August 10, 2021, 7:14pm UTC](https://forum.arduino.cc/t/mini-project-arduino-code-help/894352/1 "2021-08-10T19:14:33Z")

</div>

Hi,

I have used the code below which is for a single sound sensor. I need help in getting a code for connecting 2 sound sensors. Also is it possible to get two graphs at the same time? And is there a way to record the obtained graph?

Thank you.

**The site I found the code** : [Using a Microphone with Arduino • AranaCorp](https://www.aranacorp.com/en/using-a-microphone-with-arduino/)

**The code used:**

//Parameters  
const int micPin = A0;

//Variables  
int micVal = 0;

void setup() {  
//Init Serial USB  
Serial.begin(9600);  
Serial.println(F("Initialize System"));  
//Init Microphone  
pinMode(micPin, INPUT);  
}

void loop() {  
readMicrophone();  
}

void readMicrophone( ) { /\* function readMicrophone \*/  
////Test routine for Microphone  
micVal = analogRead(micPin);  
Serial.print(F("mic val ")); Serial.println(micVal);  
if (micVal \> 600) {  
Serial.println("mic detected");  
}  
}

---

<div class="post-metadata">

**Author:** ![Railroader](https://dub1.discourse-cdn.com/arduino/user_avatar/forum.arduino.cc/railroader/32/274550_2.png) [@Railroader](https://forum.arduino.cc/u/Railroader)\
**Post date:** [August 10, 2021, 7:36pm UTC](https://forum.arduino.cc/t/mini-project-arduino-code-help/894352/2 "2021-08-10T19:36:34Z")

</div>

Define a micPin2 and double the code.

---

<div class="post-metadata">

**Author:** ![groundFungus](https://avatars.discourse-cdn.com/v4/letter/g/73ab20/32.png) [@groundFungus](https://forum.arduino.cc/u/groundFungus)\
**Post date:** [August 10, 2021, 7:38pm UTC](https://forum.arduino.cc/t/mini-project-arduino-code-help/894352/3 "2021-08-10T19:38:29Z")

</div>

[Read the forum guidelines](https://forum.arduino.cc/t/how-to-get-the-best-out-of-this-forum/679966) to see how to properly post code.  
Use the IDE autoformat tool (ctrl-t or Tools, Auto format) before posting code in code tags.

 ![select code tags](https://europe1.discourse-cdn.com/arduino/original/4X/c/a/a/caae64d05664eef848d7f4c1facbfe1d0f6abc87.jpeg)

---

<div class="post-metadata">

**Author:** ![alto777](https://dub1.discourse-cdn.com/arduino/user_avatar/forum.arduino.cc/alto777/32/317385_2.png) [@alto777](https://forum.arduino.cc/u/alto777)\
**Post date:** [August 10, 2021, 9:26pm UTC](https://forum.arduino.cc/t/mini-project-arduino-code-help/894352/4 "2021-08-10T21:26:18Z")

</div>

> [@Railroader](#):
>
> Define a micPin2 and double the code.

Yes. If you are new to programming or coding whatever you are calling it, you will soon see that recognizing patterns and changing them to do more or new stuff is an essential skill.

So take a look at how micPin is used, and fake your way to having all the same things but talking about a newly introduced micPin2.

a7

---

<div class="post-metadata">

**Author:** ![Railroader](https://dub1.discourse-cdn.com/arduino/user_avatar/forum.arduino.cc/railroader/32/274550_2.png) [@Railroader](https://forum.arduino.cc/u/Railroader)\
**Post date:** [August 10, 2021, 9:45pm UTC](https://forum.arduino.cc/t/mini-project-arduino-code-help/894352/5 "2021-08-10T21:45:36Z")

</div>

Will this be satisfactory?

```cpp
//Parameters
const int micPin = A0;
const int micPin2 = A1;

//Variables
int micVal = 0;
int micVal2 = 0;

void setup() {
  //Init Serial USB
  Serial.begin(9600);
  Serial.println(F("Initialize System"));
  //Init Microphone
  pinMode(micPin, INPUT);
  pinMode(micPin2, INPUT);
}

void loop() {
  readMicrophone();
  readMicrophone2();
}

void readMicrophone( ) { /* function readMicrophone */
  ////Test routine for Microphone
  micVal = analogRead(micPin);
  Serial.print(F("mic val ")); Serial.println(micVal);
  if (micVal > 600) {
    Serial.println("mic detected");
  }
}
void readMicrophone2( ) { /* function readMicrophone2 */
  ////Test routine for Microphone2
  micVal2 = analogRead(micPin2);
  Serial.print(F("mic val2 ")); Serial.println(micVal2);
  if (micVal2 > 600) {
    Serial.println("mic2 detected");
  }
}

```

---

<div class="post-metadata">

**Author:** ![JennYoung](https://dub1.discourse-cdn.com/arduino/user_avatar/forum.arduino.cc/jennyoung/32/643794_2.png) [@JennYoung](https://forum.arduino.cc/u/JennYoung)\
**Post date:** [August 11, 2021, 1:53pm UTC](https://forum.arduino.cc/t/mini-project-arduino-code-help/894352/7 "2021-08-11T13:53:20Z")

</div>

I appreciate your response. Thank you 🙂 .. Yes I am new to coding.

---

<div class="post-metadata">

**Author:** ![JennYoung](https://dub1.discourse-cdn.com/arduino/user_avatar/forum.arduino.cc/jennyoung/32/643794_2.png) [@JennYoung](https://forum.arduino.cc/u/JennYoung)\
**Post date:** [August 11, 2021, 1:54pm UTC](https://forum.arduino.cc/t/mini-project-arduino-code-help/894352/8 "2021-08-11T13:54:45Z")

</div>

Sure will do this next time.

---

<div class="post-metadata">

**Author:** ![JennYoung](https://dub1.discourse-cdn.com/arduino/user_avatar/forum.arduino.cc/jennyoung/32/643794_2.png) [@JennYoung](https://forum.arduino.cc/u/JennYoung)\
**Post date:** [August 11, 2021, 1:57pm UTC](https://forum.arduino.cc/t/mini-project-arduino-code-help/894352/9 "2021-08-11T13:57:48Z")

</div>

Thank you so much. Much appreciated.. The code worked.  
Is there a way to get two graphs? So that it's easier to detect the sound obtained in each sensor?  
The image uploaded below is what I get in the serial plotter.

 ![image](https://europe1.discourse-cdn.com/arduino/original/4X/5/c/7/5c7e1afe1af94460f46520d729a6d5c73ea1e9b2.png)

---

<div class="post-metadata">

**Author:** ![alto777](https://dub1.discourse-cdn.com/arduino/user_avatar/forum.arduino.cc/alto777/32/317385_2.png) [@alto777](https://forum.arduino.cc/u/alto777)\
**Post date:** [August 11, 2021, 3:50pm UTC](https://forum.arduino.cc/t/mini-project-arduino-code-help/894352/10 "2021-08-11T15:50:25Z")

</div>

You can print multiple values to the serial potter and it will draw them in different colors. If the data is well behaviour, the auto scaling isn’t a problem. I sometimes just write constants at the extremes to keep it from juggling the scale, like lower than the minimum and higher than the max you expect to see.

You can screen grab, obvsly, or do a run and capture the data and use it i a program that produces graphs. I use Open Office spreadsheet, which isn’t Excel and is cheaper and isn’t Microsoft, that’s just me. Cheap and bitter.

a7

---

<div class="post-metadata">

**Author:** ![flashko](https://avatars.discourse-cdn.com/v4/letter/f/f04885/32.png) [@flashko](https://forum.arduino.cc/u/flashko)\
**Post date:** [August 11, 2021, 7:00pm UTC](https://forum.arduino.cc/t/mini-project-arduino-code-help/894352/11 "2021-08-11T19:00:30Z")

</div>

For several variables with labels.  
[https://dreamonward.com/2020/07/25/arduino-serial-plotter-labels/](https://dreamonward.com/2020/07/25/arduino-serial-plotter-labels/)

> <https://github.com/arduino/Arduino/blob/ba34eb640e5f6c2f8618debf61022f731c0eab74/build/shared/ArduinoSerialPlotterProtocol.md>

---

<div class="post-metadata">

**Author:** ![alto777](https://dub1.discourse-cdn.com/arduino/user_avatar/forum.arduino.cc/alto777/32/317385_2.png) [@alto777](https://forum.arduino.cc/u/alto777)\
**Post date:** [August 11, 2021, 10:41pm UTC](https://forum.arduino.cc/t/mini-project-arduino-code-help/894352/12 "2021-08-11T22:41:54Z")

</div>

Nice.

I’ve only ever used plotting comma separated values, the simplest syntax from your chart.

a7

---

<div class="post-metadata">

**Author:** ![system](https://dub1.discourse-cdn.com/arduino/user_avatar/forum.arduino.cc/system/32/1140315_2.png) [@system](https://forum.arduino.cc/u/system)\
**Post date:** [December 9, 2021, 10:42pm UTC](https://forum.arduino.cc/t/mini-project-arduino-code-help/894352/13 "2021-12-09T22:42:43Z")

</div>

Closed on December 9, 2021, 10:42pm UTC

This topic was automatically closed 120 days after the last reply. New replies are no longer allowed.
