Hi everyone ,
my problem is that i want to make a test on the state of my led ,
if my led is on the motor stop else the motor still running
here is the code i've done.
motor is connected to pin 2 and GND
the led id connected to pin 3 and GND and there is a wire betwen the led and the resistor going to the A1
const int motPin = 2;
const int monCapteur = 1;
const int test = 3 ;
float tension;
int valeurLue = 0 ;
void setup(){
pinMode(motPin,OUTPUT);
pinMode(test,OUTPUT);
valeurLue = analogRead(monCapteur);
Serial.begin(9600);
Serial.println("Moteur test");
}
void loop(){
digitalWrite(motPin,HIGH);
digitalWrite(test,HIGH);
if {valeurLue == 0) {
digitalWrite(motPin,HIGH);
else
digitalWrite(motPin,LOW);
}
Who knows?
The chances of an analogRead returning zero are low, unless the pin is tied directly to ground.
Maybe instead of if {valeurLue == 0) {
how about if {valeurLue < someThreshold) { ?
but if i write Serial.println(valeurLue) on void loop
in the serial monitor it's always 0
This is the first time you've mentioned this.
The code you posted doesn't print any analogue values read, so why don't you post your code and a schematic?
It sounds like the pin is shorted to ground.
No motor is "just like an LED". It is a very bad idea to power a motor from an Arduino output pin. If you continue doing this, after a while you will have to buy another Arduino.
malles:
no just i set the pin HIGH and the motor turn on it work try it it's just a simple continious courant motor just like a led
Not only will it draw so much current it will damage the arduino, the lack of a diode across the motor will cause high voltage spikes and do further damage to your arduino.
Remove the motor and see if you have the same problem. If you do then either you have not got it wired like you think or you have already damaged your arduino. Try another analogue pin but stop driving your motor like this.
give your motor voltage and current rating then only we can say that motor will damage your arduino ar not. As far as i know there are some motors which are rated as 5v, 0.02 -0.03A.
and for the code it is better you connect led to digital pin and use the following
if digitalpin == HIGH
motor stop
if digitalpin == LOW
motor on
zacmackra:
give your motor voltage and current rating then only we can say that motor will damage your arduino ar not. As far as i know there are some motors which are rated as 5v, 0.02 -0.03A.
Even if this were true, then having no diode would still damage the arduino.
thank you for your advice.
I am very sorry, I know my question seems to be very stupid (I'm a beginner) ... also my english (it's not my native language) ..
summary for what I want to do with my project is a bit like the mechanism of the car door. as soon as I close the car door, there is a light that goes off.
in my project, my goal is to put an motor at rest as soon as I close my other electric circuit contains a diode.