HELP PLEASE. Newbie without a clue

I have purchased a UNO R3 board and stepper motor along with 2 push/pull solenoids but i do not have a clue how to write the code. I have read allof the guides but just cant get to grips with it. I basically need 1 solenoid to push whilst the other pulls and then vice versa. I need to be able to change the frequency of these movements. Any help would be much appreciated

Graham

You do NOT write an entire program at once. You write a little bit of code, and test it. Then, you write some more, and test that. Repeat until you have written all of the code.

What, EXACTLY, triggers the solenoid push/pull action?
How, EXACTLY, are you connecting the solenoids to the Arduino? Not directly, that is for sure.

How long does one solenoid push?

I need to be able to change the frequency of these movements.

Based on phases of the moon? The price of rice in China?

The solenoids are connected to a dual H bridge DC stepper motor drive controller board module.

I do not need anything to trigger the solenoid, i just want the solenoids to push/pull repeatedly and i want to be able to vary the speeds.

I have attached a video below of the equipment i have and the action i am looking to recreate

cheers

Post a link to the datasheet for your stepper motor and a link to the datasheet for the driver board.

These links may help
Stepper Motor Basics
Simple Stepper Code

Planning and Implementing a Program

...R

R

Thanks for the reply

I will have a read through the guides you have attached and hopefully i can get some understanding of how to manage this. Below is a list of the hardware i have.

Hardware

Adafruit METRO 328 Fully Assembled - Arduino IDE compatible [ATmega328] : ID 50 : $17.50 : Adafruit Industries, Unique & fun DIY electronics and kits Arduino
Premium Male/Male Jumper Wires - 20 x 3 (75mm) : ID 1956 : $1.95 : Adafruit Industries, Unique & fun DIY electronics and kits Wires
Premium Female/Male 'Extension' Jumper Wires - 40 x 3 (75mm) : ID 825 : $3.95 : Adafruit Industries, Unique & fun DIY electronics and kits Female/Male wires
Mini Push-Pull Solenoid - 5V : ID 2776 : $4.95 : Adafruit Industries, Unique & fun DIY electronics and kits Solenoid x2
USB Cable - Standard A-B [3 ft/1m] : ID 62 : $2.95 : Adafruit Industries, Unique & fun DIY electronics and kits USB Cable
https://goo.gl/h97IVr L298N DC Stepper Motor Drive

A logic level N channel MOSFET would, in my opinion, be a better choice of driver for the solenoid than an antique stepper driver. The coil current is listed at 1.1A which is on the very edge of the 298 capability.

graemma1:
. Below is a list of the hardware i have.

The link for the motor drive datasheet does not work

And you don't seem to have a link for the motor datasheet

...R

solenoid

Board

https://www.newegg.com/Product/Product.aspx?Item=9SIA6BM36M1838&cm_re=L298N_DC_Stepper-_-9SIA6BM36M1838-_-Product
Stepper motor

I am quite happy to switch motors if i can get the code to work these. this motor must work as it does in the video above. I just need some help with the code as i dont even know where to start.

I thought that the solenoids were driven by the L298. Where is the stepper motor?

How are you going to control the frequency? A potentiometer, encoder, keypad,...?
What is the range of frequencies?

I thought the L298 was the stepper motor??

I have been given the below code. I hae uploaded to UNO R3 but not sure where i go from here.

int Pin4 = 4;
int Pin7 = 7;

void setup() {
pinMode(Pin4, OUTPUT);
pinMode(Pin7, OUTPUT);
}
void loop() {
digitalWrite(Pin4, HIGH); //stylus not touching phone
digitalWrite(Pin7, HIGH); //stylus not touching phone
delay(1000); // 1 second delay
digitalWrite(Pin4, LOW); //stylus touching phone. Where blocks show up.
delay(1000); // 1 second delay
digitalWrite(Pin7, LOW); //stylus touching phone. Where accept button is.
delay(1000); // 1 second delay
digitalWrite(Pin4, HIGH); //stylus not touching phone
delay(1000); // 1 second delay
digitalWrite(Pin7, HIGH); //stylus not touching phone
delay(1000); // 1 second delay
digitalWrite(Pin4, LOW); //stylus touching phone. Where blocks show up.
delay(500); // half second delay
digitalWrite(Pin4, HIGH); //stylus not touching phone
delay(500); // half second delay
digitalWrite(Pin7, LOW); //stylus touching phone. Where accept button is.
delay(500); // half second delay
}

graemma1:
I thought the L298 was the stepper motor??

An L298 is a H-Bridge driver. Just looking at the picture would tell you that it is not a motor.

I think I get it now - you don't have any stepper motor - this is what they look like.

You just have the L298 to drive the solenoids. Is that correct?

...R

1.1A at 5V for the solenoids. No way you can connect them directly to the Arduino pins. Easiest is to use a relay board, or build your own circuit as described for the solenoid.

Robin2 - yeah i have the L298 to drive the solenoids. On the description it said stepper motor. I told you i didnt have a clue. lol

Gabriel_SWE - The solenoids are not connected directly to Arduino pins, they are connected to the L298 H bridge driver :wink:

Using H bridge instead of relays for solenoids is quite un-orthodox.
For an H bridge you need 3 pins. Dual H bridge 6 pins.

Open library manger and search for L298N. You will find a few libraries. Install one of them and look at example code. Library manages the pins. I think the best way is to set motorspeed to 255 (avoiding pwm output to solenoids) and use motor enable/disable to control the solenoids.

Gabriel_swe:
Using H bridge instead of relays for solenoids is quite un-orthodox.
For an H bridge you need 3 pins. Dual H bridge 6 pins.

If you just want ON/OFF action or PWM in a single direction with an L298 you can control it with 1 pin. Bi-directional PWM needs either two PWM pins or 1 PWM pin and two direction pins.

...R

The L298 drops nearly 2 Volts at 1 Amp so the supply voltage to the L298 will nee to be high enough to compensate. Supply voltage needs to be at least minimum solenoid pull in voltage + 2V.

L298 data sheet (see Vcesat)