Go Down

Topic: Motor and sensor (Read 797 times) previous topic - next topic

Swaggydogy

Apr 15, 2018, 01:15 pm Last Edit: Apr 15, 2018, 10:30 pm by Swaggydogy
Hi everyone my name is swaggydogy and iam here to ask for some advices...

Im on a current project with arduino witch i meet some issue.

Im using on this project an motor, a LED and a sensor.

The idea between this is that i want to make a machine like this:



So i'll explain there is a circle platform(in dark blue) witch is paste to the top of the motor ( the white objet) all i want to make it rotate, turn the platform with motor.

But i want the motor to make 90° rotation...

So the sensor ( the blue one) will detect the red box and make a signal.
The red box are placed in the corner of the platform, next to the little circle, just to symbolize the 90° degry of the retation.

All i want is to the beggining, the motor is already on, the motor turn but when the sensor detect something (it's mean the red box) it will make the motor off, stop rotate.

Of course if nothing is detected yet, the motor will still rotate.


Here the image of the circuit, i have to tell that the circuit and also the code are combination of other circuit, code.

For the circuit, here are the models of circuit that I have used:

For the sensor:



For the motor:



And here my circuit:


--------

About the code here are the model's code:

for the sensor:

Code: [Select]
const int buttonPin = 2; // broche du capteur PIR
const int ledPin = 12; // la LED du Arduino
int buttonState = 0; // etat de la sortie du capteur
 
void setup()
{
  pinMode(ledPin, OUTPUT); //la broche de la LED est mise en sortie
  pinMode(buttonPin, INPUT); //la broche du capteur est mise en entree
}
 
void loop()
{
  buttonState = digitalRead(buttonPin);//lecture du capteur
  if (buttonState == HIGH) //si quelquechose est detecte
  {
    digitalWrite(ledPin, HIGH); //on allume la LED
  }
  else //sinon
  {
    digitalWrite(ledPin, LOW); //on eteint la LED
  }
}


for the motor:

Code: [Select]
void setup() {
  pinMode(3, OUTPUT);
}

void loop() {
  for (int i = 0; i = 50; i++) {
    analogWrite(3, i);
    delay(10);
  }
  
}



And now here is my code for my machine:

Code: [Select]
const int buttonPin = 2; // brooch for sensor PIR
const int ledPin = 12; //  the LED Arduino
int buttonState = 0; // statut of exit of the sensor

void setup() {
 pinMode(3, OUTPUT);
 pinMode(ledPin, OUTPUT); //brooch of the LED out put
 pinMode(buttonPin, INPUT); //brooch of the sensor in enter
}

void loop() {
 for (int i = 0; i = 50; i++) // we turn the motor
   {
   analogWrite(3, i);
   delay(10);
   }
 buttonState = digitalRead(buttonPin);// reading of the sensor
 if (buttonState == HIGH) // if something is detected
 {
   digitalWrite(ledPin, HIGH); // LED on
   for (int i = 50; i = 0; i++) // We stop the rotation of the motor
   {
   analogWrite(3, i);
   delay(10);
 }
 }
}




---------


Here that all, however the final code ( the last one ) doesn't work properly, it does make the motor on but the detection of the sensor doesn't make the motor stop rotate...

Can you help me out?

Robin2

You have posted your code but you have not told us what it actually does and what you want it to do that is different.

To make it easy for people to help you please use the code button </>
Code: [Select]
so your code looks like this and is easy to copy to a text editor. See How to use the Forum

...R
Two or three hours spent thinking and reading documentation solves most programming problems.

juma_yetu

I get a 410 Page Expired on that link: rather attach the pic to the thread, not expect others to traipse off to other sites, especially if it doesn't work ;)




TomGeorge

Hi,
Welcome to the forum.

Please read the first post in any forum entitled how to use this forum.
http://forum.arduino.cc/index.php/topic,148850.0.html then look down to item #7 about how to post your code.
It will be formatted in a scrolling window that makes it easier to read.

Can you please post a copy of your circuit, in CAD or a picture of a hand drawn circuit in jpg, png?

Thanks.. Tom.... :)
Everything runs on smoke, let the smoke out, it stops running....

Swaggydogy

i don't know how to put an image i try  with ImgBB but it doesn't show up...

wvmarle

You have to attach an image to your post, then you can go and edit your post to have it show up. Yes it's cumbersome. See this image guide.
You should be able to use the same tags for externally hosted images, but you rather attach it to the post to make sure it continues to show in the posts as long as the Arduino site itself is alive.
Quality of answers is related to the quality of questions. Good questions will get good answers. Useless answers are a sign of a poor question.

TomGeorge

Hi,
Make sure your image is less than 1M in size and/or about 750pixels wide and or high.

jpg or png.

Look at the help link about how to attach a file to your post.

Tom... :)
Everything runs on smoke, let the smoke out, it stops running....

Swaggydogy

ok i gonna remove this topic to met a new thank for the help about the image

Robin2

ok i gonna remove this topic to met a new thank for the help about the image
I don't understand what you mean, but please don't start another Thread about the same problem. Just continue with this one.

...R
Two or three hours spent thinking and reading documentation solves most programming problems.

Swaggydogy

but i need that people see a clean topic quickly...

kishalay

Use a ir proximity sensor instead of pir the code will be very easy ur main motive s to stop the moto when u detect anything obstruction

Robin2

but i need that people see a clean topic quickly...
All you need for that is to post the new information in the next Reply - the one people will be reading next. You can always edit your Original Reply and add "Please Skip to Reply NN"

...R
Two or three hours spent thinking and reading documentation solves most programming problems.

Robin2

You have added a lot of stuff in your Original Post which now makes several of the comments look ridiculous to a new reader.

You have not told us what sensor you are using - post a link to its datasheet.

Also,
  • what size is the machine?
  • What size are the red pillars that need to be detected?
  • How far from the pillars is the detector?
  • How fast will the pillars be rotating?

...R
Two or three hours spent thinking and reading documentation solves most programming problems.

Swaggydogy

#13
Apr 15, 2018, 10:29 pm Last Edit: Apr 15, 2018, 10:34 pm by Swaggydogy
first of all I really sorry Robin2, i have make all clear to the original topic and it's make all the other comment useless...

And about the sensor, well in the project im on... I use an IR sensor but in tinkercad with the circuit only the PIR sensor work similar to an regular IR sensor...

The code that i put to it was in origin, an programm that work for an IR sensor.

Also about the red pillar and the distance, it's doesn't matter, all you need is that it could detect.

About the speed of the motor.

I want to make a regular speed witch is not really fast to give the time for the sensor to detect and not to slow to rotate not too slow to the point.


And dear kishalay:  The PIR sensor in the circuit was only to see if the code work with Tinkercad.
Tinkercad is an site witch is really good for make simulation for arduino, 3D models, and circuit.

In fact the code that i trying to make is a code the more simple ways witch it could work correctly in my project.

About the cricuit it's just a way to represent the circuit the system. Only the code it's important.

wvmarle

first of all I really sorry Robin2, i have make all clear to the original topic and it's make all the other comment useless...
What is worse: I for one, subscribed to this topic already, DIDN'T EVEN NOTICE THIS until it was mentioned in the comments.

So you're providing new information, but quite a few of the people that actually try to offer help simply won't see it this way. I'm reading NEW replies which is where I expect to find new information, not going back in threads to see whether there happens to be changes to those posts.

OK now I've read the OP again, and it raises indeed more questions than it answers.
What is this sensor, really? Code suggests PIR sensor but those won't detect a metal pillar, they detect movement of warm objects such as people and other warm-blooded animals, cars, etc.
How do you stop (and hold) the motor and platform at the correct point? Just cutting power won't make it stop there and then, just slow down gradually until it comes to a stop.
Quality of answers is related to the quality of questions. Good questions will get good answers. Useless answers are a sign of a poor question.

Go Up