Download presentation
Presentation is loading. Please wait.
Published byToby Spencer Modified over 9 years ago
1
Arduino Circuits and Code
2
int ledPin = 9; void setup() { pinMode(ledPin, OUTPUT); } void loop() { digitalWrite(ledPin, LOW); delay(1000); digitalWrite(ledPin, HIGH); delay(1000); for (int i = 0; i<=255; i++) { analogWrite(ledPin, i); delay(10); } } power led ground resistor digital and analog write (actuator - led)
3
it matters which way round you put the led long leg to positive Resitance = (V S - V L ) / I V S = supply voltage, V L = LED voltage, I = LED current pwm pins for analogWrite things to remember
4
digital read (sensor - button) int inputPin = 9; int val = 0; void setup() { pinMode(inputPin, INPUT); Serial.begin(9600); } void loop(){ val = digitalRead(inputPin); Serial.println(val); } 5V button ground pin 9 10kΩ
5
use serial prints for debugging resistor needed in circuit debounce things to remember
6
analog read (sensor - ldr) int inputPin = 5; int val = 0; void setup() { Serial.begin(9600); } void loop(){ val = analogRead(inputPin); Serial.println(val); } ldr 5V ground pin5
7
analog read (sensor - potentiometer)
8
values 0 to 1023 - use map to get 0 to 255 use millis() instead of delay things to remember
10
servos #include Servo myservo; // create servo object to control a servo // a maximum of eight servo objects can be created int pos = 0; void setup() { myservo.attach(9); // attaches pin 9 to the servo object } void loop() { for(pos = 0; pos < 180; pos += 1) { myservo.write(pos); delay(15); } for(pos = 180; pos>=1; pos-=1) { myservo.write(pos); delay(15); }
11
servos common rotation range is 180º good for smooth continuous motion servo library uses pins 9 and 10 servo needs time to reach destination
12
steppers
13
#include // change this to the number of steps on your motor #define STEPS 100 Stepper stepper(STEPS, 4, 5, 6, 7); void setup() { // set the speed of the motor to 30 RPMs stepper.setSpeed(30); } void loop() { stepper.step(100); delay(1000); } *
14
stepper can rotate 360º can lock into fixed position - strong torque precise position setting stepper library
15
dc motors
16
const int motor1Pin = 3; const int motor2Pin = 4; const int enablePin = 9; void setup() { // set all the pins you're using as outputs: pinMode(motor1Pin, OUTPUT); pinMode(motor2Pin, OUTPUT); pinMode(enablePin, OUTPUT); // set enablePin high so that motor can turn on: digitalWrite(enablePin, HIGH); //to control the speed of the motor //analogWrite(enablePin, 30) } void loop() { digitalWrite(motor1Pin, LOW); // set leg 1 of the H-bridge low digitalWrite(motor2Pin, HIGH); // set leg 2 of the H-bridge high // swap HIGH and LOW values to change motor direction // set both HIGH or both LOW to stop motor }
17
dc motors torque gears direction and speed
18
solenoids
19
solenoid boolean drum[] = {1, 0, 0, 0, 0, 1, 0, 1}; int drumPin = 2; int counter; void setup() { pinMode(drumPin, OUTPUT); counter = 0; } void loop() { digitalWrite(drumPin, drum[counter]); if(counter == 7) { counter = 0; } else { counter++; } delay(200); // delay between beats }
20
solenoids push and pull - use springs toy hacking - reed relays
Similar presentations
© 2025 SlidePlayer.com. Inc.
All rights reserved.