im just asking help bcz this is coming wrong for me. I am a beginner
You haven't explained your need well enough to solve it, so nobody can help you until you do. You are vague, "receives data" means what, from an analog port?
You receive data from an analog port, any time you read it. You must use complete, concise, descriptive language.
im totally dumb sir, please tell me mistakes that I have done in the code.
I kindly request that you post a complete wiring diagram so we can see how the sound sensors are connected. Please provide a link to the sound sensor specification.
This means:
- read A0
- throw the result from that in the garbage, and read A1 instead
What is this supposed to do? It doesn't make any sense.
...and... what do you want it to do when there is no sound?
I suggest you spend a day digesting the replies and researching your topic. Be careful when you back edit, not to destroy the meaning of other peoples replies by erasing the content they replied to.
Feel free to edit the ones that essentially just said, "help, help". Or better, only the last one you posted...
Hi Helpers,
I am beginner, so don't be angry with me as I will ask some silly questions. I am creating this project https://www.roboticskanti.com/post/how-to-make-sound-control-robot-eye... but with arduino uno instead. The code given by him is so tough to understand as well is not working with me. I have removed 2 servos from the code as it is of no use for me.
#include <Servo.h>
Servo servo;
//Sound variables
const int sampleWindow = 250; // Sample window width in mS (250 mS = 4Hz)
unsigned int sound;
void setup()
{
servo.attach(8);
Serial.begin(9600);
}
void loop()
{
int position = 0;
unsigned long start = millis(); // Start of sample window
unsigned int peakToPeak = 0; // peak-to-peak level
unsigned int signalMax = 0;
unsigned int signalMin = 1024;
// collect data for 250 miliseconds
while (millis() - start < sampleWindow)
{
sound = analogRead(A0) && (A1);
if (sound < 1024) //This is the max of the 10-bit ADC so this loop will include all readings
{
if (sound > signalMax)
{
signalMax = sound; // save just the max levels
}
else if (sound < signalMin)
{
signalMin = sound; // save just the min levels
}
}
}
peakToPeak = signalMax - signalMin;
double volts = (peakToPeak * 3.3) / 1024;
Serial.print("Volts:");
Serial.print("\t");
Serial.println(volts);
if (analogRead(A0) == volts >= 1.0)
{
for (position = 0; position <= 75; position += 5)
{
servo.write(position);
delay(20);
}
for (position = 75; position >= 0; position -= 5)
{
servo.write(position);
delay(20);
}
for (position = 0; position <= 75; position += 5)
{
servo.write(position);
delay(20);
}
for (position = 75; position >= 0; position -= 5)
{
servo.write(position);
delay(20);
}
delay(800);
}
if (analogRead(A1) == volts >= 1.0)
{
for (position = 75; position <= 0; position += 5)
{
servo.write(position);
delay(20);
}
for (position = 0; position >= 75; position -= 5)
{
servo.write(position);
delay(20);
}
for (position = 75; position <= 0; position += 5)
{
servo.write(position);
delay(20);
}
for (position = 0; position >= 75; position -= 5)
{
servo.write(position);
delay(20);
}
delay(800);
}
}
The above code has something volts and all. But my servo is not turning to any side. My servo goes to the initial position (90 degrees), but never turns to any other side. I have changed the servo to nano pin from 5 -> 8. everything else is same.
Schematics
Looking forward for your codingness...
Thanking You In Advance!
Please post schematics.
It's late in the day here, but i'm struggling to understand what this line of code is doing other than reading the analogue signal level on pin A0.
Are those microphone boards the same as the original author is using?
Have you calibrated them - I assume that's what the pot is for on the module in your fritzing drawing.
That is some creative syntax. Unfortunately it is it will always be true. You need to separate the comparisons. I am unsure of what that is supposed to do, but my guess is:
if ((analogRead(A0) == volts) && (analogRead(A0) >= 1.0))
Using equality (==) with float (double) data type is rarely going to work right. Read this thread.
Are the various mistakes and oddities that others have commented on in the original code?
If so you may want to find a better starting place.
You could use the original code without modifications - the UNO won't know or care that you haven't all the servos attached.
See how the original code works before you messing with it.
a7
You can rather easily destroy an Arduino by powering a motor or servo from the Arduino 5V pin.
Always use a separate power supply for servos (4xAA works well for 1 or 2 small servos), and don't forget to connect all the grounds.
duplicate post, flagged for moderation.
I have merged your posts due to them having too much overlap on the same subject matter @legendaryarduino .
In the future, please only create one topic for each distinct subject matter and be careful not to cause them to converge into parallel discussions.
The reason is that generating multiple threads on the same subject matter can waste the time of the people trying to help. Someone might spend a lot of time investigating and writing a detailed answer on one topic, without knowing that someone else already did the same in the other topic.
Thanks in advance for your cooperation.
You need to first just learn to read the sensor. Serial.println() your readings. In your first post, it looks like you tried to digitalRead() these sensors. Then you tried analogRead(), except the
line makes little sense. It's a 5 volt Arduino board, a 5 volt sensor and powered by 5 volts. Why multiply by 3.3? Just because that's what the code you copy-pasted had in it?
In your original post you said you wanted the servo to move 90 deg one way or 90 deg the other based on the sound sensors' readings but the code you pasted with the analogRead() for the sensors only moves the servo between 0 and 75 degrees in 5 degree increments. (which is as others here have pointed out unusual in it's own right - I wonder if the guy who posted the project was just pretending it worked, ie running a servo sweep script and snapping his fingers at the right time to make it look as though it was working as intended).
You really ought to first get the sensors reading the way you want them to, never mind the servo stuff yet. Just play around with the sound sensors until you have a range of values you can work with, then open a new sketch, copy that sketch into the new one of your own making and try your hand at adding the servo.write() stuff immediately after the sensor readings and Serial.println() that contain your known good sound readings.
Keep it simple. And never power a servo from the Arduino.
Good luck.
OMG BRO.... U just opened up my mind! Reading this made me to understand my mistake, as well as the fake play of the ytbr. Thank you so much. You made my day..
Also Thanking Everyone Who Helped Me (Even who replied)!!!
No problem.
This topic was automatically closed 180 days after the last reply. New replies are no longer allowed.