LearnElectronicsWithArduino

From ArduinoInfo
Jump to navigation Jump to search

UNDER CONSTRUCTION 4/15/25

Learning Electronics With Arduino

What IS "Electronics" ??

Electronics is a scientific and engineering discipline that studies and applies the principles of physics to design, create, and operate electrical devices like Cellphones, Computers, Vehicle controls, Robots etc. See: (WIKIPEDIA) It's much more than just switching some power on and off.

IF You're Really New To This: See some of the Jargon you'll want to know HERE

Electricity Basics

There are a couple of little problems:

ElectInv.gif

NO WORRIES! We will show you the ways to make these powerful tools Visible so you can use them.

ELECTRICITY WORDS

These 3 words are the basic things you'll learn about here. Right now they're just words but you will touch them soon!


VOLTAGE is the electrical pressure or force that drives current through a circuit. It's measured in volts (V) and represents the potential energy difference between two points in a circuit. EXAMPLES:

  • 1.5V DC AA battery
  • 3.7V DC Lithium Battery
  • 12V DC Car battery
  • 120V AC - USA usual outlet
  • 220V AC - England, France, Egypt etc. usual outlet
  • 380V AC - 3-phase line to line voltage (220V times the square root of 3 - Why?)


CURRENT is the flow of electric charge through a circuit. It's measured in amperes (A) or amps and indicates how many electrons are moving through the circuit Each Second. EXAMPLES:

  • 0.02 A LED (Light emitting Diode)
  • 6.0 A Automobile headlamp
  • 0.5 A USA 60 watt old type light bulb
  • 0.05 A USA LED Light Bulb (Same light as old type bulb)
  • 4.0 A Automobile windshield wiper motor
  • 350 A Automobile engine starter motor


RESISTANCE opposes the flow of current in a circuit. It's measured in ohms (Ω) and depends on factors like the material, length, and cross-sectional area of the conductor. IF we know Voltage and Current in a circuit we can find resistance by dividing Voltage by Current: R=V/I EXAMPLES:

  • Automobile Headlamp: R=V/I R= 12/6 = 2 Ohms resistance
  • Old type 120V 60W bulb : R=V/I R=120/0.5 = 240 Ohms resistance
  • Automobile windshield wiper motor R=V/I R=12/4 = 3.0 Ohms resistance

When you start connecting real devices like lights and motors, sometimes you will need to figure this kind of stuff.

CIRCUITS

Led circuit1.jpg

You probably know that electricity only flows when there is a path or circuit from a source of electricity through some load (like an LED) and back to the source

We will now start using Arduino to try out these ideas and get to understand them.



Learning by using Arduino

ARDUINO is a small $15 computer that you can use to make many interesting projects. It is easy to connect things to like SENSORS (for temperature, light, pressure etc etc.) and ACTUATORS (like LED lights, motors, displays, valves etc etc.) You will program it to run the things you design.

RoboRED-Annotated-1024-0220-2.jpg

The YourDuino RoboRED is used in your kit. (You may have an almost-identical version that is Black) It is equivalent to an Arduino UNO but has several added features, like easy-to-connect pins on every Input/Output pin. Near the upper left is the PWR LED which should light up whenever the board is plugged into a USB connection, or has power from an external power supply.
At the upper left there are two added red LEDs which will blink when a software sketch is being downloaded to the board, or other data is being transferred over USB.
In the center is a red LED which is internally connected to pin 13 through a current-limiting resistor. It should blink after you load the example BLINK software sketch. The colored 3-pin connectors on every I/O Pin make it easy to connect many input and output devices. Vcc(+5V) pins and (Ground) pins with every I/O pin are good for connections to breadboards etc.



Using Arduino to understand Electronics

If we understand this stuff, we can start to make many more-interesting things work. Let's THINK about it. We have wires and circuits and electricity. It's easier to think about it if we use some SYMBOLS to make DIAGRAMS. Let's look at This Diagram :

