Skip to content

Instantly share code, notes, and snippets.

@stilldavid
Last active November 15, 2017 14:45
Show Gist options
  • Save stilldavid/691afe17d9c694d122886c6036ff940c to your computer and use it in GitHub Desktop.
Save stilldavid/691afe17d9c694d122886c6036ff940c to your computer and use it in GitHub Desktop.
Class notes from the October 28th Arduino class

Arduino Class 10/28

Thanks for attending the Arduino class!

You might be wondering what the little circuit board your child brought home is and what it's good for. The board is called an Arduino and it's a programmable microcontroller, which is just a fancy way of saying it's a little computer.

During class we all programmed them together to take a reading from a light sensor and activate a servo motor if a threshold was reached. In practice, this made for a super simple motion detector to make a head turn or a pumpkin move if it 'sensed' a shadow. The code is written in an Arduino variant of C++ that we uploaded using the Arduino IDE. The entirety of it is as follows:

#include <Servo.h>

Servo myservo;

void setup() {
  // put your setup code here, to run once:
  Serial.begin(9600);
  pinMode(13, OUTPUT);
  myservo.attach(9);
}

void loop() {
  // put your main code here, to run repeatedly:
  int reading = analogRead(A0);
  Serial.println(reading);
  delay(100);

  if(reading < 800) {
    digitalWrite(13, HIGH);
    myservo.write(0);
  } else {
    digitalWrite(13, LOW);
    myservo.write(60);
  }
}

The circuit, which is put together on the breadboard with jumper wires, looks like this:

fritzing diagram

Any wire will do, and which color you use doesn't really matter, they all conduct electricity the same.

More Circuits

I encourage you to download the free IDE linked below and try to recreate the circuit, or extend it! A great place to get started is go to File -> Examples -> Basics -> Blink which can run on the hardware with no additional circuitry. Plug in the Arduino to a computer with the USB cable and press Upload and watch the built-in LED!

There are a plethora of projects around the Internet that use Arduino at their core, everything from weather stations to mobile robots to weather balloon payloads. Look around and don't hesitate to reach out if you have any questions.

Links

--
David Stillman
me@stilldavid.com

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment