Hi everyone,
I'm using an Arudnio Uno and I'm programming it to control a stepper motor and a solid state relay.
The code is fairly simple.
If i feed a bunch of character in the serial monitors, it does a specific action as you can see from the code.
However, say for example I keep the relay off, and send a signal to make the motor move, the relay somehow turns on.
// Adafruit Motor shield library
// copyright Adafruit Industries LLC, 2009
// this code is public domain, enjoy!
#include <AFMotor.h>
char v;
AF_Stepper motor(200, 1);
void setup() {
Serial.begin(9600); // set up Serial library at 9600 bps
Serial.println("Stepper test!");
pinMode(8,OUTPUT);//Connecting to the relay
motor.setSpeed(20); // 20 rpm
}
void loop() {
if (Serial.available()>0)
{
delay(50);
v=Serial.read();
if(v=='H'){
motor.step(50, FORWARD, MICROSTEP);
Serial.println("FORWARD");
delay(1000);
}
if(v=='L')
{
motor.step(50, BACKWARD,MICROSTEP);
Serial.println("BACKWARD");
delay(1000);
}
if(v=='A')
{
motor.step(100, BACKWARD,DOUBLE);
Serial.println("BACKWARD");
delay(1000);
}
if(v=='B')
{
motor.step(100, BACKWARD,DOUBLE);
Serial.println("BACKWARD");
delay(1000);
}
if (v=='Y')
{
digitalWrite(8,HIGH);//turns relay on
delay(200);
}
if (v=='Z')
{
digitalWrite(8,LOW);//turns relay off
delay(200);
}
else
{
Serial.println("WRONG INPUT");
}
}
}


