Arduino Workshoop Loe
Arduino Workshoop Loe
Button Control:
const int ledPin = 13; // LED pin
const int buttonPin = 2; // Button pin
void setup() {
pinMode(ledPin, OUTPUT); // LED pin as output
pinMode(buttonPin, INPUT_PULLUP); // Button pin with internal pull-up resistor
}
void loop() {
if (digitalRead(buttonPin) == LOW) {
digitalWrite(ledPin, HIGH); // Turn the LED on when the button is pressed
} else {
digitalWrite(ledPin, LOW); // Turn the LED off when the button is not pressed
}
}
int redPin = 9;
int greenPin = 10;
int bluePin = 11;
void setup() {
pinMode(redPin, OUTPUT);
pinMode(greenPin, OUTPUT);
pinMode(bluePin, OUTPUT);
}
void loop() {
// Red
digitalWrite(redPin, HIGH);
digitalWrite(greenPin, LOW);
digitalWrite(bluePin, LOW);
delay(1000);
// Green
digitalWrite(redPin, LOW);
digitalWrite(greenPin, HIGH);
digitalWrite(bluePin, LOW);
delay(1000);
// Blue
digitalWrite(redPin, LOW);
digitalWrite(greenPin, LOW);
digitalWrite(bluePin, HIGH);
delay(1000);
}
LCD Display: Show sensor data on a character LCD (use a potentiometer that rotates at 0
to 180 degrees to show angle on LCD)
#include <LiquidCrystal.h>
LiquidCrystal lcd(12, 11, 5, 4, 3, 2); // Define the LCD interface
void setup() {
lcd.begin(16, 2); // Initialize the LCD with 16x2 characters
}
void loop() {
int sensorValue = analogRead(A0); // Read the analog sensor value
int angle = map(sensorValue, 0, 1023, 0, 180); // Map the sensor value to angle (0-180)
lcd.clear(); // Clear the LCD
lcd.setCursor(0, 0); // Set the cursor to the first line
lcd.print("Angle: "); // Display text
lcd.print(angle); // Display the angle value
delay(500); // Delay to update the display
}
#include <IRremote.h>
int RECV_PIN = 11; // Define the IR receiver pin
IRrecv irrecv(RECV_PIN);
decode_results results;
void setup() {
irrecv.enableIRIn(); // Start the IR receiver
pinMode(13, OUTPUT); // LED connected to pin 13
}
void loop() {
if (irrecv.decode(&results)) {
int value = results.value;
if (value == 0xFFA25D) { // Replace with your remote's button code
digitalWrite(13, !digitalRead(13)); // Toggle the LED on pin 13
}
irrecv.resume(); // Receive the next value
}
}
You'll need a stepper motor and a stepper motor driver for this task. Here's a basic example using the
AccelStepper library:
#include <AccelStepper.h>
AccelStepper stepper(1, 8, 9); // Define the stepper motor and pins
void setup() {
stepper.setMaxSpeed(1000); // Set the maximum speed in steps per second
stepper.setSpeed(500); // Set the initial speed
}
void loop() {
stepper.runSpeed(); // Run the motor at the current speed
// You can change the speed or direction as needed
}