Potentiometer random values

Hi Everyone,

I am trying to setup a IR sensor with a Servo motor , I have a potentiometer when I rotate it the servo motor will rotate which has IR sensor mounted on top which then measures the distance.

The problem is the potentiometer giving some random values when try to connect my IR sensor (sharp) to the power supply. When I disconnect the IR sensor the potentiometer is working fine.

I cannot figure out what is going wrong.

I have attached the circuit diagram.

#include <Servo.h>

const int SERVO = 8;
const int POT   = 0;

Servo servoMotor;

int val = 0;

void setup() {

void loop() {

  val = analogRead(POT);
  val = map(val,0,1023,0,255);

Thanks in advance.

Is the whole circuit really powered by one of those feeble 9V batteries ?

No , Its only the servo motor powered by battery. The IR is powered by arduino 5V. But all the grounds are connected to the same line.

Can you please post a copy of your circuit, in CAD or a picture of a hand drawn circuit in jpg, png?
Fritzy diagrams are not very informative.

Drawing your circuit and posting picture will be much better.
Put labels to your pins and components.
For example, what resistance value is your pot?

Thanks.. Tom... :slight_smile:

Hi Tom ,

Thanks for the reply. I am not good at drawing circuits , I am newbie to electronics. Sorry for that.

I more thing what I observed is that when connecting my IR to the 5v voltage regualtor the potentiometer works fine and when I connect my IR to the 5v power supply from arduino the voltage drops from 5.02 to 4.92. Is this something has to do with this ?