0% found this document useful (0 votes)
28 views4 pages

Workshop 1

The document discusses a workshop on controlling a servo motor using Arduino. It contains: 1) A circuit diagram and steps to code the servo motor to turn left and right when a button is pushed. 2) The C++ code to control the servo motor, which uses a for loop to rotate it to 90 degrees in one direction and 0 degrees in the other direction when a button is pressed. 3) Images are provided to show testing of the circuit in action.
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
28 views4 pages

Workshop 1

The document discusses a workshop on controlling a servo motor using Arduino. It contains: 1) A circuit diagram and steps to code the servo motor to turn left and right when a button is pushed. 2) The C++ code to control the servo motor, which uses a for loop to rotate it to 90 degrees in one direction and 0 degrees in the other direction when a button is pressed. 3) Images are provided to show testing of the circuit in action.
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 4

Workshop 1 – Le Tai Nhan– GCD210460 – GCD1102

1. Circuit (Schema)

2. Step by step finish all requirements


- Step 1: I will create code to shaft rod 90 degrees turn left and turn right.
- Step 2: Add the button to when we push button the shaft rod will action.
- Step 3: Next code will make the shaft rod action when we push it.
3. Sketch (codes) for this workshop

// C++ code

//

/*

Sweep

by BARRAGAN <http://barraganstudio.com>

This example code is in the public domain.

modified 8 Nov 2013 by Scott Fitzgerald

http://www.arduino.cc/en/Tutorial/Sweep

*/

#include <Servo.h>

int pos = 0;

int buttonState = LOW;

int SERVO = 9;

int BUTTON = 2;

//Create an servo instance

Servo servo_9;

void setup()

servo_9.attach(SERVO);

servo_9.write(pos);

pinMode(SERVO, OUTPUT);
pinMode(BUTTON, INPUT);

Serial.begin(9600);

void loop()

// check button, read BUTTON pin,

buttonState = digitalRead(BUTTON);

Serial.println(buttonState);

// if BUTTON pin high and servo_9.read()= 0, write servo to 90

if (buttonState == HIGH && servo_9.read()== 0)

for (pos = 0; pos <= 90; pos += 1)

// tell servo to go to position in variable 'pos'

servo_9.write(pos);

// wait 15 ms for servo to reach the position

delay(15); // Wait for 15 millisecond(s)

buttonState = 0;

// if BUTTON pin high and servo_9.read()= 90, write serve to 0

if (buttonState == HIGH && servo_9.read()== 90)

for (pos = 90; pos >= 0; pos -= 1)

// tell servo to go to position in variable 'pos'

servo_9.write(pos);
// wait 15 ms for servo to reach the position

delay(15); // Wait for 15 millisecond(s)

buttonState = 0;

Serial.println(servo_9.read());

4. Test evidence images

You might also like

pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy