loading

Circuits.io woo!

Step 1: Detecting the Button Presses

Make a circuit to detect when a button is pressed. You can view this in the Serial monitor in the Circuits.io webtool. This is the code:

const int buttonPin = 2;

int buttonState;

void setup() {

pinMode(buttonPin, INPUT);

Serial.begin(9600);

}

void loop() {

buttonState = digitalRead(buttonPin);

Serial.println(buttonState);

delay(100);

}

Step 2: Mess Around With the Circuit.

Same code, but change the circuit around to see what happens. Answer: Nothing.

Step 3: Dimming an LED

wire it up to dim the LED using analogue output, PWM, which stands for Pulse Width Modulation.

CODE:

int led = 9; // the PWM pin the LED is attached to

int brightness = 0; // how bright the LED is

int fadeAmount = 5; // how many points to fade the LED by

// the setup routine runs once when you press reset:

void setup() {

// declare pin 9 to be an output:

pinMode(led, OUTPUT);

}

// the loop routine runs over and over again forever:

void loop() {

// set the brightness of pin 9:

analogWrite(led, brightness);

// change the brightness for next time through the loop:

brightness = brightness + fadeAmount;

// reverse the direction of the fading at the ends of the fade:

if (brightness == 0 || brightness == 255) {

fadeAmount = -fadeAmount ;

}

// wait for 30 milliseconds to see the dimming effect

delay(30);

}

I could not get anything to happen.

Step 4: Servo Motor!

Getting motion to happen with the arduino.

CODE:

#include

Servo myservo; // create servo object to control a servo

// twelve servo objects can be created on most boards

int pos = 0; // variable to store the servo position

void setup() {

myservo.attach(9); // attaches the servo on pin 9 to the servo object

}

void loop() {

for (pos = 0; pos <= 180; pos += 1) { // goes from 0 degrees to 180

degrees

// in steps of 1 degree

myservo.write(pos); // tell servo to go to position in

variable 'pos'

delay(15); // waits 15ms for the servo to reach

the position

}

for (pos = 180; pos >= 0; pos -= 1) { // goes from 180 degrees to 0

degrees

myservo.write(pos); // tell servo to go to position in

variable 'pos'

delay(15); // waits 15ms for the servo to reach

the position

}

}

About This Instructable

167views

0favorites

More by Alan_Hanrahan:Messing With Arduino Simulator Disassembling a Bubble Gun Electronics: Totally Legitimate Science 
Add instructable to: