0

Can someone please tell me what's going on with my LCD screen and how I can fix this issues below?

I have the following:

  • Arduino Uno R3 w/ ATMEGA 328P-PU
  • 16x2 LCD
  • TowerPro MicroServo SG90
  • DPDT Slide Switch w/ 120 ohm resistor

Objective: Read the sensor value (If switch is on or off), and move a servo accordingly while displaying switch state on LCD.

Issue: LCD display seems to receive random data during program run (see image). All starts up well, and as soon as a few seconds have lapsed in the void loop(), the screen becomes garbled. Also, the switch value (while debugging) gets a zero reading while HIGH, acting accordingly as if the switch was off. The servo motor runs as it should, but gets random pulses every now and again where it starts to buzz, but doesn't turn.

Images: Three images below.

Outcome 1 Outcome 2 Garbled Data Received

Schematic: Schema

Coding:

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

const int sensorPin = A0;    // select the input pin for the potentiometer
int ledPin = 13;      // select the pin for the LED
int sensorValue = 0;  // variable to store the value coming from the sensor
int oldPos = 0;
int pos = 0;
int oldStat = 0;

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

void setup() {
  Serial.begin(9600);
  lcd.begin(16, 2);
  lcd.setCursor (0, 0);
  lcd.print("Starting up FSS!");
  delay(700);
  lcd.clear();
  lcd.print("Init SERVO...");
  delay(500);
  servo.attach(9);
  lcd.clear();
  lcd.print("SERVO Success!");
  delay(400);
  lcd.clear();
  lcd.print("Testing SERVO...");
  servo.write(0);
  delay(200);
  servo.write(90);
  delay(200);
  servo.write(45);
  delay(300);
  lcd.clear();
  lcd.print("SERVO Running!");
  lcd.clear();
  lcd.print("Select AUX Source");
  pinMode(ledPin, OUTPUT);
}

void loop() {
  lcd.clear();
  lcd.setCursor (0, 0);
  lcd.print("Select AUX Src");
  lcd.setCursor(0, 1);

  sensorValue = analogRead(sensorPin);
  Serial.print("Sensor: ");
  Serial.println(sensorValue);

  if(sensorValue == 0){
    //if(sensorValue = oldStat){
      oldStat = sensorValue;
      digitalWrite(ledPin, LOW);
      lcd.print("Switch is OFF");
      pos = 45;

      Serial.println("Switch is OFF");
    //}
  } else{
    digitalWrite(ledPin, HIGH);
    lcd.print("Switch is ON");
    pos = 120;
    Serial.println("Switch is ON");
  }

  if (pos != oldPos){
    servo.write(pos);
  }

  oldPos = pos;

  delay (700);
}
4

Insufficient decoupling. Put a 100nF cap on the supply lines at the LCD and a 100uF cap on the supply lines at the servo.

  • I'll need to get the 100nF and then I'll install that. I'm also going to build a voltage supply apart from the base. If the decoupling works, I'll mark as answer. Thanks! – Johan Brink Oct 19 '14 at 19:05
  • Get a dozen or so. They're one of the most common to use. – Ignacio Vazquez-Abrams Oct 19 '14 at 19:09
  • Electronics is not my strong suit (obviously) so what's happening here? The arduino is behaving correctly (and probably reading the value correct) but it just can't display it because of noise from the servo affecting the transmission to the LCD? So a Serial.println would print the correct value or not? – Madivad Oct 20 '14 at 23:58
  • @Madivad: The servo has caused the power to the panel to go pear-shaped, so you can't even know if the electronics in it are in any shape to be sent any commands or data. – Ignacio Vazquez-Abrams Oct 21 '14 at 0:05

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.