To put in practice what I've learned from the Arduino course with Zahraa Khalil from LinkedIn
h Hardware
Learning Arudino: Foundations
: Interfacing with Analog Devices
: Interfacing with hardware
h Hardware
I decided to create a music stand that would open and close automatically holding my sheet of music.
the whole concept is very simple:
a light sensor detects when the light is blocked while I pass my hands over the sensor, Arduino sends a command to a servo motor attached to a board which hods or release the paper.
VIDEO:
the LEDs work as a 4 second countdown until the door closes and holds the paper
Code:
#include <Servo.h>
Servo alavanca;
int LED1=9;
int LED2=8;
int LED3=7;
int LED4=6;
int LED0=5;
int servoPin=10;
void setup() {
// put your setup code here, to run once:
Serial.begin(9600);
pinMode(9, OUTPUT);
pinMode(8, OUTPUT);
pinMode(7, OUTPUT);
pinMode(6, OUTPUT);
pinMode(5, OUTPUT);
alavanca.attach(servoPin);
}
void loop() {
// put your main code here, to run repeatedly:
int lightSensor = analogRead(A0);
Serial.println(lightSensor);
if (lightSensor <= 180) {
digitalWrite(LED0, HIGH);
delay(500);
alavanca.write(80);
delay(100);
digitalWrite(LED0, LOW);
digitalWrite(LED1, HIGH);
digitalWrite(LED2, HIGH);
digitalWrite(LED3, HIGH);
digitalWrite(LED4, HIGH);
delay(1000);
digitalWrite(LED0, LOW);
digitalWrite(LED1, LOW);
digitalWrite(LED2, HIGH);
digitalWrite(LED3, HIGH);
digitalWrite(LED4, HIGH);
delay(1000);
digitalWrite(LED0, LOW);
digitalWrite(LED1, LOW);
digitalWrite(LED2, LOW);
digitalWrite(LED3, HIGH);
digitalWrite(LED4, HIGH);
delay(1000);
digitalWrite(LED0, LOW);
digitalWrite(LED1, LOW);
digitalWrite(LED2, LOW);
digitalWrite(LED3, LOW);
digitalWrite(LED4, HIGH);
delay(1000);
digitalWrite(LED0, LOW);
digitalWrite(LED1, LOW);
digitalWrite(LED2, LOW);
digitalWrite(LED3, LOW);
digitalWrite(LED4, LOW);
delay(30);
}
else {
delay(150);
alavanca.write(0);
digitalWrite(LED0, HIGH);
}
}
hardware used:
Arduino UNO board
Servo Motor
LED
jumping wires
Comments
Post a Comment