Things used in this project

Hardware components:
12757 01
SparkFun RedBoard
×1
DC Stepper Motor 28-BY-J-48
×1
MB 1010 LV-Max-Sonar EZ1
×1
Wunderbar relayr 02 1024x1024
WunderBar
×1

Custom parts and enclosures

Stepper Motor 1 Diagram
Stepper (28-BY-J-48) Pins to Driver Board (ULN2003A) to Arduino UNO / Sparkfun Redboard Pins
Stepper%20motor%201
Stepper Motor 2 Diagram
Stepper (28-BY-J-48) Pins to Driver Board (ULN2003A) to Arduino UNO / Sparkfun Redboard Pins
Stepper%20motor%202
Sonar Sensor Diagram
Sonar Sensor (MB1010 LV-Max-Sonar-EZ1) to Arduino UNO / Sparkfun Redboard
Lv max sonar ez1

Schematics

Back-Saver Motor and Sonar connections to RedBoard
Back-Saver Motor Connections.fzz
Back-Saver Motor Connections_bb.png
Back saver%20motor%20connections bb

Code

Sonar CodeC/C++
Code for the Sonar we got from http://playground.arduino.cc/
/*
This code reads the Analog Voltage output from the
LV-MaxSonar sensors
If you wish for code with averaging, please see
playground.arduino.cc/Main/MaxSonar
Please note that we do not recommend using averaging with our sensors.
Mode and Median filters are recommended.
*/

const int anPin1 = 0;
long distance1;

void setup() {
  Serial.begin(9600);  // sets the serial port to 9600
}

void read_sensors(){
  /*
  Scale factor is (Vcc/512) per inch. A 5V supply yields ~9.8mV/in
  Arduino analog pin goes from 0 to 1024, so the value has to be divided by 2 to get the actual inches
  */
  distance1 = analogRead(anPin1)/2;
}

void print_all(){
  Serial.print("S1");
  Serial.print(" ");
  Serial.print(distance1);
  Serial.print("inches");
  Serial.println();
}

void loop() {
  read_sensors();
  print_all();
  delay(50); 
}
stepper motor codeC/C++
Runs the stepper motors attached to the "robot" forward or in reverse (configurable in software)
/****************************************************************************
   BYJ48 Stepper motor code
   Connect :

   Stepper 1
   IN1 >> D8
   IN2 >> D9
   IN3 >> D10
   IN4 >> D11
   
   Stepper 2	
   IN1 >> D5 
   IN2 >> D4
   IN3 >> D3
   IN4 >> D2
 
   VCC ... 5V Prefer to use external 5V Source
   Gnd
   written By :Mohannad Rawashdeh
  http://www.instructables.com/member/Mohannad+Rawashdeh/
     28/9/2013

Edited by Team Direct: Added second motor, runs in opposite direction.
http://www.hackster.io/direct/back-saver

  **************************************************************************/

#define IN1  10
#define IN2  11
#define IN3  12
#define IN4  13
#define IN5  5
#define IN6  4
#define IN7  3
#define IN8  2



int Steps = 0;
boolean Direction = true;// gre
unsigned long last_time;
unsigned long currentMillis ;
int steps_left=4095;
long time;
void setup()
{
Serial.begin(115200);
pinMode(IN1, OUTPUT); 
pinMode(IN2, OUTPUT); 
pinMode(IN3, OUTPUT); 
pinMode(IN4, OUTPUT); 
pinMode(IN5, OUTPUT); 
pinMode(IN6, OUTPUT); 
pinMode(IN7, OUTPUT); 
pinMode(IN8, OUTPUT);



// delay(1000);

}
void loop()
{
  while(steps_left>0){
  currentMillis = micros();
  if(currentMillis-last_time>=1000){
  stepper(1); 
  time=time+micros()-last_time;
  last_time=micros();
  steps_left--;
  }
  }
   Serial.println(time);
  Serial.println("Wait...!");
  //delay(2000);0
  Direction=1;//!Direction;
  steps_left=4095;
}

void stepper(int xw){
  for (int x=0;x<xw;x++){
switch(Steps){
   case 0:
     digitalWrite(IN1, LOW); 
     digitalWrite(IN2, LOW);
     digitalWrite(IN3, LOW);
     digitalWrite(IN4, HIGH);
     
     digitalWrite(IN5, HIGH); 
     digitalWrite(IN6, LOW);
     digitalWrite(IN7, LOW);
     digitalWrite(IN8, HIGH);
   break; 
   case 1:
     digitalWrite(IN1, LOW); 
     digitalWrite(IN2, LOW);
     digitalWrite(IN3, HIGH);
     digitalWrite(IN4, HIGH);
     
     digitalWrite(IN5, HIGH); 
     digitalWrite(IN6, LOW);
     digitalWrite(IN7, LOW);
     digitalWrite(IN8, LOW);    
     
   break; 
   case 2:
     digitalWrite(IN1, LOW); 
     digitalWrite(IN2, LOW);
     digitalWrite(IN3, HIGH);
     digitalWrite(IN4, LOW);
     
     digitalWrite(IN5, HIGH); 
     digitalWrite(IN6, HIGH);
     digitalWrite(IN7, LOW);
     digitalWrite(IN8, LOW);       
     
   break; 
   case 3:
     digitalWrite(IN1, LOW); 
     digitalWrite(IN2, HIGH);
     digitalWrite(IN3, HIGH);
     digitalWrite(IN4, LOW);
     
     digitalWrite(IN5, LOW); 
     digitalWrite(IN6, HIGH);
     digitalWrite(IN7, LOW);
     digitalWrite(IN8, LOW);     
     
   break; 
   case 4:
     digitalWrite(IN1, LOW); 
     digitalWrite(IN2, HIGH);
     digitalWrite(IN3, LOW);
     digitalWrite(IN4, LOW);
     
     digitalWrite(IN5, LOW); 
     digitalWrite(IN6, HIGH);
     digitalWrite(IN7, HIGH);
     digitalWrite(IN8, LOW);
   break; 
   
   case 5:
     digitalWrite(IN1, HIGH); 
     digitalWrite(IN2, HIGH);
     digitalWrite(IN3, LOW);
     digitalWrite(IN4, LOW);
     
     digitalWrite(IN5, LOW); 
     digitalWrite(IN6, LOW);
     digitalWrite(IN7, HIGH);
     digitalWrite(IN8, LOW);      
     
   break; 
     case 6:
     digitalWrite(IN1, HIGH); 
     digitalWrite(IN2, LOW);
     digitalWrite(IN3, LOW);
     digitalWrite(IN4, LOW);
     
     digitalWrite(IN5, LOW); 
     digitalWrite(IN6, LOW);
     digitalWrite(IN7, HIGH);
     digitalWrite(IN8, HIGH);
     
   break; 
   case 7:
     digitalWrite(IN1, HIGH); 
     digitalWrite(IN2, LOW);
     digitalWrite(IN3, LOW);
     digitalWrite(IN4, HIGH);
     
     digitalWrite(IN5, LOW); 
     digitalWrite(IN6, LOW);
     digitalWrite(IN7, LOW);
     digitalWrite(IN8, HIGH);
     
   break; 
   default:
     digitalWrite(IN1, LOW); 
     digitalWrite(IN2, LOW);
     digitalWrite(IN3, LOW);
     digitalWrite(IN4, LOW);
     
     digitalWrite(IN5, LOW); 
     digitalWrite(IN6, LOW);
     digitalWrite(IN7, LOW);
     digitalWrite(IN8, LOW);     
     
   break; 
}
SetDirection();
}
} 
void SetDirection(){
if(Direction==1){ Steps++;}
if(Direction==0){ Steps--; }
if(Steps>7){Steps=0;}
if(Steps<0){Steps=7; }
}

Credits

Replications

Did you replicate this project? Share it!

Love this project? Think it could be improved? Tell us what you think!

Give feedback

Comments

Similar projects you might like

Octoblu and Wunderbar: Baby Monitor that texts you updates
Easy
  • 2,190
  • 16

Full instructions

By using Relay's Wunderbar on Octoblu's IoT platform, it was easy to create a simple baby monitor that texts you updates about your baby.

Wunder Bird
Easy
  • 524
  • 13

Work in progress

Let reality shape the virtual

Wunder Bird

Team Les pigeons

Sound and Light
Easy
  • 218
  • 0

Work in progress

Sound starts stops based on proximity. Light dims according to sound volume as well.

Sound and Light

Team Dumpkowski

SmarterBike
Easy
  • 150
  • 1

SmarterBike adds small affordable sensors to bikes and connects them to a smartphone app. Using it, we will find the best routes for bikers.

Add projectSign up / Login
Respect project