Need help with coding

Last night(for me) I spent 3 hours in front of my computer, wiring, and programming, although I have no idea how to program, so I ended up yoinking some code from the internet. I need help with my coding, so can anyone out there combine these two codes for me? My build is a motion-activated sensor that activates a servo motor.
Sensor code

const int soundPin = A0; //sound sensor attach to A0
int threshold = 600; //Set minimum threshold for LED lit
void setup()
{
  pinMode(ledPin, OUTPUT); //set pin13 as OUTPUT
  Serial.begin(9600); //initialize serial
}
void loop()
{
  int value = analogRead(soundPin);//read the value of A0
  Serial.println(value);//print the value
  if (value > threshold) //if the value is greater than 600
  {
    digitalWrite(ledPin, HIGH); //turn on the led
    delay(200);//delay 200ms
  }
  else
  {
    digitalWrite(ledPin, LOW); //turn off the led
  }
  delay(1000);
}

Motor code

//
#include <Servo.h>

int i = 0;

int postision = 0;

int j = 0;

Servo servo_0;

Servo servo_9;

void setup()
{
  servo_0.attach(0, 500, 2500);

  servo_9.attach(9, 500, 2500);

}

void loop()
{
  postision = 0;
  for (i = 1; i <= 90; i += 1) {
    servo_0.write(postision);
    delay(50); // Wait for 50 millisecond(s)
  }
  for (postision = 90; postision >= 1; postision -= 1) {
    servo_9.write(postision);
  }
}

What does the combined code have to do?

That's a really bad idea - it limits your debug options.

What should the combined sketch do ?

How are the motor and servos powered ?
Which Arduino are you using ?
Is servo_0 really attached to pin 0 ?
Why isn't ledPin declared anywhere ?

Is there anything you can do? I'm very new to arduino so I dont know what to do.

I can do lots of things, but I have to know what the ultimate aim is.

question 1: The combined sketch will activate the sound sensor and when the sound sensor gets a signal it activates the servo motor.
Question 2 :idk
Question 3: im using the uno
question 4: idk
Question 5:its built in on the sound sensor

You need to tell us what "activate" means.

My ultimate aim is to build a sound activated servo

it means that when the sound sensor gets a signal it will turn on the servo, so it will move.

Have you got the sketch with the sound sensor and the LED working ?

Hi paxid,

Bob was asking some questions:

  1. What should the combined sketch do ?

your answer to question 1: The combined sketch will activate the sound sensor and when the sound sensor gets a signal it activates the servo motor.

How are the motor and servos powered ?
Your answer Question 2 :idk (I assume "idk" means I don't know

  1. Which Arduino are you using ?
    Your answer to Question 3: im using the uno

  2. Is servo_0 really attached to pin 0 ?
    Your answer to question 4: idk (I assume "idk" means I don't know

  3. Why isn't ledPin declared anywhere ?
    Your answer to Question 5:its built in on the sound sensor

Well ... is this a privately initiated project ?
or is this some kind of "school-project" you are forced to do but you don't like it?

How many days are left until this project shall be finished?

The answer you have been giving so far show that your programming-knowledge has a lot of room for improvement.

Are you willing to learn? My assumption is: No

This post talks about a motion-activated servo

Your last post talks about a sound activated servo.

well if you hoped for "I have to write some lines of code do some clicks and the the project is done within 2 or 3 hours.
The truth is: NO it is some more work.
If you don't like learning about elektonics and programming and have the chance to switch over to a completely different project do it!

If you are willing to pay 500 up 800 dollars you will find somebody who will do all the work for you.

If you are hoping for somebody who writes a complete program for you for free the minimum is to be clear about what sensors you are using providing a datasheet of the sensors
and give a detailed description in normal words what the functionality shall be
and to not hop around to say in one posting a motion-activated servo
and in another posting a sound activated servo.

On such unclearness everybody will react "this is my bottom! code it yourself!"

Until now your postings sound like
I don't feel like doing this shitty project at all.
Can someone do this for me?

1 Like

im making a wakeup system that splashes water on my face and I need to connect a sound sensor to the 5v plug, but unfortunately, the piece is already taken by a servo motor and I cannot turn on my sound sensor with the 5v. Also, if anyone knows the language I need help connecting this piece of code with a sound sensor code.
Servo code:
// C++ code
//
#include <Servo.h>

int i = 0;

int postision = 0;

int j = 0;

Servo servo_0;

Servo servo_9;

void setup()
{
servo_0.attach(0, 500, 2500);

servo_9.attach(9, 500, 2500);

}

void loop()
{
postision = 0;
for (i = 1; i <= 90; i += 1) {
servo_0.write(postision);
delay(50); // Wait for 50 millisecond(s)
}
for (postision = 90; postision >= 1; postision -= 1) {
servo_9.write(postision);
}
}

sound sensor code:
const int ledPin = 13; //pin 13 built-in led
const int soundPin = A0; //sound sensor attach to A0
int threshold = 600; //Set minimum threshold for LED lit
void setup()
{
pinMode(ledPin,OUTPUT);//set pin13 as OUTPUT
Serial.begin(9600); //initialize serial
}
void loop()
{
int value = analogRead(soundPin);//read the value of A0
Serial.println(value);//print the value
if(value > threshold) //if the value is greater than 600
{
digitalWrite(ledPin,HIGH);//turn on the led
delay(200);//delay 200ms
}
else
{
digitalWrite(ledPin,LOW);//turn off the led
}
delay(1000);
}

Are there any alternatives for the 5v

What is the consumption of this sound sensor? If its consumption is small you can try a pin(s) as a power supply for the sensor.


pinMode ( 4, OUTPUT ); digitalWrite ( 4, HIGH ); // Vcc for audio sensor
pinMode ( 8, OUTPUT ); digitalWrite ( 8, LOW ); // GND for audio sensor if needed

Or just make a branched cable to power the sound sensor as well.

idk. i have the link if you can see it

but, i think it might work with a 3.3v and all I need now is someone to combine the code. If you can do it, can you put the sound sensor to activate the motor, in this specific order?

Please paste your code using the specific format. Visit this link General Guidance and How to use the Forum

As for the 5v pin debacle, if at all the sound sensor cannot be powered with 3.3V (as far as I know it should work on 3.3V) you can solder a Y connector for the servo and sensor, and have both components powered by 5V.

Very confused about what I should do then pasting code on the forums. What buttons do I press and what do I do to get that weird text?

nvm ignore please