Rails3LED13.jpg

Slow Down Time: Look carefully:

Your RoboRED (Arduino) runs on Electricity. A supply of '5 volts' comes from the USB cable or batteries. At the top and bottom of the diagram there are two main connections:

5 VOLTS

GROUND

Find them on the diagram. What about "RAILS"? A lot of things connect to that 5 Volts and that Ground. Tekkie-Speak calls them 'rails' like railroad rails running through a project or circuit. Some call them "BUSSES" like "The 5 Volt BUS" More Jargon!

NOTICE: On the diagram, there is a Resistor connected to an LED from pin 13 down to Ground. Soon you will turn pin13 ON (HIGH to 5V) and light it up, and you will turn pin13 OFF (LOW to Ground) so you can make it blink.




RoboRed-Annotated-2--CU-800.jpg

Now take a CLOSE LOOK here at the actual Arduino. This detail shows the ROWS of PINS on your arduino: Look for the RED (5 Volts, remember??) look for the BLUE (Ground) and note there is also a YELLOW row (Where you will connect may other things like Sensors and Actuators. Now look at YOUR actual arduino. See those rows of pins and their color?? OK!




What is Physical Computing ?

Using a computer to SENSE real things like temperature or light or pushbuttons and using the computer to CONTROL real things like lights and motors is called PHYSICAL COMPUTING.

  • One way to do this is to write code using the Arduino IDE system and upload it directly to an Arduino. This code is written in an easy version of C and C++ that is specific to Arduino.
  • A second way is to write your code in a Block Oriented visual Drag and Drop system called MIXLY . We will show you how.

And you will need HARDWARE . You will start with a "KIT" which is a box (Photo Below) that includes an Arduino Microcomputer, cables, and a selection of sensors and actuators, LCD display etc. so you can get right into connecting your Arduino, connecting devices and trying out simple Software Sketches with MIXLY.

SO.. What IS ALL THIS STUFF??

750px-MakerWorkshopMicrocomputerNotArduino2-900.jpg


Kit Contents LISTS

Here is the list of all the parts in the kits from Yourduino. For some schools parts were added to the standard kit. They are marked "ADD" on the left side. The kits are like the large photo above PLUS those "ADD" parts.

Media:KitNumbersOriginal-Added.pdf

HOW Do These Things Work TOGETHER ? ?

Here is how we will THINK about Arduino. There are three main things that are part of all automatic systems:

[Sensor Inputs | Software Decisions | Action Outputs]


All automatic systems, from a simple thermostat to the Mars Rover have those 3 parts.

When you create a new project, YOU will decide the three things:

  • WHAT Sensors and Inputs you will CONNECT to Arduino, and on What Pins
  • WHAT Software Decisions you will make as you write CODE
  • WHAT Output Action Devices will you connect to Arduino, and on What Pins

Sensor Inputs:

These can be simple like a pushbutton switch or complex like a GPS receiver or an accelerometer. There are hundreds of possibilities for sensing things in the Physical World.<br

Action Outputs:

These can be simple like an LED or complex like the motors and motion control of a Robot.

Software Decisions:

This is where you decide what Sensor Inputs Arduino will look at, what Decisions it will make , and what Action Outputs it will cause to happen. You will decide how your project Behaves by how you make decisions in software. You make this actually work by writing software code statements. The software should be organized so these 3 things happen over and over again in Loop:

  • READ SENSORS
  • MAKE DECISIONS
  • TAKE ACTIONS



There are two different types of Inputs and Outputs and you need to understand the difference:

DIGITAL INPUTS and OUTPUTS

'DIGITAL things are BITS that have only two possible values: 0 or 1. Like "The light is OFF or ON"

ANALOG INPUTS and OUTPUTS

'ANALOG things are VALUES that have a Range of Values. Like "The light is BRIGHTER or DIMMER or in between.

The STRUCTURE of an ARDUINO SYSTEM

Let's take a look at this diagram that shows the structure or "architecture" of a microcomputer based system like Arduino.

This shows examples of the kinds of Digital Input devices you might use. And Digital Output devices.

It also shows examples of Analog Input devices and 'Analog Output devices.

AND it shows examples of devices that communicate with SIGNALS that are a sequence of Digital Ones and Zeros. They communicate Data with those signals.

ArduinoArch3-1024.jpg



OK, now You go ahead and control A Digital Output (an LED) with software you write.

SOFTWARE TIME - CREATING MIXLY SKETCHES


Start the MIXLY software on your computer. Let's take a little while to get used to creating MIXLY sketches by dragging functions out from the library on the left. Then we'll come back and start connecting your GIS-MakerSpaceElectronicsCourse kit parts and making more interesting things. We will give you MIXLY examples for each of the devices in the kit.

LOOK AT THE MIXLY MAIN SCREEN

Mixly1.jpg


Slow Down! Look at all the parts of the screen. Soon you'll be used to it and get a lot of stuff done.

  • The LEFT SECTION: "BLOCKS" has many things you can pull out onto the main screen. The example shows 4 blocks that have been pulled out, and clicked together.
  • The CENTER SECTION is where you place your blocks. You also type in or select choices or numbers in the blocks
  • UPPER RIGHT selects Language. It may start in Chinese and you'll have to set it to your language



Here is another view of the MIXLY screen. We will use these marked things later:

MixlyAnnotated.jpg

  • BOTTOM CENTER: (Red marked) Things you MUST set up to have things work.
    • FIRST, YOU MUST SET THE CORRECT BOARD TYPE AND SERIAL PORT
      • "Arduino/Genuino UNO" is correct for us
      • The entry "COM3" in the example will be different. On the PC There will usually be only one choice. But you may have COM1 and then some higher number which is Arduino.
      • On the MAC, pick the entry that has "tty" in it.
    • BOTTOM CENTER also has two buttons:
      • "Compile" Checks all the BLOCKS you set up in your code. It might cause error messages that would be found in the LOWER SCREEN SECTION
        • You will see a LOT of lines roll by in the LOWER SCREEN SECTION. LOTS of Tekkie stuff you fortunately don't need to worry about!
      • "Upload" does both "Compile" and if no errors it creates your Arduino code and UPLOADS it into the RoboRED board, and makes it run.


After UPLOAD your actual code will start running in the RoboRED or UNO board! In the example, the Pin 13 LED will go HIGH for one second, Then LOW for 1 second. This is called "BLINK!" Next, we'll show you how to DO that!

YOUR FIRST MIXLY ARDUINO SKETCH:

The visible-to-You part of an Arduino software program is called a SKETCH. But the Sketch becomes alive when you upload it to your Arduino. Let's walk through Editing a MIXLY Sketch and Verifying it and Uploading it:

OK, Looking at YOUR MIXLY screen: In the BLOCKS section, click IN/OUT. Should see:

2020-03-30 121106.jpg

NEXT: Click on the "DigitalWrite" block, HOLD and DRAG it to the right out onto your screen. Should see:

2020-03-30 121031.jpg

THAT is the way you will find and drag out MIXLY Blocks to use them in your sketches!

 

BREAK: MIXLY MESS AROUND

Let's get back to your own Software!

Mess around with clicking on BLOCKS sections, and dragging stuff out.

How do you get RID of a block you pulled out? GRAB it with your MOUSE and THROW IT OVER YOUR LEFT SHOULDER! OR click "NEW" in the center tool bar. And there is a TRASH CAN on the lower right too.

FIRST REAL MIXLY SKETCH

NOW: Let's try to do something real. Clear the screen with "NEW" and drag out a "DigitalWrite" block.

NOTICE that there are two SETTINGS you can change: PIN# and Stat. Click PIN# and set it to 13. Leave Stat as HIGH.

DUPLICATE the Block; RIGHT-CLICK and pick DUPLICATE. Drag that block down to make some room. (NOTE: The best place to grab a block is on the little bump on its lower left). On the bottom block change HIGH to LOW.Like this:

2020-03-30 125044.jpg

NOW get a different block:Click on Control and find and drag out a DELAY block.

2020-03-30 125452.jpg

Make sure it's separate.Then Duplicate it.
Finally, drag the blocks until they 'click' together like this:

2020-03-30 130014.jpg

Now LET'S TRY IT OUT!

In the center tool bar, click "Compile". WAIT.. The first time you do this it will take a long time. LOTS of TekkieStuff rolling by in the bottom window. Should eventually say "Compile success!".. Later this will take less than 30 seconds.

HARDWARE TIME!

Get your RoboRED or other Arduino and it's USB Cable. Plug them in. At least one LED should light up on the board. It MIGHT blink another LED. Before you plug in an Arduino the center bar will look like this: 2020-03-30 131019.jpg When you plug in, it should show a number like "COM3" or similar. If there are more than one, pick the highest number. Should look like this:
2020-03-30 131100.jpg

WHAT ARE WE REALLY DOING, HERE?? We are making a computer (The RoboRED or Arduino UNO or other) DO what we TELL it to do.

Later you will be hooking up many other parts, like LEDs and Servomotors and controlling them. For now, we will start by using one LED that is already connected on the Arduino board.

The PIN 13 LED: Every Arduino has one LED permanently connected to PIN 13, and we will use that to get started. And soon we will talk about PINS, BITS, VOLTAGE, HIGH, LOW and ALL THAT.

OK,DO IT! Click on Upload. Watch the stuff roll by as it does Compile, and THEN you should see "Upload Success!"

AND the LED on your Arduino board should blink ON 1 second, OFF 1 second..

WHAT'S REALLY HAPPENING??

Your sketch controls that LED with the "DigitalWrite" block.

THIS turns the LED ON: 2020-03-30 195254.jpg

and THIS turns it off: 2020-03-30 195607.jpg
The SKETCH you created DID things. Check it out. Look at the 4 blocks and what they do:

2020-03-30 130014.jpg

  1. Turn Pin 13 LED ON (HIGH)
  2. Delay 1000 Milliseconds (1000/1000ths of a second = 1 second) WATCH the LED being ON
  3. Turn Pin 13 LED OFF (LOW)
  4. Delay 1000 Milliseconds (1000/1000ths of a second = 1 second) WATCH the LED being OFF

And LOOP (Do that over and over forever, or until you turn it all off).


OK. Mess with it and see what happens: Change the first "Delay" to 100. Upload. Do you see a short blink??

Change it to 10, then 1 and Upload (Cover the LED with your hand to shade it). Can you see 1/1000 of a second blink?? If you had a BRIGHT LED you could make a strobe light. We'll try some other things in a minute.

UnderConstruction SECTION 4/6/25 (OUTLINE below)

'NEXT: Use Arduino as a VOLTMETER and learn Voltage Dividers

OK, its time to continue learning about Voltage,Current, Resistance and All That. You will need that to be able to build interesting projects.

If you have a multimeter / Voltmeter device you can use it also.

You need a VOLTMETER so you can actually sample the invisible Voltage at different parts of circuits. Soon you will be writing your own sketches but here's a sketch you can use to make Arduino into a 2-channel Voltmeter:

Here's what it looks like: There are Two Analog inputs that can read a range of voltages. One is connected to +5V and the other is connected to the center of a two-resistor Voltage Divider. (You'll hear more about Those!).

ArduinoVoltmeter2chan.jpg


Here is a pre-written Arduino Sketch that we will use:

ArduinoVoltmeter2chan 2.jpg






The .MIX file is HERE

NOTE: To download .mix files, RIGHT click and "Save Link As"




CONNECTING to Arduino

OK. let's CONNECT some stuff with WIRES, so we can really understand what is going on.

We will use things like this from the Kit to get started:

  • BREADBOARD: A prototyping tool used to build temporary circuits without soldering
  • diagrams (Samples?)
  • First connections: +5v , Gnd.
  • Measure with Multimeter if available
  • Breadboard: Bond top to bottom Voltage and ground rails??
  • Example: Resistor and LED To 5V and to Ground.
  • THEN Mixly and Blink
  • Then external Resistor/led

ANALOG SENSORS

Voltage Dividers:

VoltDivider2.png
Now let's figure out this Voltage Divider stuff. Look at the diagram above. A Voltage Divider has 2 resistors connected in Series, connected to a source of (V)oltage and a (G)round or common point. The connection in the middle between the two resistors is the (S)ignal Output, and is some fraction of the Input Voltage. So we can connect a pot used as a Voltage Divider into the breadboard and connect it with wires.. As we move the pot, the output voltage going to Yourduino varies from 0 to 5 Volts and all the values in between. The way Arduino works gives values from 0 to 1023. If we have a photoresistor connected in series with a resistor, we have a voltage divider that changes with the light intensity, giving us a varying voltage.

