Servo Motor Probem for making both Move Opposite ways

Post here about your Arduino projects, get help - for Adafruit customers!

Moderators: adafruit_support_bill, adafruit

Please be positive and constructive with your questions and comments.
User avatar
animefruit
 
Posts: 332
Joined: Tue Feb 25, 2020 1:04 pm

Re: Servo Motor Probem for making both Move Opposite ways

Post by animefruit »

Ok.
That is great.
Thanks for the links.
I got the bigger one and it says it will get here tomorrow.
So if that is true I will be able to test it out with that code tomorrow.

User avatar
animefruit
 
Posts: 332
Joined: Tue Feb 25, 2020 1:04 pm

Re: Servo Motor Probem for making both Move Opposite ways

Post by animefruit »

I tested out the big servo you recommended me and it seems to work way better.

It doesn't do any weird turning it not supposed to be doing.

When I tell it to move 90 degrees on the Arduino Sweep Sketch only in the "setup" part of the code, it moves 90 degrees and moves the opposite direction of 90 degrees, and than it stops just like it should.

So it working well right now, but I will ask you questions if I have any more problems.

User avatar
adafruit_support_bill
 
Posts: 88096
Joined: Sat Feb 07, 2009 10:11 am

Re: Servo Motor Probem for making both Move Opposite ways

Post by adafruit_support_bill »

Good to hear that is working for you. Thanks for the update.

User avatar
animefruit
 
Posts: 332
Joined: Tue Feb 25, 2020 1:04 pm

Re: Servo Motor Probem for making both Move Opposite ways

Post by animefruit »

Hey Bill. This is Neal Again.

I got done with the servo part of my project, at least for now.

I am now trying to get my sensors to work better.

I use piezo sensors to sense the pressure.

I am trying to mount the piezo sensors to materials so that it acts as a bigger sensor.

But I don't know what I am supposed to use necessarily.

I actually found other websites that show how to make nerf gun sensors briefly, but I don't know if I should use the same things for my project.

Also, just so you know, my sensors are supposed to be on a vest that people are supposed to wear for a tagging game with nerf guns, while these sensors from these websites are not necessarily supposed to be worn.


In this website they say to use sheet steel:

https://hackaday.com/2013/08/14/reactiv ... rsoft-etc/


In this website they say to use a thin plastic picture frame:



https://github.com/mcoms/nerf-target

In this one they say to use cardboard or any support the person wants:

https://www.google.com/amp/s/ http: ... e=true


I actually tried a cardboard box, and it didn't work too much differently than right now

Although, I did not try out using sheet steel or a picture frame.


What do you think I should do for my piezo sensor targets?

User avatar
adafruit_support_bill
 
Posts: 88096
Joined: Sat Feb 07, 2009 10:11 am

Re: Servo Motor Probem for making both Move Opposite ways

Post by adafruit_support_bill »

For something wearable, I would avoid sheet metal because of possible injury from the edges. Rigid cardboard should work, but plastic would be more durable.

How big do the targets need to be? What kind of cardboard are you using and what are the problems you are having with it?

User avatar
animefruit
 
Posts: 332
Joined: Tue Feb 25, 2020 1:04 pm

Re: Servo Motor Probem for making both Move Opposite ways

Post by animefruit »

My targets are around 5 inches in width and around 7 inches in length.

You can also see roughly how big they are in inches in my image I attached.

I have different targets I made.

The first ones I made have pezio sensors taped to the back of hard plastic I cut out from a hard plastic cover of a note book.

The difference between them is that one pezio sensor is taped with the white side of it facing up , which is the last target in the image, and the other is with the golden side of the pezio sensor facing up, which is the 2nd target in the image.

I couldn’t tell what side of the pezio sensor is supposed to be facing up.

Does it matter?

The problems with those is that some parts of the sensors don’t register when I press them sometimes.

I also taped a pezio sensor to the inside of a thin light cardboard box and tested that out.

This target is the first target in the image.

This one still doesn’t seem to register to much more than my other pezio sensors that just have notebook cover plastic over them.

I also improved this problem by adding beads around and on the sensor.

The point of that was to add pressure on the sensor when pressed, and the bead that directly hits the sensor seems to really help a lot.
But it still seem like it doesn’t register in some areas sometimes.

I did this with two of the sensors.


One was with harder plastic from a cover of a notebook , which is the 3rd target on the image, and one was with more bendy standard number 1 plastic, which is the second to last target in the image.

