Isseu TimerOne and Servo.h and

ARDUINO UNO

i have make a robot that sud follow a blak line whit to stapper motors and a servo(from rc car) to pull up a hook and 2 light sensors to follow the line and 2 input to set the hook up an down whit the servo

the stapper motors have blod its onwn controller i need for bold the pulse generator to drive the motors and i use the enable input on this controller to run or stop it

evrting alloon workes but when i put it toghter in a program then only the servo works but no motor running.


#include <TimerOne.h>
const int outpin = 10; // genrate pulse
const int inpin = 3;      // leest pulse
int values = 0 ;//pulse values /// espected will be 0 (low) and 1 (high)

#include <Servo.h>
Servo myservo;
// Een variabele om de servo positie in te bewaren.
int pos = 0;

int sensoraPin = 8; // De schakelaar of drukknop zit op Pin 8.
int sensorbPin = 12; // De schakelaar of drukknop zit op Pin 12.
int sensorcPin = 4;  // lijn sensor links
int sensordPin = 7;  // lijn sensor rechts

int sensoraStatus = 0; // Een variabele voor de status van de schakelaar of knop.
int sensorbStatus = 0; // Een variabele voor de status van de schakelaar of knop.
int sensorcStatus = 0; // Een variabele voor de status van de lijn sensor
int sensordStatus = 0; // Een variabele voor de status van de lijn sensor
int duration, distance; //to measure the distance and time taken

void pulse(void);
void servo(void);
void rijd(void);

void setup() {
  Serial.begin(115200);

    pinMode(outpin, OUTPUT);
    pinMode(inpin,  INPUT);
   Timer1.initialize(2000); //tijds interval getal hoger dan lager de freuentie
   Timer1.pwm(outpin, 50); // send pulse to pin with a 50% duty cycle


  pinMode(13, OUTPUT);  // vrij bleutooht
  pinMode(12, INPUT);  // vrij bleuthoot
  pinMode(4,  INPUT);  // lijn sensor links
  pinMode(7,  INPUT);  // lijn sensor rechts
  pinMode(5,  OUTPUT);  // eneble step 1
  pinMode(11, OUTPUT);  //vrij
  pinMode(6,  OUTPUT);  // eneble step 2
  pinMode(8,  INPUT);
  pinMode(3,  INPUT);
  pinMode(10, OUTPUT);
  
  myservo.attach(6);
  


}

void loop () 
{
  pulse();
  servo();
  rijd();
}

void pulse () 
{

    values = digitalRead(inpin);
    Serial.print(values);
     Serial.println();
}


void servo () 
{



  sensoraStatus = digitalRead(sensoraPin); // Lees de status van de shakelaar of knop.
  sensorbStatus = digitalRead(sensorbPin); // Lees de status van de shakelaar of knop.
  sensorcStatus = digitalRead(sensorcPin); // lees lijn sensor
  sensordStatus = digitalRead(sensordPin); // lees lijn sensor

  if (sensoraStatus == LOW && sensorbStatus == HIGH  ) { // Als de ingang hoog is ( knop ingedrukt ):
    // Ga van 0 graden naar 180 graden in stapjes van 1 graad.
    for (; pos < 90; pos += 1) {
      // Draai naar de opgegeven positie.
      myservo.write(pos);
      // Wacht 15 milliseconden zodat de servo kan draaien naar de positie.
      delay(0);
    }
  }
  else  { // Zo niet..
    // Ga van 180 graden naar 0 graden in stapjes van 1 graad
    for (; pos >= 0; pos -= 1) {
      // Draai naar de opgegeven positie.
      myservo.write(pos);
      // Wacht 15 milliseconden zodat de servo kan draaien naar de positie.
      delay(0);
    }
  }
}
void rijd () 
{

  //line detected by both
  if ( sensorcStatus == HIGH && sensordStatus == HIGH ) {
    //run
    digitalWrite(5, LOW);
    digitalWrite(13, LOW);
  }

  //line detected by left sensor
  else if ( sensorcStatus == HIGH && sensordStatus == LOW) {

    digitalWrite(5, HIGH);
    delay(500);



  }
  //line detected by right sensor
  else if (sensorcStatus == LOW && sensordStatus == HIGH) {
    //turn right
    digitalWrite(13, HIGH);
    delay(500);


  }
  //line detected by none
  else if (sensorcStatus == LOW && sensordStatus == LOW) {
    //stop
    digitalWrite(5, HIGH);

    digitalWrite(13, HIGH);


  }
}


ARDUINO UNO (Vellerman)

Hello dtd01

Try and exclude the ussage of the TimerOne.h libary.

see trhe picture i have put on here

i need the pulse to drive (drive speed) the controller need a input pulse and a enable

its a steppenmotor controller

i also bay a arduino R4 minima but the can use the current program

i am not so good in this program wolrd its all new for me

so i need a pulse for the controller this pulse must be always there

whit the enable i set the motor on/off so to stop or drive or turn (one motor of the ohter dive)

i have bay this last week maby i have to change te progam because i get errors wenn i put the progam on the r4

first thank you all for helping

If I understand correctly, the timer and servo do not work together

I need that servo and that timer for a pulse,

how else can I generate a continuous pulse for the arduino uno?

i need one pin out whit a pulse for the motor controllers

Using the enable pin to stop and start isn't really a good idea. Steppers should be accelerated and decelerated to run smoothly. Consider using a library to generate the steps for your motors.
If you use my MobaTools library, you can also control your servos with it, and all is done via timer 1 without disturbing each other. You can also set the speed for servo movement, so you don't need your for loops to do that anymore.

i see only timerOne.H

can you tell me what i have to use

This topic was automatically closed 180 days after the last reply. New replies are no longer allowed.