GithubHelp home page GithubHelp logo

kckuei / arduino-fun Goto Github PK

View Code? Open in Web Editor NEW
0.0 1.0 0.0 268.94 MB

Documents my first foray and some working notes into microcontroller programming using the Arudino Uno Starter Kit.

C++ 100.00%

arduino-fun's Introduction

Arduino Projects

Documents my first foray and some working notes into microcontroller programming using the Arudino Uno Starter Kit.

Setup

In addition to the project manual, these docs were helpful with getting started:

Arduino IDE 2.0 Installation

  • I used the appImage installation option for linux
  • Don't forget to enable permissions to run: Properties > Permissions > Execute: > Click Allow executing file as program

Error on Blink Demo

One issue I encountered with uploading programs using the IDE:

Sketch uses 924 bytes (2%) of program storage space. Maximum is 32256 bytes.
Global variables use 9 bytes (0%) of dynamic memory, leaving 2039 bytes for local variables. Maximum is 2048 bytes.
avrdude: ser_open(): can't open device "/dev/ttyACM0": Permission denied
Failed uploading: uploading error: exit status 1

And the resolution:

In root:

sudo chmod a+rw /dev/ttyACM0

Projects

01. Get to Know Your Tools

An electricity/circuits refresher, and primer of how breadboards work.

Concepts

  • transducers = convert other forms of energy to electrical energy or vice versa
  • sensors = convert other forms of energy to electrical energy
  • actuators = convert electrical energy to other forms
  • circuits = are closed loop systems that convey electricity from a power source (e.g. battery) to something that does something useful (load)
  • power flows from high to low potential
  • ground generally point of least potential energy
  • in DC circuits, flow is unidirectional
  • in AC circuits, flow changes direction every 50 or 60 Hz
  • current = amount of charge flowing past a point in circuit (amps)
  • voltage = difference in energy between a point in a circuit and another (V)
  • resistance = how much a component resists flow of current (ohms)
  • V (voltage) = I (current) * R (resistance)
  • Breadboard = protoyping board for building circuits that doesn't require soldering. Consists of multiple horizontal/vertical rows of conductive metal strips with wells that you can easily plug into.
  • reading resistor bands
    • are either 4 or 5-band
    • the band colors are color-coded to digits
    • for 4-band resistors
      • 1st band = 1st digit
      • 2nd band = 2nd digit
      • 3rd band = number of trailing zeros/multiplier
      • 4th band = tolerance

Building a Simple, Series, and Parallel Circuit

Simple Circuit Series Circuit Parallel Circuit

02. Spaceship Interface

A digital I/O to mimic those snazzy 1970s sci-fi spaceship interfaces.

Picard Engage

Concepts

  • Skech = an Arduino computer program. Every sketch has two main functions: a setup() and loop() function.
  • The setup() function is run once at the start of the program, and the loop() function is run repeatedly like a while loop.
  • The digital pins on the Arduino board can be used to listen for or recieve a signal (i.e. what is the state?) or trigger a response (i.e. set the state). The response is binary, i.e. it is either on/off (or low/high in terms of voltage).
  • Use pinMode() to configure the digital pins as either inputs or outputs in setup().
  • Use digitalRead() to read a state (e.g., listen for a signal like a button push).
  • Use digitalWrite() to set the state of a digital pin (e.g., light up a button).
  • Use delay() to halt execution of the code for a set duration.

Beep-Boop

Press Button Toggle Button

Microcontroller Program.

03. Love-O-Meter

Registers how hot you are.

Concepts

  • Arudino has a build-in analog-to-digital convert (ADC).
  • Analog pins 0-5 report a value between 0-1023, which maps to a range from 0 to 5 volts.
  • Use the Serial.begin() command in setup() to open up a serial port to communicate with the cpu.
  • Then you can use Serial.print or Serial.println to log values.

These Hands were Made for Hold'n

Temperature Meter

Microcontroller Program.

04. Color Mixing Lamp

Create a lamp that smoothly changes colors based on external lighting conditions using a tri-color LED and three phototransistors.

Concepts

  • phototransistors = components that generate a current proportional to quantity of light absorbed.
  • LED = light-emitting diode, emits light when current/voltage is applied.
  • A fading LED effect can be achieved by either directly manipulating the applied voltage, or using pulse width modulation (PWM).
  • The output of the Arudiono is non-variable constant 5V voltage, therefore need PWM to achieve this affect.
  • How it works:
    • PWM rapidly turns the output to HIGH and low over a fixed period of time. Rapidly turning the pin HIGH and LOW emulates a changing voltage, perceptually akin to frames in a movie.
    • Duty cycle = the percentage of time that a pin is HIGH in a period.
    • A pin that is HIGH half of the time, and LOW the remaining time has a duty cycler of 50%.
    • The lower the duty cycle, the dimmer the LED.
  • Programatically, the duty cycle is set by passing a second argument to digitalWrite().
  • To measure the relative amount of red, green, or blue, we can apply filters to the individual phototransistors. E.g.m, red filter passes only red light, green filter only passes green light, etc.
Kinda Moody Red to Blue

Microcontroller Program.

Variant: A Nightlight to Keep Scary Monsters Away

It brightens as the external lighting fades:

  • Uses the same tri-color LED and one phototransistor.
  • Interestingly, the response and calibration/fudge factor is sensitive to the orientation of the phototransistor with respect to the light source.
  • For best results, it's probably best to use a 2-3 phototransistors oriented at different angles, and then take the average of their sensor values for a less biased result.
  • The LED itself also emits light which the phototransistor may be picking up, so it may be a good idea to isolate/obscure the line of sight of the phototransistor from the LED.
On/Off Gradual Fade In/Out

Microcontroller Program.

05. Mood Cue

Uses a servo motor to make a mechanical guage to point to the mood for the day.

Concepts

  • Servo motors = motors that move to a specific position, typically a 0-180 degree range of motion.
  • Similar to PWM in LED's, servos expect a number of pulses to tell them what angle to move to.
    • Pulses vary between 1000 and 2000 microseconds
    • Arudiono comes with a Servo.h library for controlling the motor
  • Use map to map/change the scale of the analog input from 0-1023 to 0-180 degrees.
  • Decoupling capacitors are used to reduce, decouple changes caused by components from the rest of the circuit (e.g. voltage drops from drawing more current due to already being in motion)
  • Capacitors are directional, and also have a cathode/anode side.
  • CAUTION: Putting capacitors in backwards can make them explode.
Testing Testing :) :| :) :|

Microcontroller Program.

Note: The servo signal and power wires (white and red wires) are reversed compared to the manual.

Variant: Decision-Maker

Push a button and have it pick a choice for you (yes, no, maybe)

Idea: Disco Board

Tiny discoteque light board to impress the ladies

06. Light Theremin

Uses a phototransistor and a piezo element to make a light-based theremin.

Concepts

  • theremin is an instrument that makes sounds based on nearby movements, e.g. musician's hands.
  • piezo is a small element that vibrates when it recieves electricity; the displacement of air hence creates sound waves.
  • We use the map() function to map the light intensity from a phototransistor to a pitch or frequency. That frequency or pitch is then specified in a tone() function that manipulates the sound emitted from the piezo: hence the 'light thermin'.
  • millis() returns the number of ms elapsed since start of program. We use it to add a calibration state in the setup by mapping the min/max phototransistor values representative of someone playing the light thermin.
  • tone() is a function that can be used to play a sound (given a pin), that takes a pitch and duration.

[Video placeholder]

Microcontroller Program.

07. Keyboard Instrument

Uses a few resistors and buttons to build a musical keyboard.

Concepts

  • resistor ladder is a technique for reading a number of switches using the analog input; consists of arranging several switches in parallel; each button when pressed engages a different number of resistors and hence voltage level, which gets passed/read to the input analog pin.
  • Each of the switches acts as a voltage divider.

[Video placeholder]

Microcontroller Program.

08. Digital Hourglass

Uses a tilt sensor, array of LED's, some resistors, and Arduino's built-in timer to build a digital hourglass.

Concepts

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.