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

No comments:

Post a Comment

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...