Pages: [1]   Go Down
Author Topic: HELP ME!!! Desperation!  (Read 651 times)
0 Members and 1 Guest are viewing this topic.
Offline Offline
Newbie
*
Karma: 0
Posts: 3
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

Hello arduino users! I am trying to get two servos to activate and respond to a knock sensor but CANNOT DO IT! I have scoured the web for code possibilities or anything of the sort but, clearly, have been unsuccessful. I am able to get both servos moving as I would like, but NEED them to only activate for a short time (3 seconds or so) by means of a knock sensor.

Any help in this matter would be greatly appreciated... this is for a group design project and we are all stumped!

THANKS!
Logged

0
Offline Offline
Sr. Member
****
Karma: 1
Posts: 360
I'm 15. I like making things. I like breaking things better.
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

Do you have any code written?  If you can move a servo, just use this knock sensor code: http://www.arduino.cc/en/Tutorial/Knock but instead of changing the led state, move the servo.
Logged

Alice asked the Chesire Cat, who was sitting in a tree, "What road do I take?"
The cat asked, "Where do you want to go?"
"I don't know," Ali

Offline Offline
Newbie
*
Karma: 0
Posts: 3
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

OK- we have found that code and have been using it as a guide, yet we are confused about replacing the ledPin code with our servo code. Do you have any pointers?

Thank you!
Logged

0
Offline Offline
Sr. Member
****
Karma: 1
Posts: 360
I'm 15. I like making things. I like breaking things better.
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

Yes. Replace the line that toggles the led with the line to move the servo.
Logged

Alice asked the Chesire Cat, who was sitting in a tree, "What road do I take?"
The cat asked, "Where do you want to go?"
"I don't know," Ali

Offline Offline
Newbie
*
Karma: 0
Posts: 3
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

Ok- thank you again! We tried toggling our servo code:

#include <Servo.h>
Servo first; // create servo object
Servo second; // create servo object
int firstservopin = 8;                               // digital output to which signal wire(yellow) of first servo is connected
int secondservopin= 7;                      //  digital output to which signal wire(yellow) of second servo is connected
void setup() {
  first.attach(firstservopin); // attach the servo to digital output 8
  second.attach(secondservopin); // attach the servo to digital output 7
  first.write(90); // center the servo
   second.write(90); // center the servo
   delay(1000);
}
void loop() {
 
  first.write(0);                        // move first servo to pos 0
  second.write(0);                 // move second servo to pos 0
  delay(1000);
  first.write(120);               // move first servo to pos 120
  second.write(120);         // move second servo to pos 120
  delay(1000);
}



With the example led knock sensor code, but we still have been unsuccessful after many attempts and are very frustrated! Everything is connected the way it should be, we still are unable to get the servos to respond to the knock sensor

Thank you 
Logged

0
Offline Offline
Newbie
*
Karma: 0
Posts: 10
Arduino rocks
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

Have you gotten the knock sensor to work by itself? It's usually a good idea to get each component working before you start merging them.

If you're able, test your knock sensor to find your ideal threshold. This can be done by using a Serial.print(sensorReading); and watching the serial monitor in the Arduino IDE

Once you've established the threshold, it's time to merge all of the components. I would imagine it would look something like this:

Code:
#include <Servo.h>

//Servo
Servo first; // create servo object
Servo second; // create servo object
#define firstservopin 8
#define secondservopin 7

//Knock Sensor
#define knockSensor A0
const int threshold = 100; //Sensitivity of the Knock Sensor
int sensorReading;

void setup() {
  first.attach(firstservopin); // attach the servo to digital output 8
  second.attach(secondservopin); // attach the servo to digital output 7
  first.write(90); // center the servo
  second.write(90); // center the servo
}

void loop() {
  sensorReading = analogRead(knockSensor);
  
  if (sensorReading >= threshold) {    
    first.write(0);                        // move first servo to pos 0
    second.write(0);                 // move second servo to pos 0
    delay(1000);
    first.write(120);               // move first servo to pos 120
    second.write(120);         // move second servo to pos 120
    delay(1000);
  }
}

Logged

Pages: [1]   Go Up
Jump to: