Using IR Remote control the Ultrasonic and Servo.Show info in LCD Display

This is my task from University:

Construct "Object Tracking System" using LCD display, ultrasonic distance sensor, servo motor and remote controller. Servo motor and ultrasonic distance sensor should be attached together so that servo will control the angle of distance measurer (0-180 degrees). The devise should have two modes of operation: tracking and measurement. Modes should be changed by pressing FUNC button on remote controller. In measurement mode "M:" should appear on the upper line of the LCD display, and the position angle together with the distance value should be displayed on the bottom line of the display in the following format: for example if the servo is at 90° angle and the distance measurement is 32.5cm display should show "P:90° D:32.5cm". User must be able to change the position degree by pressing PREV or NEXT buttons on remote control to decrease or increase the angle respectively, or user can directly enter degree with 0- 9 buttons and press PLAY/PAUSE button to move to the entered degree (must be between 0-180). In this case entered numbers will appear on the upper line after "M:" and after PLAY/PAUSE button is pressed the number should be cleared. In tracking mode "T:" should appear on the upper line of the LCD display, and the position angle together with the distance value should be displayed on the bottom line. In this mode user enters the threshold distance to track the object using 0-9 buttons (entered numbers should appear on the upper line after "T:"). Once and PLAY/PAUSE button is pressed the servo should start moving forward and back continuously until the ultrasonic sensor sees an object that is closer that threshold distance. While moving the LCD should show the current position angle and distance measurement. If an object is found the servo should stop and the entered threshold should be cleared.

I created code and schemem but completely. Help me with code
I can control servo by pressing bottons "prev" and "next". Also information from servo and ultrasonic are in LCD.
Now I need to switch between function and select angle or distance by pressing buttons 0-9 select them.

#include <IRremote.h> 
#include <Servo.h>
#include <LiquidCrystal.h>

#define next 0xFD609F
#define prev 0xFD20DF

LiquidCrystal lcd(12, 11, 5, 4, 3, 2);

int RECV_PIN = 8;       
IRrecv irrecv(RECV_PIN);

Servo servo;
int val;
bool cwRotation, ccwRotation; 
decode_results results;

int trigPin = 7;
int echoPin = 6;
long distance;
long duration;

void setup(){
  lcd.begin(16, 2);
  lcd.setCursor(0, 0);
   pinMode(trigPin, OUTPUT);
   pinMode(echoPin, INPUT);
void loop() 
  if (irrecv.decode(&results)) {
    Serial.println(results.value, HEX);
    if (results.value == next){
      if(val >= 5){
        val -=5;
if (results.value == prev){
      if(val <= 175){
        val +=5;
  digitalWrite(trigPin, LOW);
  digitalWrite(trigPin, HIGH);
  digitalWrite(trigPin, LOW);
  duration = pulseIn(echoPin, HIGH);
  distance = duration*0.06/2;;
    lcd.setCursor(0, 1);
    lcd.print("P: ");
    lcd.setCursor(2, 1);
    lcd.setCursor(6, 1);
    lcd.print("D: ");
    lcd.setCursor(8, 1);


Your topic was Moved to it's current location / section as it is more suitable.

Could you also take a few moments to Learn How To Use The Forum.

Other general help and troubleshooting advice can be found here.
It will help you get the best out of the forum in the future.

That is a frizzy thing, not a schematic. Post the code you have written so far, then explain what it does not do correctly and how it should behave. Do one section at a time. How much time have you got left and how long has it taken you to get this far? What is the university training you to do?

I am surprised the university did not specify the "object". Many objects do not reflect ultrasound, for instance a stuffed toy animal.

This topic was automatically closed 120 days after the last reply. New replies are no longer allowed.