Arduino starts being really weird!!! - too many components?

Howdy,

Well, i got a Robot with a Hc-SR04 Ultra sonic sensor, a Servo, a DC Motor with L298n H bridge, and a Uno.
The goal is that the Servo turn as soon as there is a Threshold distance reached. If i only hook up the Servo and the Sensor, everything just workes fine. As soon as i get the Motor included, the servo just starts turning and tries to go far beyond 180 degrees. The Sensor works fine with just the motor running. As soon a the servo gets connected same weird behaviour.
So hopefully anybody out there u could help!!!

cheers

Two things to check.
Can the power supply cope with the ammount of current you are requesting? It sounds to me like it can't.

Power supply decoupling - fit capacitors across each device, 0.1uF ceramic and 100uF plus in parallel.

Thanks man,

so you mean two caps parallel to each device (0,1 uf and 100uf), right?

One 0.1uF cap per device and one 100uF per five to ten devices.

Hey,

i tried what u said. Did work. I also used an external battery to power the servo. As i was messing around with it i bit more, i figured that the problem could be a software one. As soon as i write 'myservo.attach(servo_pin)' it doesn't work anymore. Even though i don't have the servo connected.

Thanks man

So i finally found out what is causing the trouble...
It's not a current problem, but a library one. When i drive the servo without the library everything works just fine. After some research i think at has something to do with the timer the library is using. Driving the servo oldschool, without the library isn't really perfect.
Any suggestions how to get it working with the servo.h library? I always thought the uno could at least do two simultaneous pwms. correct me if i'm wrong. (the second pwm i'm using is the one for the motor shield).

Cheers

The Servo library uses timer1, timer1 controls PWM on pins 9 and 10. It doesn't affect the
others.

That's it. Oh man, i had the motor driver on 9, so the timer1 caused the trouble.
U just made my day.