The one with standard number 1 plastic seems to work better than all of the targets, but it still doesn’t always register when I press it some areas of it.

What would you recommend me to do for my targets?
Attachments
018C5265-AFB9-49CE-964E-6F7425BCDBEE.jpeg
018C5265-AFB9-49CE-964E-6F7425BCDBEE.jpeg (721.09 KiB) Viewed 175 times

User avatar
adafruit_support_bill
 
Posts: 88096
Joined: Sat Feb 07, 2009 10:11 am

Re: Servo Motor Probem for making both Move Opposite ways

Post by adafruit_support_bill »

What is behind the sensors? It looks like they are taped to a board of some kind. You should have something soft behind it so that the sensor can move when hit.

Please post the code you are using - and also a circuit diagram so we can see how the piezo sensors are connected.

User avatar
animefruit
 
Posts: 332
Joined: Tue Feb 25, 2020 1:04 pm

Re: Servo Motor Probem for making both Move Opposite ways

Post by animefruit »

The pezio sensors are taped to the back of plastic and the plastic is taped to cardboard.

I don't think cardboard is soft enough.

I will have to put something softer behind them.

Also, does it do anything to my piezo sensors if they are all connected to the same pin?

Would it help for them to be separated in smaller groups to each pin, rather than having them all connect to one pin?

I was thinking of connecting 10 of them onto the same pin.

I found this link and it says that you shouldn't connect a bunch of sensors to one pin because it wouldn't be able to filter the signals.

I don' know what they mean by "filtering the signals" but do I need to filter my signals?

I would think I would not need to filter my signals because I want to make it to where when any of the piezo sensors are hit than it will count toward subtracting a number.

Here is the link:
https://www.quora.com/What-is-the-way-t ... -nanoboard


Here is my code:

Code: Select all

  #include <Servo.h>
#include "Wire.h"
#include "Adafruit_LiquidCrystal.h"


Adafruit_LiquidCrystal lcd(0);

Servo myservo1;
Servo myservo2;

const int knockSensor = A0;

const int threshold = 50;
int health = 500;
int sensorReading = 0;


int pos =0;


void setup()

{
  pinMode(LED_BUILTIN, OUTPUT);

  Serial.begin(9600);
  Serial.println("Nerf Target v0.0.1, github.com/mcoms/nerf-target, 2014.");

// sg90

  lcd.begin (20 , 4);
  lcd.clear();


  Serial.begin(9600);
  myservo1.attach(9);
  myservo1.write(0);//was 0

  myservo2.attach(10);
  myservo2.write(45);//was 179




}

void loop()
{
  do
  {


    myservo1.detach();
    myservo2.detach();

    sensorReading = analogRead(knockSensor);


    lcd.setCursor(0, 1);
    Serial.println(health);
    lcd.println(health);

    if (sensorReading > threshold) {

      Serial.println("Knock!");
      health = health - sensorReading;




      Serial.print(sensorReading);
      lcd.print(sensorReading);


      int sensorValue = analogRead(A0);

      Serial.println(sensorValue);
      delay(1);

    }


  } while (health > 1);
  digitalWrite(LED_BUILTIN, HIGH);
  delay(2000);//was 2000
  digitalWrite(LED_BUILTIN, LOW);
  delay(1000);
  myservo1.attach(9);
  myservo2.attach(10);

  delay(15);

 for (pos = 0; pos <= 180; pos += 1) { // goes from 0 degrees to 180 degrees
    // in steps of 1 degree
    myservo1.write(pos);              // tell servo to go to position in variable 'pos'
    delay(15);                       // waits 15 ms for the servo to reach the position
  }
  for (pos = 180; pos >= 0; pos -= 1) { // goes from 180 degrees to 0 degrees
    myservo1.write(pos);              // tell servo to go to position in variable 'pos'
    delay(15);                       // waits 15 ms for the servo to reach the position
  }

 delay(1000);

  health = 500;
}   

I will send you my diagram in a separate post.

User avatar
animefruit
 
Posts: 332
Joined: Tue Feb 25, 2020 1:04 pm

Re: Servo Motor Probem for making both Move Opposite ways

Post by animefruit »

Here is a diagram a drawn based on what my devices are connected to in the image below:
Attachments
EF9C0EE8-8309-4835-9EF4-3A738D5DC55E.jpeg
EF9C0EE8-8309-4835-9EF4-3A738D5DC55E.jpeg (324.29 KiB) Viewed 158 times

