Bgd
Published

LEGO Automatic Car/People Barrier

A little project done at an IoT hackathon. The whole idea was that people who are always on time should be rewarded for their punctuality.

EasyShowcase (no instructions)5 hours485
LEGO Automatic Car/People Barrier

Things used in this project

Story

Read more

Code

thenanobarrier

Arduino
//3 - 5 noiembrie 2017
//Florea Bogdan

//libraries included
#include <Servo.h>

//definire variabile pentru servo si led RGB
Servo myservo;
int rPin = 11;
int gPin = 10;
int bPin = 9;
int pos = 0;
int buzzer = 5;

// DONT COPY AND PASTE
// CHECK ALWAYS YOUR PINS
void setup() {
  // initializare componente
  pinMode(rPin, OUTPUT); //red 
  pinMode(gPin, OUTPUT); //green
  pinMode(bPin, OUTPUT); //blue
  myservo.attach(6); //micro servo-motor
  pinMode(buzzer, OUTPUT); //added buzzer
  Serial.begin(9600);
}
//
//WE have no problems here

void loop() {
  
  // put your main code here, to run repeatedly:
  
  Serial.println("Bariera inchisa!");
  myservo.write(0); //bariera inchisa
  setColor(255, 0, 0); // rosu
  delay(4000);
  
  Serial.println("Bariera deschisa!");
  tone(buzzer, 500);
  for (int j = 0; j < 91; j++)
  {
    myservo.write(j); //bariera openh
    delay(5);  
  }
  
  setColor(0, 255, 0); //green ptr 2.5 secunde
  delay(2500);
  noTone(buzzer);
  Serial.println("Bariera se intoarce");
  setColor(255, 0, 255); //yellow
  for (int i = 90; i >= 0; i--)
  {
    myservo.write(i);
    delay(20);
  }
}
// final


// functie pentru setare culoare RGB LED
void setColor(int red, int green, int blue)
{ //setare culoare led RGB
  analogWrite(rPin, red);
  analogWrite(gPin, green);
  analogWrite(bPin, blue);
}

Credits

Bgd

Bgd

4 projects • 2 followers
H3llo friend!
Contact

Comments