What if you want to measure voltages that are more than 5 volts? You use a Voltage Divider to reduce the voltage. If you make a 3 to 1 ratio voltage divider (say, 20K for the top section and 10K for the bottom), then you can read voltages from 0 to 15 volts. Good for automotive batteries. You could to this by putting two of your 10K resistors in series for the top resistor.



Several Useful Voltage Dividers

Here are several ways "Voltage Dividers" are used with Arduino: (Better Graphic Coming!!)

VoltageDividersDiagram.jpg

Those examples (one at a time!) are:

(A) equal voltage divider.  The voltage is Half of applied voltage. We use +5V so that mid point will be 2.50 V

(B) three equal resistors. Voltages are 1/3 5V and 2/3 5V

(C) Potentiometer: continuously variable voltage output 0..5V

(D) Same as A but a light dependent resistor AKA Photocell is the top resistor. In dark, voltage out is almost zero. In sunlight it would be almost 5V . So: Increasing voltage out with increasing light. In Mixly, the value could be compared to a constant and then action could be alarm etc.

(E) Same as A but top resistor is temperature dependent "Thermistor". Lower resistance with higher temperature.


The Light Dependent resistor and the thermistor are both rated as 10K ohms at a standard condition. Its 25C for the Thermistor. I forget the standard for the light.

Using a Multimeter to measure voltages (Optional: can go directly to Arduino/Mixly reading voltages)

Get a multimeter and use it to see if we understand this Voltage Stuff. Strip two separate wires off the Rainbow cable. BR (Brown) and RD (Red) would be good. Cut off the connectors at one end. STRIP about 1 to 2 inches of insulation off the cut end. Wind the RD wire tightly around the Positive (+) lead from the multimeter. Use some tape (like used on paper) around it to make it stay in place. Do the same for the BR or other wire.

Connect your actual Arduino with a USB cable to your computer. One red LED should light up. Another LED might be blinking. Learn how to set the multimeter to read "DC Voltage". Then connect the minus (-) lead (BR or whatever you used) to ANY of the pins in a BL (Blue) row. Connect the plus (+) lead (RD or whatever you used) to ANY pin in the RD (Red) row.

What does the meter read?? SHOULD be close to but not exactly 5.0 V. Connect the (+) lead to any of the Ground,(Blue) pins. It should read almost 0.0V




DIGITAL SENSORS AND DIGITAL ACTUATORS

Now we will go beyond "Digital Binary" devices that are only ON or OFF.

Many complex and useful devices do much more than turn ON or OFF or DIM. One way they can do this is by sending a longer pattern of On and Off, 1s and 0s, that convey information (such as temperature values). This pattern is a called a Digital Signal

Understanding these digital signals is like knowing a foreign language. We use the word "protocol" to describe a digital language. Like a foreign language, you need a translator to understand each digital protocol. But! Don't worry. Lots of people, all over the world, use Arduino, and they have written translators for Arduino to understand all kinds of digital protocols, for all kinds of devices. Just like you can find a foreign language dictionary at your local library, these protocol translators are in libraries too. These are "libraries" of software that the Arduino team or other people have written for us to use, and are already installed into MIXLY. When we figure out how to do something cool, or how to understand a new digital protocol, we might put our code in a Library and share it with others.


DIGITAL SENSORS

Pushbutton

Let's start with the simplest kind of sensor: a Pushbutton. YOU push the button, it puts out a 1 or a 0 . You connect it to an Arduino Input pin.

We already know how to turn the Pin13 LED on, right?? OK here's a pushbutton wired to the Arduino:

SingleSwitch.jpg

Use a 3-pin cable to connect the switch to Arduino Pin 2. Then start Mixly.

Drag out a Digital Write block so you can control the LED

Drag out a Digital Read block so you can see what the Switch is doing.

Hook them together like this:

SwitchPin2 LED-Pin13.jpg

With Arduino connected by USB, UPLoad that. Try pushing the Button! What happens??


UH-OH The LED is ON before you press the button. And if you press the button the LED goes OFF.. The world is UpsideDown.

Rails3.jpg

REALITY CHECK TIME Look at our Diagram. Look at the SWITCH, the PULLUP RESISTOR and the INPUT.

What is the INPUT connected to when the switch is NOT pressed?

It's pulled UP to a "1" (Also Known As HIGH AKA +5V) so the LED is turned on. When it's pressed, INPUT is connected to (GROUND AKA "0" AKA "LOW").

Get used to thinking about Arduino DATA as "1" or "HIGH" or "+5V". OR "0" or "LOW" or "GROUND".

IT's EASY TO FIX! LET's DO IT.

Think about this LOGICically. Like what is True or False. In Mixly click on Logic on the left. Drag out a "NOT" . Also drag the "Digital Read" off the "Digital Write". Connect the NOT before the Digital Read. Like this:

NOT Switch.jpg

Then move the Not Digital Read back to the Digital Write. Like this:



FIXED NOT.jpg

Now UPload that. How does it work now?? You can always FIX any data that is UpSideDown.





BUZZER

BuzzerBeeper.jpg

Now that you can make the LED come on when you push the button, let's also make a noise when you push it. Look in the Kit for "Buzzer Beeper". They are small round black parts. See the photo to tell them apart. You want the BUZZER. Note that one connection is marked (+). See INFO HERE

Get the multicolored RIBBON CABLE out of the Kit. SEE INFO HERE NOTE: one side starts with BRown-ReD-ORange. Grab BR and RD close to the end and strip them off together separate from the rest. Now you have a "Cable".


ButtonBuzzer.jpg

Here you can see the small black BUZZER. Note the (+) pin and push the RD wire from your cable onto it. Push the BR wire on the other pin. Then connect the RD-BR cable connected to Arduino. BR to Pin13 Blue (Ground) and RD to Pin13 Yellow (Signal)


Analog: Potentiometer sets blink delay

AnalogPotentiometerValueSetsDelay.jpg

PotentiometerBreadboard.jpg Here is a Potentiometer on a breadboard we used for this example:

This example reads the value of a Potentiometer (like a volume control) and displays the value on the Serial Monitor. It also sets the delay in blinking the Pin13 LED.

Here's a Mixly sketch that does that.



Photo (light) Sensor Brick

LightSensorBrick.jpg

This is a sensor that reacts to the light level by changing it's resistance. Often called a PhotoResistor. Here's what one looks like on a small circuit board with 3-pin connector.


PhotoResistorControlLED.jpg