User avatar
adafruit_support_bill
 
Posts: 88096
Joined: Sat Feb 07, 2009 10:11 am

Re: Servo Motor Probem for making both Move Opposite ways

Post by adafruit_support_bill »

Also, does it do anything to my piezo sensors if they are all connected to the same pin?

Would it help for them to be separated in smaller groups to each pin, rather than having them all connect to one pin?

I was thinking of connecting 10 of them onto the same pin.
A piezo sensor is like a capacitor. So if you connect them in parallel, when one is hit, part of the signal will be absorbed by the others. You will get better response if you use one pin for each sensor.

And you should remove all the unnecessary code from your 'do' loop. The servo detach and the serial output and display updating takes time and you will miss some hits. You want to just do analog reads as fast as possible to make sure you don't miss anything.

This code:

Code: Select all

  do
  {


    myservo1.detach();
    myservo2.detach();

    sensorReading = analogRead(knockSensor);


    lcd.setCursor(0, 1);
    Serial.println(health);
    lcd.println(health);

    if (sensorReading > threshold) {

      Serial.println("Knock!");
      health = health - sensorReading;




      Serial.print(sensorReading);
      lcd.print(sensorReading);


      int sensorValue = analogRead(A0);

      Serial.println(sensorValue);
      delay(1);

    }

  } while (health > 1);
can be replaced with something like:

Code: Select all

	do
	{
		sensorReading = analogRead(knockSensor);
		if(sensorReading > threshold)
		{
			Serial.println("Knock!");
			health = health - sensorReading;
			Serial.print(sensorReading);
			lcd.print(sensorReading);
		}
	}
	while (health > 1);
If you really need to detach the servos, you can do that at the end of your main loop() function.

User avatar
animefruit
 
Posts: 332
Joined: Tue Feb 25, 2020 1:04 pm

Re: Servo Motor Probem for making both Move Opposite ways

Post by animefruit »

Ok. I did that and it seems to work better.

I have another problem though.

My Battery Pack I use doesn’t hold my battery’s very well together, although it did when I first used it.

Whenever I shake it a little bit the batteries move inside and whenever I turn it upside down with the lid off the batteries fall out.

Is there any way to fix my battery pack or can I get a more secure battery pack or a battery pack that doesn’t have to use batteries such as a rechargeable battery pack?


What would you recommend?

Just so you know the battery pack I am using right now is one of these from these 2 links:


https://www.amazon.com/gp/product/B00HR ... UTF8&psc=1


https://www.amazon.com/gp/product/B075G ... UTF8&psc=1

User avatar
adafruit_support_bill
 
Posts: 88096
Joined: Sat Feb 07, 2009 10:11 am

Re: Servo Motor Probem for making both Move Opposite ways

Post by adafruit_support_bill »

The plastic locking tabs on those do tend to wear out over time. You could wrap a strip of velcro around the pack for a temporary fix.

You should be able to find a 6v rechargeable NiMH pack. Check with the battery specialist sites or an RC hobby shop.

User avatar
animefruit
 
Posts: 332
Joined: Tue Feb 25, 2020 1:04 pm

Re: Servo Motor Probem for making both Move Opposite ways

Post by animefruit »

That sounds great. But is 6V too much for an Arduino Nano?

I thought Arduino Nanos could only run on 5V.

I see some that are 4.8V.

Would 4.8 V be better?

User avatar
adafruit_support_bill
 
Posts: 88096
Joined: Sat Feb 07, 2009 10:11 am

Re: Servo Motor Probem for making both Move Opposite ways

Post by adafruit_support_bill »

Nanos have an on-board voltage regulator which regulates your battery voltage down to 5v.

Your current battery pack is also a 6v pack: Each AA alkaline battery is 1.5v and 4x 1.5v = 6v.

User avatar
animefruit
 
Posts: 332
Joined: Tue Feb 25, 2020 1:04 pm

Re: Servo Motor Probem for making both Move Opposite ways

Post by animefruit »

Ok. That would be great.

But can I solder the rechargeable NiMH pack to my Arduino Nano?

I don’t think it is solderable.

If not, can you recommend me a rechargeable battery pack that I can solder to my Arduino Nano?

I was wondering if a LiPo battery would be great, or do you recommend something else?

Locked
Please be positive and constructive with your questions and comments.

Return to “Arduino”