beginner needs help

Hi everybody

Having just received my first SainSmart and sensor shield boards I'm now looking for a guide on how to use them
Is there a user manual/Guide for idiots? OK Dummy/Noob may be better terms

Having Google'd user manual for SainSmart and getting mainly boards for sale I'm hoping that somebody here can offer some guidance

what I need to learn is how to connect a servo and a stepper, just 1 of each for now, controlled via a switch. I will be aiming to connect many more going forward but getting 1 of each to start with will be the mission

The board was connected to the pc, blink script loaded run and ammended and seems to do what it says on the tin

So now its all guns blazing and connect the servo - but where, how, which one of the 1 to 30 plus connectors do i use and how do i address that set of pins in the program. yes its basic I know, but where do I get/find this basic knowledge

Any help in solving my lack of knowledge greatly appreciated

Hi Notlob

I assume it is the SainSmart Uno you have, and also the SainSmart Sensor Shield. Is that right? In future, it helps if you can post links to the hardware you are asking about (unless it is a standard Arduino board, of course).

You should take a look at the sample programs in the Arduino IDE - there are ones for servos and stepper motors. Also look in the Examples and Playground sections of this website. They will explain how to connect up servos and steppers and run basic programs to try them out. Then, to do more, you will need to learn about writing your own program / modifying the examples to do what you want.

So that leaves your point about all the connectors on the Sensor Shield :slight_smile: Does your one look like this?

http://www.sainsmart.com/zen/documents/20-011-904/Pinout.png

What they have is the usual two rows of single header sockets as on the Uno (marked "Arduino Ports" in the photo). But they have also duplicated most of the pins with +5V and 0V pins next to the signal pin (for example, marked "Digital IO Port D0-D13" in the photo). This just makes it easier to connect servos, for example, which need power as well as signal connections.

So, if an example program says connect a servo to 0V, +5V and digital pin 9, you could connect the three wires to the three pins marked "GVS" in the column marked "9" in the "Digital IO" group.

Hope that helps

Ray

http://arduino-info.wikispaces.com/SensorShield

Much better than my explanation :slight_smile:

http://yourduino.com/sunshop2/index.php?l=product_detail&p=195
this is the shield i have

wanderson :- thank you for the link to the guide which I will digest over the next few days as I try to understand

Ray :- above link to shield - copied from the tutorial from wanderson :slight_smile:
thanks for the input re pin 9 example and where to start looking

any body else with comments please feel free

I'm sure I will return with any questions in the near future

Again thank you for sharing your time and knowledge on this subject

David

Hi,

Look at the How-To for the Yourduino Microcomputer Starter Set:
http://arduino-info.wikispaces.com/YourDuinoEngStarter

(The product page is HERE: )

There are pages on Servo, Stepper Motor etc.

Over 1000 Students have used this low-cost kit in beginning Engineering and Computer Science courses.

Feedback, Critique, comments on the how-to welcome! to terry at yourduino.com

DISCLAIMER: Mentioned stuff from my own shop...

Ok having read the link from wanderson and the info from Ray I have managed to get the servo to work on the sweep program, no stepper motors yet but they are in the post :smiley:

so with the shield connected I have the servo running connected to pin 9 as per the tutorial same as if it was running on the main board

but the shield has 0-53 digital connections and the main board has 12 - pins 2-13 so how do I address the pins on the shield?

reading the tutorial it seems I can use pins 3,5,7,9,11 as servo feeds what happened to the even pins?

one step forward - feels great, but, raises more questions :astonished: any help again appreciated

Hi Notlob

Based on the link you posted, your shield is designed to work with the Arduino Mega, which has many more IO pins than the Uno. If you are using the shield with a Uno, then I don't think those extra pins connect to the Uno.

To check, when you plug the shield in, is there a double row of pins underneath the shield that are beyond the end of the Uno board?

All the best

Ray

Hi Ray

the shield is being used with a Sain Smart mega 2560 not an Uno - will try to find a link
but its an Arduino mega copy as far as I know - with my limited experience
shield fits all pins on main board

I bought them because of the number of outputs available as i need to control a few servo's
model railway layout point /switch control even including the cost of the 2 boards and 30 plus servos/steppers, its still going to be cheaper than commercial point motors and control circuitry

Ok so I'm an anorak - lol, English sense of humour, - no offense to anoraks intended or implied

Ok, sorry, thought you had a Uno.

In which case, you can access the "extra" Mega pins from your programs just by using the relevant pin number. For example, digitalWrite(42, HIGH);

http://arduino-info.wikispaces.com/MegaQuickRef

HI

Thanks to all for the earlier info

Based on what was said and the links provided I have managed to get 1 button to control 1 servo, 2 LED's and 2 relays, on a separate relay board
Please see below sketch I have written, based on the help from this site, any comments appreciated as this is my first attempt in this field and I feel sure there will be a better way to do what I want

/*
 To control the stop position of 1 servo at both ends of the sweep, 
 Set 2 relays either on or off based on the servo position
 Set red/Green LED's to display path of the Point/Switch
 Using 1 normally open push switch - non latching
 
 The circuit:
 * LED's attached from pins 14 & 15 to ground through 220 Ohm resistors
 * pushbutton attached to pin 5 from +5V
 * 20K resistor attached to pin 5 from ground
 * Servo signal from pin 4
 
 
 created 2014
 by Notlob
 
 Based on the debounce button & servo sketches
 links to be added from the example page of arduino website
 
 */
 
 
#include <Servo.h>  // Comes with Arduino IDE 

