LCD blinks when activating an ultrasonic sensor with servo motor

Hi, I am a beginner in arduino. I am doing a project which serves to dispense alcohol and measure body temperature. To dispense the alcohol I use an ultrasonic sensor which activates a servomotor that makes the alcohol fall. And for the temperature I use an mlx90614 sensor and the result is seen on an LCD display.

The problem is that when you put your hand on the ultrasonic sensor, the servomotor is activated, but at the same time for some reason, the 16x2 display blinks once, when the display is not linked to it.

I tried to see the connections, but I can't solve it, and in the code, the ultrasonic sensor, the servo and the screen are not linked.

What is the problem?

Me too.

Hi @facuaaa
Topic duplicity?

https://forum.arduino.cc/t/lcd-parpadea-al-activar-un-sensor-ultrasonico-con-servomotor/917839

RV mineirin

Hi,
We need to see your code?
We need to see a circuit diagram?
Include your power supplies.

Can you please post some images of your project so we can see your component layout?

Thanks... Tom... :grinning: :+1: :coffee: :australia:

How is the servo powered? Not by the Arduino, I hope.

Yes, how do I have to do it?

unsigned long previousMicrosTriac1 = 0;
unsigned long previousMicrosTriac2 = 0;
const long intervalTriac1 = 5000;
const long intervalTriac2 = 5;
#include <LiquidCrystal.h>
#include <Wire.h>
#include <Servo.h>
#include <Adafruit_MLX90614.h>
int BUZZER = 9;
int cm=0;
long distancia,duracion; //long valores decimales 
int posicion1=120;
int posicion2=180;
Servo miServo; //al pin 13
#define Pecho 6 //Echo al pin 6
#define Ptrig 7 //Trig pin 7
LiquidCrystal lcd(12, 11, 5, 4, 3, 2);
// Instanciar objeto
Adafruit_MLX90614 termometroIR = Adafruit_MLX90614();
 
void setup() {
  pinMode(BUZZER, OUTPUT);
  pinMode(Pecho, INPUT);  //define el pin 6 como entrada (echo)
  pinMode(Ptrig, OUTPUT); //define el pin 7 como salida (triger)
  miServo.attach (10);         //define el pin 13 como salida para mover el servo enviando la señal de distancia menor a 10
  // Iniciar comunicación serie
  Serial.begin(9600);
  lcd.begin(16, 2);
  // Iniciar termómetro infrarrojo con Arduino
  termometroIR.begin();
 
 
}
 
void loop() {
  unsigned currentMicros = micros();
  if(currentMicros - previousMicrosTriac1 >= intervalTriac1){
    previousMicrosTriac1 = currentMicros;
      digitalWrite (Ptrig,LOW);
      delayMicroseconds(2);
      digitalWrite(Ptrig,HIGH); //genera el pulso de triger de 10ms 
      delayMicroseconds(10);
      digitalWrite(Ptrig,LOW);
    
      duracion= pulseIn(Pecho, HIGH);  //con esto sabemos cuanto tiempo estuvo en alto(HIGH)
      distancia =(duracion/2)/29;     //   calcula la distancia en centimetros
    
 
    
      if (distancia <=10 && distancia >=1){
      miServo.write(posicion1);                //mueve el servo si la distancia es menor a 10cm 
      Serial.println("Obstaculo");          //envia la palabra "obstaculo" por el puerto serial 
      
      }
      else 
      {
        miServo.write(posicion2);
      }
      
  } 
  if(currentMicros - previousMicrosTriac2 >= intervalTriac2){
    previousMicrosTriac2 = currentMicros; 
   
    // Obtener temperaturas grados Celsius
    float temperaturaObjeto = termometroIR.readObjectTempC(); 
    lcd.setCursor(3,0);
    
    lcd.print("Tomese la");
    lcd.setCursor(2,1);
    lcd.print("temperatura");
    
    if (temperaturaObjeto>30){
      lcd.clear();
      lcd.setCursor(0,0);
      lcd.print("Temperatura: ");
      lcd.setCursor(0,1);
      lcd.print(temperaturaObjeto);
      delay(1000);
      lcd.clear();
      if(temperaturaObjeto>=37.5){
        tone(BUZZER,2000);
      }
      else{
        noTone(BUZZER);
      }
    }
  }
}

everything is powered by the arduino and the cable to the pc. then I send you the photo

With an external supply capable of supplying the current required by the servo. A 4 AA cell pack is a popular power supply for servos. Connect the ground of the pack to Arduino ground as well as the servo. The plus side of the pack goes to the plus supply of the servo, only.

POST LOCKED
Please do NOT cross post / duplicate as it wastes peoples time and efforts to have more than one post for a single topic.

Continued cross posting could result in a time out from the forum.

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.