Constant 1.7 Volts Problem

Hi,

I'm new to the Arduino environment so please be simple as possible :).

I am supposed to drive a 24V brushless DC motor with Arduino Mega 2560 but I, first, decide to start with an easy 24V DC fan. I use L289N motor driver and a 24VDC optical sensor to run the fan. Basically, if the sensor is high, the fan will run; if it is low, it will stop.

So, my components in this project are as follows:

  • 1 Arduino Mega 2560,
  • 1 L289N motor driver,
  • 1 24V DC power supply,
  • 1 24V DC relay,
  • 1 24V optical sensor.

I've connected the sensor so that if it is high then the relay will be active and 5V coming from Arduino itself will activate a pin that I've defined as input. Then, the fan will start to turn. After I tried the code, I noticed that when my sensor is low, that is, the output pin is low, the fan motor is not stopped but slowed down. When the sensor is high, it is turning faster.

When I checked the output pin, I read about 2.5V where it should be low, and 4.7V where it should be high.

My problem here is I cannot stop the motor. It either turns slow or fast but never stops.

Then I tried this code below to plot an empty pin:

/*
  ReadAnalogVoltage
  Reads an analog input on pin 0, converts it to voltage, and prints the result to the serial monitor.
  Graphical representation is available using serial plotter (Tools > Serial Plotter menu)
  Attach the center pin of a potentiometer to pin A0, and the outside pins to +5V and ground.

  This example code is in the public domain.
*/

// the setup routine runs once when you press reset:
void setup() {
  pinMode(40,INPUT);
  // initialize serial communication at 9600 bits per second:
  Serial.begin(9600);
}

void loop() {
  // read the input on analog pin 40:
  int sensorValue = digitalRead(40);
  // Convert the analog reading (which goes from 0 - 1023) to a voltage (0 - 5V):
  float voltage = sensorValue * (5.0 / 1023.0);

  Serial.println(voltage);
}

When I plot, I saw this:

Then I noticed, when I touch A9 (analog pin) and metal part on Arduino where the USB cable is plugged in, I saw 0V on the plotter:

Could it be some kind of short circuit or my Arduino is not working properly? What should I do?

Thanks,
Ersin

// read the input on analog pin 40:
int sensorValue = digitalRead(40);

  • ? -

OK. I've changed it and still the same results, same plot. :slightly_frowning_face:

The analog input pins are labeled with an "A" followed by a number. Is the pin labeled "40" an analog input?

I've tried every single pin. Now, I've changed the code as below. Still getting the same plot.

// the setup routine runs once when you press reset:
void setup() {
  pinMode(A8,INPUT);
  // initialize serial communication at 9600 bits per second:
  Serial.begin(9600);
}

// the loop routine runs over and over again forever:
void loop() {
  // read the input on analog pin 0:
  int sensorValue = analogRead(A8);
  // Convert the analog reading (which goes from 0 - 1023) to a voltage (0 - 5V):
  float voltage = sensorValue * (5.0 / 1023.0);
  // print out the value you read:
  Serial.println(voltage);
}
float voltage = sensorValue * (5.0 / 1023.0);

The correct divisor is 1024.0.

  // read the input on analog pin 0:
  int sensorValue = analogRead(A8);

The comment is out-of-date. I suggest removing it.

Then I tried this code below to plot an empty pin:

  int sensorValue = analogRead(A8);

What is connected to pin A8?

Nothing is connected to the board. Only USB cable for power and connection to PC.

What voltages are you expecting to read from a floating pin?

Well, shouldn't it be 0? :roll_eyes:

If you connect the pin to GND the voltage will be zero. But then the pin is no longer floating.

Soulplox:
Well, shouldn't it be 0? :roll_eyes:

No it shouldn't. It will be any possible reading. It picks up interference from the air and can return a value of anything.

OK, back to my question:

I am trying to make an simple AGV following a magnetic line. When the sensor on the AGV is low, then it should understand that it is the end of the line and should go backwards. But in my case I cannot read 0V on the output pin, that I cannot stop my AGV ever.

Why can't I stop the fan when my optical sensor is low? I want to see 0V on my analog output (in my case pin 9). When the sensor is high, I read 4.7V and fan turns at high speed. However, when it is low, I read about 2.5V and fan slows down but does not stop.

I've also tried this code below that I believe somehow related to the same problem. In this code, when input pin 2 is high, the LED on Arduino should be off. Else, it is on. I've seen that when I connect 5V of Arduino to pin 2, the LED is turning off. However, when I pull the cable, it is turning on after a delay of 3-4 seconds. And the plot is like this:

The code:

int Pin_Input = 2;

void setup() {
pinMode(Pin_Input, INPUT);
pinMode(13, OUTPUT);
Serial.begin(9600);
}

void loop() {

int Sensor_Value = digitalRead(Pin_Input);

Serial.println(Sensor_Value);

if (Sensor_Value == LOW)
{
  digitalWrite(13, HIGH);
}
else
{
  digitalWrite(13, LOW);
}
}

However, when I pull the cable,

Are you not listening?
DO NOT PULL THE CABLE BECAUSE THE INPUT PIN WILL FLOAT

Yes that is what happens when an input floats.

OK, back to my question:

No this is further information that you should have posted initially. What you need to post is a schematic ( not a physical layout diagram ) of how things are wired up.

In this code, when input pin 2 is high, the LED on Arduino should be off. Else, it is on. I've seen that when I connect 5V of Arduino to pin 2, the LED is turning off. However, when I pull the cable, it is turning on after a delay of 3-4 seconds.

Won't happen if you use:

pinMode(Pin_Input, INPUT_PULLUP);

Hi,

Can you please post a copy of your circuit, in CAD or a picture of a hand drawn circuit in jpg, png?

Thanks... Tom :slight_smile: