how to make a motor run and stop

how do i write code to make my motor run for say 1 minute then stop until told to start again?

If you want someone to write a program for you then you should ask in the Gigs and Collaborations section and be prepared to pay.

If you want to learn how to do it yourself then all of the techniques that you will need are covered in the examples that come with the Arduino IDE.

...R

Can you express what you want to do in a flowchart?

Hi crash,

That should be quite simple. What type of motor do you have?

i have a dc 2.5-6v submersible water pump,soil moisture sensor,mb102 breadboard power supply 3.3-5v,hc-o6 slave bluetooth module,micro sd sd storage board memory shield module and sd card. i am wanting to make an aotumatic plant watering system that can also be controlled by bluetooth.i was hoping to be able to use the mb102 power supply, the micro sd storage board and the sd card instead of the uno r3.
so here goes my attempt at a flowchart

(moist-return to check soil moisture)
power on- check soil moisture-
(dry-pump water for 1 minute then return to check soil moisture)

("A" pump water for 1 minute then return to check soil moisture)
bluetooth- if-
("B" return to check soil moisture)

so there it is , not much but it has been confusing me for a couple of weeks.

"but it has been confusing me for a couple of weeks."

Surely in that amount of time you've written some code. If you showed it to us we might be able to help you fix it.

here’s the best i’ve got so far

// BTLE - Version: Latest 
#include <BTLE.h>

// I2CSoilMoistureSensor - Version: Latest 
#include <I2CSoilMoistureSensor.h>

int sensor_pin=A0;
int output_value;
const int motorIn1 = 9;
const int motorIn2 = 10;
char val;


void setup() {
  Serial.begin(9600);
  {
    pinMode(motorIn1,OUTPUT);
    pinMode(motorIn2,OUTPUT);
  }
  
 }

void loop() {
  output_value= analogRead(sensor_pin);
  output_value= map(output_value,
  550,0,0,100);
  if(Serial.available())
  {
    val =Serial.read();
  }
  if( val == 'A' )
  { 
    analogWrite(motorIn1,400);
  }
  if( val == 'B' )
  {
    analogWrite(motorIn1,0);
  }
  if(output_value < 30)
  {
    analogWrite(motorIn1,400);
  }
 
  
  
 
}
analogWrite(motorIn1,400);

analogWrite can only do values from 0 - 255.

ok if i give analogWrite motorIn a value of 255 it will give the motor a speed of that right? then how do i get it to stop after 1 minute automaticaly and recheck the sensor?

It's a pump, you will probably really just want to switch it ON and OFF. PWM doesn't make sense to me. So use a digital pin and just say digitalWrite(motorPin, HIGH) and ditigalWrite (motorPin, LOW) for on and off switching (or the other way around depending on your wiring).

How is the pump wired? You don't mention any electronic switch and your Arduino for sure can't power it directly. A solderless breadboard may also have a hard time dealing with the current required by the pump, which I expect to be around 0.5-1 A.

Finally: add a serious delay (in the tune of 5-10 mins) between watering and checking the resulting moisture levels. It takes a while for the water to be absorbed and reach the sensor.

ok then how do i delay the switch between motorPin high and motorPin low?

crash111f:
ok then how do i delay the switch between motorPin high and motorPin low?

Go have a look at the "Blink Without Delay" example.

And look here if you need more help with it. https://www.gammon.com.au/blink

here’s my new code. but i’ve got an error

// I2CSoilMoistureSensor - Version: Latest 
#include <I2CSoilMoistureSensor.h>

int sensor_pin=A0;
int output_value;
const int motorPin = 9;
const int motorIn2 = 10;
char val;


void setup() {
  Serial.begin(9600);
  {
    pinMode(motorPin,OUTPUT);
  }
  
 }

void loop() {
  output_value= analogRead(sensor_pin);
  output_value= map(output_value,
  550,0,0,100);
  if(Serial.available())
  {
    val =Serial.read();
  }
  if( val == 'A' )
  { 
    digitalWrite(motorPin,HIGH);
  }
  if( val == 'B' )
  {
    digitalWrite(motorPin,LOW);
  }
  if(output_value < 30)
    digitalWrite(motorPin,HIGH);
  delay (60,000);
    digitalWrite(motorPin,LOW)
    delay (300,000);
  }

Arduino: 1.6.4 (Mac OS X), Board: “Arduino Uno”

Using library I2CSoilMoistureSensor in folder: /Users/chrisfisher/Documents/Arduino/libraries/I2CSoilMoistureSensor

/Applications/Arduino.app/Contents/Java/hardware/tools/avr/bin/avr-g++ -c -g -Os -w -fno-exceptions -ffunction-sections -fdata-sections -fno-threadsafe-statics -MMD -mmcu=atmega328p -DF_CPU=16000000L -DARDUINO=10604 -DARDUINO_AVR_UNO -DARDUINO_ARCH_AVR -I/Users/chrisfisher/Library/Arduino15/packages/arduino/hardware/avr/1.6.4/cores/arduino -I/Users/chrisfisher/Library/Arduino15/packages/arduino/hardware/avr/1.6.4/variants/standard -I/Users/chrisfisher/Documents/Arduino/libraries/I2CSoilMoistureSensor /var/folders/vq/93q1xgpx4v30m70p7zmzhn_w0000gn/T/build2312616869697043999.tmp/smart_plant_water_4.cpp -o /var/folders/vq/93q1xgpx4v30m70p7zmzhn_w0000gn/T/build2312616869697043999.tmp/smart_plant_water_4.cpp.o
smart_plant_water_4.ino: In function ‘void loop()’:
smart_plant_water_4.ino:39:16: error: too many arguments to function ‘void delay(long unsigned int)’
In file included from /Users/chrisfisher/Documents/Arduino/libraries/I2CSoilMoistureSensor/I2CSoilMoistureSensor.h:16:0,
from smart_plant_water_4.ino:4:
/Users/chrisfisher/Library/Arduino15/packages/arduino/hardware/avr/1.6.4/cores/arduino/Arduino.h:134:6: note: declared here
void delay(unsigned long);
^
smart_plant_water_4.ino:41:5: error: expected ‘;’ before ‘delay’
smart_plant_water_4.ino: At global scope:
smart_plant_water_4.ino:48:1: error: expected declaration before ‘}’ token
too many arguments to function ‘void delay(long unsigned int)’

Indeed. Just as the error message says, missing ;.

delay (60,000);

Lose the comma. The compiler is seeing that as two separate numbers.