Here's a Mixly sketch that reads the value from the PhotoResistor with an Arduino Analog Input. The value is displayed on the Serial Monitor. The light level is compared to a (changeable) threshold light level and if it is now darker than the threshold the Pin13 LED is turned on. You could use this to operate a relay to turn on lights, as an example.

Richt-Click and "SaveAs" to download the .Mix file. PhotoresistorValues-LED-OnDark.mix





Bi-directional Data: DS18B20 Temperature sensor DHT11?

DIGITAL ACTUATORS

ServoMotor

Servo-sg90-400.jpg

Many complex and useful devices do much more than turn ON or OFF or DIM. One way they can do this is by sending a longer pattern of ons and offs, 1s and 0s, that convey information (such as temperature values). This pattern is a called a Digital Signal.

Understanding these digital signals is like knowing a foreign language. We use the word "protocol" to describe a digital language. Like a foreign language, you need a translator to understand each digital protocol. But! Don't worry. Lots of people, all over the world, use Arduino, and they have written translators for Arduino to understand all kinds of digital protocols, for all kinds of devices. Just like you can find a foreign language dictionary at your local library, these protocol translators are in libraries too. These are "libraries" of software that the Arduino team or other people have written for us to use, and are already installed into MIXLY. When we figure out how to do something cool, or how to understand a new digital protocol, we might put our code in a Library and share it with others.

Next we are going to use some of these libraries to let the Arduino understand how to talk to a Servo Motor and a Temperature Sensor.

(A Signal Output): Standard servos like the one in the Kit are controlled by ON-OFF signal pulses sent to them. They rotate their output shaft to a position you command them to go to. You can connect your servo directly to a 3-pin connector on the RoboRED.

Standard Servo Motors (Servo for short) like the one in the Kit were originally made to steer radio controlled airplanes. They rotate the lever on top to the position that you command. To talk to a Servo, Arduino has to send the right pattern of On and Off, the right protocol. There is a library to translate the position you want to the Servo's protocol so it will understand and work correctly. This gives the Arduino a new kind of Output, that can move things on command. The library that the Arduino needs to talk to the Servo is all ready to go in MIXLY. In MIXLY, libraries make a new kind of block, that does this new thing. To use the Servo, go to the Blocks list, in the Actuator section find the block that looks like this..

Servoblock.png


Let's use the Servo block to control the Servo. For these examples, connect your servo to Pin 9 on the YourDuino 3-pin connector, like this:

Servo robored.jpg

In MIXLY, Fill in the PIN# on the Servo block to tell the block where the Servo is plugged in. Tell the block where to point the Servo by giving it a position in degrees from 0 to 180. Its best not to use the very ends of the Servo range, because the gears can jam. So really, its best to only use from 10 to 170.

And this block knows it takes a while for the Servo to move to the new place. So you can tell the block to wait by giving it a Delay (in milliseconds) to make sure the Servo has time to get to the new place before MIXLY goes to the next block.
MixlyServo.jpg

Here is an example the just commands the Servo to move back and forth . Here is how it looks in MIXLY.
MixlyServoSweepReturn.jpg



CHALLENGE: POT CONTROL OF SERVO

Next, lets take an input we know from before, and use it to control the servo.

With your Pot connected to Analog Pin 0 (First Analog pin) you can make the servo follow your pot position.

Remember: The Pot digital value goes from 0..1023 You will need to map that to the servo 0..180 (degrees)

DC motor controller

NotYet!

STEPPER MOTORS

ABOUT STEPPER MOTORS:

An excellent page about stepper motors is on the RepRap 3D Printer WIKI here:

A stepper motor is a motor controlled by a series of electromagnetic coils. The center shaft has a series of magnets mounted on it, and the coils surrounding the shaft are alternately given current or not, creating magnetic fields which repulse or attract the magnets on the shaft, causing the motor to rotate.

