razangry1731
Published

IR servo with LCD display and buzzer ALLARM

You will learn how to make a servo move with an ir remote control and the degree measurement you will see on the lcd display!

BeginnerFull instructions provided6,030
IR servo with LCD display and buzzer ALLARM

Things used in this project

Hardware components

Buzzer
Buzzer
×1
SG90 Micro-servo motor
SG90 Micro-servo motor
×1
IR transmitter (generic)
for example a remote control
×1
IR receiver (generic)
×1
Jumper wires (generic)
Jumper wires (generic)
×1
Arduino UNO
Arduino UNO
×1
Breadboard (generic)
Breadboard (generic)
×1
Rotary potentiometer (generic)
Rotary potentiometer (generic)
×1
USB-A to B Cable
USB-A to B Cable
to connect the pc with arduino uno
×1
Alphanumeric LCD, 16 x 2
Alphanumeric LCD, 16 x 2
×1

Story

Read more

Schematics

IR SERVO

IR SERVO

Code

IR SERVO

Java
/*
 Controls:
  * PAUSE to reset the number
  * 0 to 9 keys to add a digit to the number
  * Press or hold UP / DOWN to easly switch between different positions 

 Credits:
   * Manauzzi Stefano (software)
   * Scaldarella Francesco (hardware)
*/

// Libraries
#include <IRremote.h>
#include <IRremoteInt.h>
#include <Servo.h>  
#include <LiquidCrystal.h>

// Pin you have to connect to
int ServoPin = 8;     
int receiver = 11;
int buzzer = 13;

// Useful objects
Servo Servo;    
IRrecv irrecv(receiver);
decode_results results; 

// Initialize the display
LiquidCrystal lcd(7, 6, 2, 3, 4, 5);

// The starting position is 0 degrees.
int ServoPosition = 0;      
int ServoPositionn = 0;

// Main Function to transform the IR signal in an instruction
int translateIR(int InitialServoPos) {

  // Analise the received signal
  switch(results.value) {


  // Reset the number
  case 0xFF02FD: return 0;    break;
  
  // All numbers (0-9) to set a specific degree position (0-90)
  case 0xFF6897: return InitialServoPos * 10;    break;
  case 0xFF30CF: return InitialServoPos * 10 + 1;    break;
  case 0xFF18E7: return InitialServoPos * 10 + 2;    break;
  case 0xFF7A85: return InitialServoPos * 10 + 3;    break;
  case 0xFF10EF: return InitialServoPos * 10 + 4;    break;
  case 0xFF38C7: return InitialServoPos * 10 + 5;    break;
  case 0xFF5AA5: return InitialServoPos * 10 + 6;    break;
  case 0xFF42BD: return InitialServoPos * 10 + 7;    break;
  case 0xFF4AB5: return InitialServoPos * 10 + 8;    break;
  case 0xFF52AD: return InitialServoPos * 10 + 9;    break;

  // Change the position with UP / DOWN
  case 0xFF906F: return InitialServoPos + 10;    break;
  case 0xFFE01F: return InitialServoPos - 10;    break;

  /*
  // Repeat
  case 0xFFFFFFFF: 
    // Augment the position
    if (InitialServoPos % 10 == 1) {
      return InitialServoPos + 10;
    }
    // Decrease the position
    else if (InitialServoPos % 10 == 2) {
      return InitialServoPos - 10;
    }
    break;
  */
  }
  

  // Don't over repeat with a secoundary background delay
  int delayyy = 100;
  delay(delayyy);
}

// *** Setup ***
void setup()   
{
  // Start the Serial process
  Serial.begin(9600);
  
  // Set up the buzzer
  pinMode(buzzer, OUTPUT);
  
  // Set up the servo
  Servo.attach(ServoPin);
  
  // Set up the IR
  irrecv.enableIRIn();

  // Initialize display LCD
  lcd.begin(16,2);
}

// *** Main Loop ***
void loop()  {
  
  // Receive the signal
  if (irrecv.decode(&results)) {
    ServoPosition = translateIR(ServoPosition); 
    irrecv.resume(); // receive the next value
  }

  // Position Adjustments
  if (ServoPosition > 180) {
    ServoPositionn = 180;
  } 
  if (ServoPosition < 0) {
    ServoPositionn = 0;
  } else {
    ServoPositionn = ServoPosition;
  }
  
  // Update the positon
  Servo.write(ServoPositionn);       
  
  // Display
  if (0 <= ServoPosition && ServoPosition <= 180) {
    lcd.setCursor(0, 0);
    lcd.print("    Degrees     ");
    lcd.setCursor(0, 1);
    lcd.print(ServoPosition);
    lcd.print("_______________");
  }

  // Buzzer allarm and alert message
  int buzzerTime = 70;
  if (ServoPosition > 180) {
    digitalWrite(buzzer,HIGH);
    delay(buzzerTime); 
    digitalWrite(buzzer,LOW);
    delay(buzzerTime); 
    lcd.setCursor(0, 0);
    lcd.print("!!!!Error404!!!!");
    lcd.setCursor(0, 1);
    lcd.print("!Invalid number!");
  }
  
  // Set and apply the update delay
  int MainDelayyyy = 1;
  delay(MainDelayyyy);    
}

Credits

razangry1731
0 projects • 2 followers
Contact

Comments

Please log in or sign up to comment.