Monday, July 20, 2020

Stepper Motor direction control using S9110 Bridge

Using Stepper Motor from EPO Summer Camp

Motor driver L9110S H Bridge, a Stepper Motor,  jumper cables are available at EPO Houston or online.

Stepper Motor Wiring:  

From Motor Driver to Arduino

  • A1B (white) to pin 8
  • A1A (gray)   to pin 9
  • VCC  to 5V
  • GND to GND
  • B1B (orange) to pin 10
  • B1A (blue)    to  pin 11
From Stepper Motor to Motor Driver:  Just had to match cables from stepper motor. However for some stepper motors the polarity pairs may be different.

Code

From video, but changed for stepper motor being used. (ie steps/rev are different)
Homework button code is not shown on purpose. 
Hint: Add button and signal in and out wires to the Arduino.

#include <Stepper.h> 

// The stepper motor used is 7.5 deg/steps => (1 rev/360 deg) *(360 deg/7.5 steps) = 48 steps/ rotation.
const int stepsPerRevolution = 48;  // chg this to fit the #steps/rev for specific motor
Stepper motor(stepsPerRevolution, 8,9,10,11);  // pins 8-11

int motorSpeed = 10;  //24  in rpm = revolutions/minute
int delayTime = 3000;

void setup() {
  Serial.begin(9600);
  motor.setSpeed(motorSpeed);
}

void loop() {
  motor.step(stepsPerRevolution); // fwd 1 revolution
  delay(delayTime);
   motor.step(-stepsPerRevolution); // reverse direction 1 rev
  delay(delayTime); 
}

Sunday, July 12, 2020

Basics Blinky, DC Motor, PhotoResistor


EPO Summer Camp Week 1 Arduino UNO Basics that can be reused:  
Blinking LED, DC Motor, Dim LED, read Photo-resistor


Overview

  •  Blinking LED  using digitalWrite to send power signal  HIGH for on or LOW for off
  •  Dim LED using analogWrite to send power signal (0-255)
  •  DC Motor  reuse code for blinking  and din LED to power motor on/off or vary speed
  •  Photoresistor senor  
    •  reuse circuit just replacing LED with sensor  
    •  change code analogRead to light read value 
Using Arduino SW from here:  https://www.arduino.cc/en/main/software

Connection Overview (in words)

All 4 projects can use Arduino pin 3 for output or input. Pin 3 was chosen because it is a PWM pin, which allows it to write and read analog signals.( More on PWM in week 2 Stepper Motors.) However A0, analog pin 0 can also be used for analog examples.
The 300 Ohm resistor is needed for LED and analog sensor. The DC motor needs electronics, which supplied by the L9110S H Bridge.
  • Arduino Pin 3 to LED + on breadboard
    • Pin 3 is also a PWM pin
    • digital PWM pins are marked with a tilde, ~  and can be used with analogWrite()
  • LED - on breadboard to 220 Ohm resistor
  • Other side of resistor to GND on Arduino 

Code Overview

Setting up
  • define variables - global and constant
    •  int myDelay = 2000;  // Time on and off in milliseconds so 1000 = 1 sec
  • In  setup() 
    •  setup the pin(s) used: pinMode(3,OUTPUT); or pinMode(3,INPUT);
    •  Serial.begin(9600); // set-up to use Serial.println(x);  baud is how fast; 9600 is standard
  • In loop() define any local variables.  Like saving sensor value to print or react to it.
in loop() - repeatly called
  • digitalWrite for on/ off  or min/ max control only
  • analogWrite(PWM 0-255) for %power  and direction control (on digital PWM ~ pins)
  •     LED brightness
  •     Motor speed
  • analogRead(A1) for input (0-255) from analog sensor like photo-resistor
    • Analog pins are read only

Blinky

The HW Hello World. Turn something on and off. This circuit and both digital and analog code can be reused.

Digital - just on/off = Blinky
  digitalWrite(3,HIGH); 
  delay(myDelay); 
  digitalWrite(3,LOW); 
  delay(myDelay); 

Dim LED

Analog - vary the power so the LED is brighter or dimmer. 
So on/dim (instead of off)
   // range of power 0-255
  analogWrite(3,200);  // Bright
  delay(myDelay); 
  analogWrite(3,20); // Dim (very small looks like its off)  
  delay(myDelay);
 
Analog - pin reads in value from the analog sensor.
  int lt = analogRead(A1); 
  Serial.println(lt);

DC Motor

Reuse Blinky code using Analog  for DC motor to run fast (200) then very slow (20).
Uses L9110S DC Stepper Motor Driver H Bridge 

Connection Overview (in words)


H Bridge to Arduino
  • VCC signal (power +) on H-Bridge to Arduino Pin 3
  • GND on Arduino to  H-Bridge to Arduino Pin 3
  • Power to 3.3V
H Bridge to motor
  • red to 1 side of motor
  • black to other side of motor
  • side picked decides "polarity" of motor and direction it turns
    • need for understanding driving wheels to move See Avoiding Obstacles post later (coming)

Photoresistor

Connection Overview (in words) 
  • Arduino Pin 3 to Photoresistor - on breadboard where resistor starts.
  • Other side of Photoresistor power (3.3V) to Arduino 3.3 V power
  • GND on H-bridge to Arduino  GND

All Things Arduino

As I learn electronics, its good to use different hardware. Arduino UNO is popular and simple. I hope to apply what is learned to other hardware like, but not just Raspberry Pi. 

This blog will:
  • Try to document so projects, (mostly) simple and hard can be recreated.
  • Reference good existing tutorials on a topic with summary and added info.
Here goes....


Arduino and pump

Motor Driver witn 9110 or 9110S  https://www.laskakit.cz/user/related_files/l9110_2_channel_motor_driver.pdf https://docs.sunfounder.com/pro...