SOLVED When use servo.h libraries it stop for 2 to 10 sec

i try to make remote for car whit 433mhz reserver transmitter

and i take 2 code and put togther
but when i try use servo to turn wheel it stop work for 2 to 10 sec and wake up until i use again

what i do wrong

//RC Resive kode

#include “RH_ASK.h”
#include <SPI.h>
#include “Servo.h”

//Servo servo1;
Servo servo2;
//RH_ASK driver;
RH_ASK driver(1000, 11, 8, 10); // bps,rx,tx

//Those are used for fine tuning
int SERVO_LOW = 0;
int SERVO_HIGH = 180;
int c1,c2,c3;
int fart;

// Pin assignments for channels(output to servos)

//byte CH1_PIN = 10;
byte CH2_PIN = 12;
//byte CH3_PIN = 11;

//mot 1 er back wheel - L298n chip
//mot 2 er Front wheel turn - L298n chip i change to use servo for turn
int mot1speed=5; //motor one speed 0 - 180
int mot1a=2; //enable motor forward or back
int mot1b=4; //enable motor forward or back
int mot2speed=6;
int mot2a=3;
int mot2b=7;

void setup() {
// put your setup code here, to run once:

pinMode(mot1speed,OUTPUT);
pinMode(mot1a,OUTPUT);
pinMode(mot1b,OUTPUT);
pinMode(mot2speed,OUTPUT);
pinMode(mot2a,OUTPUT);
pinMode(mot2b,OUTPUT);

//
//servo1.attach(CH1_PIN);
servo2.attach(CH2_PIN); //for turn front wheel
// pinMode(CH3_PIN, OUTPUT);

// Debugging only, comment serial stuff when done
Serial.begin(9600);
if (!driver.init())
Serial.println(“init failed”);

}

int treatValue(int data) {
return (data * 9 / 1024) + 48;
}
//--------------------------

void loop()
{

uint8_t buf[12];
uint8_t buflen = sizeof(buf);
if (driver.recv(buf, &buflen)) // Non-blocking
{
c1 = buf[0];
c2 = buf[1];
c3 = buf[2];

// Remap values to the predefined range
byte v1 = map(c1, 0, 255, SERVO_LOW, SERVO_HIGH);
byte v2 = map(c2, 0, 255, SERVO_LOW, SERVO_HIGH);

// servo2.write(v1); not use now
// delay(35);

//control turn whit server
Serial.print("servo2 “);
Serial.print(v2);
Serial.print(” ");
servo2.write(v2);
delay(35);

//control of back wheel - fart = speed
if (v1 > 80 && v1 < 95 ) {
// stop drive
analogWrite(mot1speed,0);
digitalWrite(mot1a,LOW);
digitalWrite(mot1b,LOW);
Serial.print("stop1 ");
Serial.println(v1);
}

//Back wheel forward
if (v1 > 96){
fart = ((v1-90)*2.8333);
analogWrite(mot1speed,fart);
digitalWrite(mot1a,HIGH);
digitalWrite(mot1b,LOW);
Serial.print("Frem ");
Serial.println(fart);
}

//Back wheel back
if (v1 < 79){
fart =(((v1-80)*-1)2.1875); //if want max fart =(((v2-80)-1)*3.1875);
analogWrite(mot1speed,fart);
digitalWrite(mot1a,LOW);
digitalWrite(mot1b,HIGH);
Serial.print("Tilbage ");
Serial.println(fart);
}
}
}


//Transmitter code

#include “RH_ASK.h”
#include <SPI.h> //#include Not actually used but needed to compile

RH_ASK driver(1000, 11, 12, 10); // bps,rx,tx

int xPin = A2;
int yPin = A3;
int buttonPin = 3;

int xPosition = 0;
int yPosition = 0;
int buttonState = 0;
int buttonS;

void setup()
{
Serial.begin(9200); // Debugging only
if (!driver.init())
Serial.println(“init failed”);
}

void loop()
{
// Since my joysticks are really not precise we can encode their values at 256 possibly less
xPosition = analogRead(xPin);
xPosition = map(xPosition, 0, 1023, 0, 255);
yPosition = analogRead(yPin);
yPosition = map(yPosition, 0, 1023, 0, 255);
buttonS = digitalRead(buttonPin);
if (buttonS == 1)
{
buttonState = 0;
}
else
{
buttonState = 1;
}
//Put the values in the array, 8 bits per input
uint8_t values[3];
values[0]=(uint8_t) xPosition;
values[1]=(uint8_t) yPosition;
values[2]=(uint8_t) buttonState;

Serial.println(buttonState);

//Serial.print(xPosition);
Serial.print(" : ");
//Serial.println(yPosition);
Serial.println(buttonS);
driver.send(values, 3);
driver.waitPacketSent();
delay(20);
}

I suspect your servo is drawing too much power and causing your Arduino to reset. Connect the servo power wire directly to a 4V to 6V battery pack. Connect the negative side of the battery pack and the ground wire of the servo to Arduino ground.

Hi

Now I use Sensor Shield now and give 5v to servor and resiver ground to ground on uno
But same problem some time sleep 1 sec other time 5 sec

Thanks for answers i forgot about how mutch power a uno can give :slight_smile:

Solved It was a bad servo i change to new servo and now work

Thanks