cancel
Showing results for 
Search instead for 
Did you mean: 

Issue with a black pill board programmed via the Arduino IDE

robotics_beginner
Associate II

Hello, all. I am currently trying to program a black pill board to print out the output from a sound sensor, for which I use the Arduino IDE 2.3.2. 

Used components:

- STM32F411CEU6 black pill
- KY-037 sound sensor

Current connections:

- the "G" pin from the sensor is connected to the "GND" pin on the black pill
- the "+" pin from the sensor is connected to the "3v3" pin on the black pill
- the "A0" pin from the sensor is connected to the "A9" pin on the black pill

The code:

 

 

#define DIGITAL_INPUT PA9

void setup() {
  Serial.begin(9600);
  pinMode(DIGITAL_INPUT, INPUT);
}

void loop() {
  Serial.println(analogRead(DIGITAL_INPUT));
}

 

 

This code prints out values around 270-290 and it doesn't seem like creating any loud noises has any effect on the output, and neither does changing the potentiometer on the sensor itself. What I am trying to get is an output that has a clear and visible change between different amounts of noise. I am starting to think that the current output is just the floating value of the "A9" pin.

Other relevant info:

- I believe the problem isn't in the black pill itself, since I can successfully implement a simple "blink" functionality.
- I have already adjusted the potentiometer on the sensor so that the L2 is off. It turns on briefly when it detects a noise (such as clapping or anything louder).
- Changing the pin from "A9" outputs values from different ranges, but those values still don't seem to be affected by any noise, no matter how loud.
- The values don't change if "A9" is connected to the "A0" pin on the sensor instead of "D0".

If anyone can offer some assistance, I would majorly appreciate it.

1 ACCEPTED SOLUTION

Accepted Solutions
robotics_beginner
Associate II

I double-checked the contact on the black pill pins and it seems that it fixed the issue. Apparently the contacts on all the pins were a bit weak, so I reinforced them a bit and now I am getting an actual output. Now I get values around 690 in silence, with different jumps in value depending on the sounds I make. I can't believe it was such a trivial thing afterall.

I appreciate you all helping me out and I wish you the best of luck in your future endeavors. Have a great day!

View solution in original post

7 REPLIES 7
robotics_beginner
Associate II

Quick correction for the last point in other relevant info. The values don't change if "A9" is connected to the "D0" pin on the sensor instead of "A0".

The sensors seems to.give high or low. So  you should not use analog read.  Chek with a multimeter if the output changes.      https://www.arduino.cc/reference/en/language/functions/digital-io/digitalread/

If you feel a post has answered your question, please click "Accept as Solution".
mwalt.3
Associate III

Hi , you need to use an analog pin

I already am. Is A9 not analog?

What do you mean "high or low"? The sensor has both an analog output pin and a digital one. If I use digitalRead, I just get a constant output of "0", even when I can clearly see that L2 is on.


@robotics_beginner wrote:

I already am. Is A9 not analog?


https://stm32world.com/wiki/Black_Pill 

robotics_beginner
Associate II

I double-checked the contact on the black pill pins and it seems that it fixed the issue. Apparently the contacts on all the pins were a bit weak, so I reinforced them a bit and now I am getting an actual output. Now I get values around 690 in silence, with different jumps in value depending on the sounds I make. I can't believe it was such a trivial thing afterall.

I appreciate you all helping me out and I wish you the best of luck in your future endeavors. Have a great day!