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);
}
}
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
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 Idon't know
Which Arduino are you using ?
Your answer to Question 3: im using the uno
Is servo_0 really attached to pin 0 ?
Your answer to question 4: idk (I assume "idk" means Idon't know
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?
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);
}
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?
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.