This design allows for very precise control of the motor: by proper pulsing, it can be turned in very accurate steps of set degree increments (for example, two-degree increments, half-degree increments, etc.). They are used in printers, disk drives, and other devices where precise positioning of the motor is necessary.

There are two basic types of stepper motors, unipolar steppers and bipolar steppers:

Small Stepper Motor and Driver Board

MIXLY sketch below..

NOTE: The connections can be confusing! The code examples below assume you are connecting 4 Arduino pins in sequence to pins IN1,IN2,IN3,IN4 on the motor driver board shown. Then in the stepper library statement the correct sequence of motor pins is taken care of. See photos below.

StepperWithDriver.jpg

Example: Arduino Connections

Pins 8,9,10,11 will be connected to In1,In2,In3,In4 Color code sequence: Brown-Red-Orange-Yellow Then Green=Ground, Blue=5V

StepperRoboRED_Connections.jpg

StepperDriverConnections.jpg

It's easier to get the connections right if you use colored wires like THESE

Arduino Pin

Driver pin

Color

8

1

brown

9

2

red

10

3

orange

11

4

yellow

GND

-

green

VCC +5V

+

blue


Then software is initialized in 1-3-2-4 sequence:

Stepper small_stepper(STEPS, 8, 10, 9, 11); //Example Software Sketch below.

NOTE: If your motor just buzzes or runs incorrectly, the connections are probably wrong.

MIXLY SKETCH CONTROLS STEPPER MOTOR

MixlyStepperFixed2.jpg




Get the .MIX file here: https://www.yourduino.com/docs/MixlyExamples/StepperElden.mix




MOTOR DETAILS


This is a 5v 28YBJ-48 Stepper Motor with Gear Reduction, so it has good torque for its size, but relatively slow motion. These motors/drivers are made by the millions for A/C units, fans, duct controls etc. which is why they are so inexpensive.

4 Phase 5 Wire Connection

StepperMotor5V-2.jpg

  • Phase : 4
  • Current : 160 mA per winding (320 mA in 4-step mode) Measured: 250mA stopped, 200 mA running fast
  • Resistance : 31 Ω per coil winding (from Red wire to any coil) (Some 24-28 ohms)
  • Voltage : 5V DC
  • Step Angle (8-Step sequence: Internal Motor alone): 5.625° (64 steps per revolution)
  • Step Angle (4-Step sequence: Internal Motor alone): 11.25° (32 steps per revolution)
  • Gear Reduction ratio: 1 / 64 (Not really exact: probably 63.68395.:1 )
  • SO: it takes (64*64 = 4096 steps per output shaft revolution.. In 8-step sequence.
  • SO: it takes (32*64 = 2048 steps per output shaft revolution.. In 4-step sequence.
  • NOTE: Arduino "Stepper Library" runs in 4-step mode
  • No-Load Pull-Out Frequency : 800pps
  • No-Load Pull-In Frequency : 500pps
  • Pull-In Torque : ≥ 78.4mN.m
  • Wiring Instruction : A (Blue), B (Pink), C (Yellow), D (Orange), E (Red, Mid-Point)
  • Weight : 30g

PROBLEMS?? (Motor Just Vibrates??)

NOTE: If your motor vibrates but does not turn or will only run in one direction, it's wires are probably connected with the wrong sequence.

The Arduino pin connections need to have 4 pins connected to Motor Driver In1, In2, In3, In4 and then the pins entered in the software in the sequence 1-3-2-4 for proper sequencing. Also, The + and - pins near "5-12V" need to be connected:

  • - to Arduino Ground,
  • + to Arduino +5 (for one motor test only) or (best) to a separate +5V 1A power supply.

CONTROLLING HIGHER POWER

  • Power FET brick
  • Relay boards
  • Optoisolation / Crydoms

COMMUNICATIONS SYSTEMS

  • wired systems
  • wireless systems: Bluetooth and WiFi