// constants won't change. They're used here to 
// set pin numbers:
#define Servo1PIN  4  

const int buttonPin = 5;     // the number of the pushbutton pin
const int ledPin =  13;      // left this in sketch to verify the sketch works if i had wired board incorrectly
const int servopath_pin_ST = 14;    // the straight LED pin
const int servopath_pin_DV = 15;    // the diverge LED pin

// variables that will change:
int ledState = LOW;          // the current state of the output pin for pin 13 on the board
long lastDebounceTime = 0;
long debounceDelay = 50;
int buttonState = 0;         // the current reading from the input pin
int lastButtonState = LOW;   // the previous reading from the input pin
int servo_1_lastpos = 0;

// define start and end positions for each servo 
// might not be needed for all servos as some could use the same values
#define Servo1MIN  74 // Don't go to end of servo travel
#define Servo1MAX  101 // which may be 0 to 180.


// added 2 servos each will turn the posite way when button pressed
Servo myservo1;  // create servo objects to control a servos

int posservo_1 = 0;    // variable to store the servo position 


void setup() {   /****** SETUP: RUNS ONCE ******/
  // start serial port at 9600 bps and wait for port to open:
  Serial.begin(9600);
 
  // initialize the LED pins as an output:
  pinMode(ledPin, OUTPUT);
  pinMode(servopath_pin_ST, OUTPUT);
  pinMode(servopath_pin_DV, OUTPUT);
  // initialize the pushbutton pin as an input:
  pinMode(buttonPin, INPUT);    

  // attaches the servo on pin 4 to the servo objects 
  myservo1.attach(Servo1PIN);  
 
  // move servo 1 to the default start position
    digitalWrite(servopath_pin_ST ,LOW);     // pin 14 - off - turn off led and set relay 8 to non-conduct
    digitalWrite(servopath_pin_DV ,LOW);     // pin 15 - off - turn off led and set relay 7 to non-conduct
   
   for(posservo_1 = Servo1MAX; posservo_1 > Servo1MIN; posservo_1 -= 1)  // goes from 0 degrees to 180 degrees 
          {                                  // in steps of 1 degree 
            myservo1.write(posservo_1);      // tell servo to go to position in variable 'posservo_1' 
            delay(50);                       // waits 50ms for the servo to reach the position 
          }
  servo_1_lastpos = Servo1MIN;

  digitalWrite(servopath_pin_DV ,HIGH);        // pin 15 - on - light green led and set relay 8 to conduct  

}//--(end setup )---  

  
void loop(){
  // read the state of the pushbutton value:
 int reading = digitalRead(buttonPin);
 if (reading != lastButtonState) {
    // reset the debouncing timer
    lastDebounceTime = millis();
  }
   if ((millis() - lastDebounceTime) > debounceDelay) {
    // whatever the reading is at, it's been there for longer
    // than the debounce delay, so take it as the actual current state:
    // if the button state has changed:
    if (reading != buttonState) {
      buttonState = reading;
      // only toggle the LED if the new button state is HIGH
      if (buttonState == HIGH) {
         Serial.print("button changed");
        ledState = !ledState;
        // we can now use the ledstate as the test for changing the points
      }
}
}
 digitalWrite(ledPin, ledState);  //set LED on Board to = ledstate - high or low

lastButtonState = reading;

if(ledState == HIGH ){                           // new position - set point for straight on
      if (servo_1_lastpos < Servo1MAX) {         // if point not set for straight on then
        digitalWrite(servopath_pin_ST ,LOW);     // pin 14 - turn off led and turn of frog power set relay 8 to non-conduct 
        digitalWrite(servopath_pin_DV ,LOW);     // pin 15 - turn off led and turn of frog power set relay 7 to non-conduct
        //digitalWrite(ledPin, ledState);
         for(posservo_1 = Servo1MIN; posservo_1 < Servo1MAX; posservo_1 += 1)  // goes from 0 degrees to 180 degrees 
          {                                      // in steps of 1 degree 
            myservo1.write(posservo_1);          // tell servo to go to position in variable 'posservo_1' 
            delay(50);                           // waits 50ms for the servo to reach the position 
          }
        Serial.print(" gone to ");
        Serial.print(Servo1MAX);
        Serial.println(" degrees ");
        Serial.println(" Green Light Lit, Points straight on, Relay 8 set for frog");
        servo_1_lastpos = Servo1MAX;     
        digitalWrite(servopath_pin_ST ,HIGH);   //set green led on and turn on frog power set relay 8 to conduct     
      }    
}      
else 
{                                              // new position - set point for diverge
     if(servo_1_lastpos > Servo1MIN) {
      digitalWrite(servopath_pin_ST ,LOW);     // pin 14 - off
      digitalWrite(servopath_pin_DV ,LOW);     // pin 15 - off 
      for(posservo_1 = Servo1MAX; posservo_1>=Servo1MIN; posservo_1-=1)     // goes from 180 degrees to 0 degrees 
  {                                
    myservo1.write(posservo_1);                // tell servo to go to position in variable 'pos' 
   delay(50);                                  // waits 50ms for the servo to reach the position 
  }
  Serial.print(" back to ");
  Serial.print(Servo1MIN);
  Serial.print(" degrees ");
  Serial.println(" Red Light Lit, Points Diverge, Relay set for frog");        
  //Serial.println();  
  servo_1_lastpos = Servo1MIN;
  digitalWrite(servopath_pin_DV ,HIGH);   //set red led on and turn on frog power set relay 7 to conduct 

     
  } // end else
}   // end if led = high
    
}