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