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:
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:
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:
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?