Arduino Forum

Using Arduino => Displays => Topic started by: wbegg on Jan 20, 2012, 11:58 pm

Title: Problem with LCD and Motor
Post by: wbegg on Jan 20, 2012, 11:58 pm
I'm having a really strange problem that I hope someone here can remedy.

I have put together a guitar pickup winder with an LCD interface. The motor is turned on via a relay, and is driven via a PWM signal from the Arduino to control speed. Motor is 12V and isolated via a MOSFET (logic driven by PWM).

The LCD is a JHD204A (20x4) hd44780 compatible display. As the motor turns, the LCD indicates # of turns from interrupt input from an optointerrupter (and some other tid-bits).

The problem is, sometimes in the middle of the operation, the LCD starts to display junk characters, and sometimes when the motor goes low (off state from relay), display goes blank and arduino must be reset. This only does this when the motor is under load, ie. if I detach the drive belt, let motor run without a load, and turn the shaft by hand to increment turns, everything works great.

I'm using a computer supply for the power supply to run both the motor and the logic. The PS is rated +12V @ 26A and +5V @ 30A which should be more than enough to run what I need. The DC motor is out of an old printer.

Could this be an effect of a current change, caused by the motor, which affects the state of the LCD? I'm baffled.
Here is the code.

Code: [Select]
/*

sketch for counting turns with optointerruptor for pickup
winder. Uses interrupt on pin 2 to increment counts and
displays pertinent information on a 20 x 4 LCD Display.

*/
#include <LiquidCrystal.h>

LiquidCrystal lcd(7, 8, 9, 10, 11, 12);


// Global Variables
 
volatile unsigned int M_SEC_0 = 0;        // for rpm
volatile unsigned int M_SEC_1 = 0;        // for rpm
volatile unsigned long CUR_WINDS = 0;      // current count of winds
volatile unsigned int RPM_CNT = 0;        // revolution increment for RPM calc


// pin map

const int tachPin = 0;    // infrared tachometer input. Pin 2 for interrupt.
const int motorEng = 4;   // pin for motor relay
const int pwmIn = A5;     // Potentiometer pin to set motor speed pwm
const int pwmOut = 3;     // PWM out for motor speed
const unsigned int A_SW = A0;       // analog switch

void setup()
{
  lcd.begin(20,4);          // 20x4 HD44780 compatible LCD display
//  Serial.begin(9600);
  pinMode(tachPin, INPUT);  // input pin for calculating winds and rpm
  pinMode(motorEng, OUTPUT); // connected to motor relay
  pinMode(pwmIn, INPUT);
  pinMode(pwmOut, OUTPUT);
  digitalWrite(tachPin, HIGH);
  digitalWrite(motorEng, HIGH);
 
// Attach the Interrupt

attachInterrupt(tachPin, tachometer, RISING);  // interrupt for counting. Connected to optointerrupter on digital pin 2 (interrupt 0) 
}


// Interrupt function

void tachometer()
{
  CUR_WINDS++;        // increment # of winds cnt
  RPM_CNT++;          // increment count for RPM calculation
}


// function set to read switches from resistor array to save analog inputs on arduino

int read_ana_switch()
{
 
  /*
  reads analog switch and returns integer val 1::n
  This is done to save digital inputs.  Here we can have numerous switches on
  one analog pin.
 
  switch    int val
  UP_SW      1
  DN_SW      2
  LT_SW      3
  RT_SW      4
  RED_SW     5
  GRN_SW     6
  */
 

   const int HYS = 4;           // Hysteresis for selection +/- adc counts
   const int UP_SW = 51;        // adc counts for up switch
   const int DN_SW = 61;        // adc counts for down switch
   const int LT_SW = 71;        // adc counts for left switch
   const int RT_SW = 84;        // adc counts for right switch
   const int RED_SW = 128;      // adc counts for red arcade button
   const int GRN_SW = 108;      // adc counts for green arcade button
   
   int adc = 0;           // raw adc counts
   int which_switch = 0;  // which switch was pressed
   
     adc = analogRead(A_SW);  // dummy read for multiplex settling
     delay(10);
     adc = analogRead(A_SW);
   
     if( ( adc >= UP_SW - HYS ) && ( adc <= UP_SW + HYS ) )
      {
        which_switch = 1;
      }
      else if( ( adc >= DN_SW - HYS ) && ( adc <= DN_SW + HYS ) )
      {
        which_switch = 2;
      }
      else if( ( adc >= LT_SW - HYS ) && ( adc <= LT_SW + HYS ) )
      {
        which_switch = 3;
      }
      else if( ( adc >= RT_SW - HYS ) && ( adc <= RT_SW + HYS ) )
      {
        which_switch = 4;
      }
      else if( ( adc >= RED_SW - HYS ) && ( adc <= RED_SW + HYS ) )
      {
        which_switch = 5;
      }
      else if( ( adc >= GRN_SW - HYS ) && ( adc <= GRN_SW + HYS ) )
      {
        which_switch = 6;
      }

return which_switch;
}


void spinit()
{
  /*
  Turns motor and counts total turns and calculates RPM 
 
  */
 
  static unsigned int num_winds = 100;  // default number of winds to perform
  unsigned int wind_inc = 1;             // increment num_winds by...
  unsigned int ms_elapsed = 0;           // number of milliseconds elapsed when counting to 1 second for rpm calc
  unsigned int rpm = 0;                  // average speed of guitar pickup
  unsigned int loop_cnt = 0;
  int ana_sw = 0;
  int prev_ana_sw = 0;
 
//    M_SEC_0 = millis();    // initalize rpm gate time
//    M_SEC_1 = M_SEC_0;
   
while( ana_sw != 5 )
  {
    if(num_winds >= (CUR_WINDS+1))
    digitalWrite(motorEng, HIGH);
    else digitalWrite(motorEng, LOW);
    int sensorValue = analogRead(pwmIn); // read speed potentiometer
    int outputValue = map(sensorValue, 0, 1023, 0, 255); // map the sensor value to a range from 0 - 255:
    analogWrite(pwmOut, outputValue); // use that to control the transistor
   
    long winds_rem = (num_winds - CUR_WINDS);
    ana_sw = read_ana_switch();      // read the analog switch
   
    if( ana_sw == 1 | ana_sw == 2 )  // inc/dec faster if sw is held down
    {
      if( ana_sw == prev_ana_sw )
      {
        wind_inc++;
      }
      else
      {
        wind_inc = 1;
      }
    }
   
    if( ana_sw == 1 )
    {
      lcd.clear();
      num_winds += wind_inc;  // if the up switch is pressed, increment the number of winds to do
    }
    if( ana_sw == 2 )
    {
      lcd.clear();
      num_winds -= wind_inc;  // if the down switch is pressed, decrement the number of winds to do
    }
    prev_ana_sw = ana_sw;   
    // calculate RPM in 1hz intervals
   
    M_SEC_1 = millis();                 // get elapsed time
    ms_elapsed = M_SEC_1 - M_SEC_0;

    if( ms_elapsed >= 1000 ) 
    {
      rpm = ( ( 60000 / ms_elapsed ) * RPM_CNT );          // calculate rpm
       
      M_SEC_0 = millis();    //reset counters
      M_SEC_1 = M_SEC_0;
      RPM_CNT = 0;
    }
 

      if (CUR_WINDS >= num_winds)
         {
          lcd.setCursor(0,3);
          lcd.print("Winding is Complete!");
         }
      lcd.setCursor(0,0);
      lcd.print("# Winds: ");
      lcd.print(num_winds);
      lcd.setCursor(0,1);
      lcd.print("RPM: ");
      lcd.print(rpm);
      lcd.setCursor(0,2);
      lcd.print("Total Winds: ");
      lcd.print(CUR_WINDS);
      lcd.setCursor(0,3);
     
//      if (CUR_WINDS >= num_winds)
//        digitalWrite(motorEng, LOW);
     
     

}


  lcd.clear();
  digitalWrite(motorEng, LOW);
  CUR_WINDS = 0;
  delay(400);
}


void loop()

{
 
   spinit();
 


Title: Re: Problem with LCD and Motor
Post by: dc42 on Jan 21, 2012, 01:28 am
Do you have a diode connected across the motor to catch the back emf when the mosfet switches off?
Title: Re: Problem with LCD and Motor
Post by: wbegg on Jan 21, 2012, 04:06 am
Quote
Do you have a diode connected across the motor to catch the back emf when the mosfet switches off?


Yes I do. I also have a diode across the coil of the relay. Cathode to Vcc (+12V).

I may have solved the problem. I connected a 1000 uF cap across the supply voltage for the LCD, and it's working much better. Now only having problems about 9 out of 10 iterations. I think I can solve the problem by filtering the motor supply a bit with a cap across the +12 supply. Should have done this before I made the PCB.
Title: Re: Problem with LCD and Motor
Post by: wbegg on Jan 21, 2012, 04:28 am
Here it is, working.

http://www.youtube.com/watch?v=8HVvRiigLkI (http://www.youtube.com/watch?v=8HVvRiigLkI)

Sorry for the jerky camera. Kinda hard to look through and push buttons at the same time.
Title: Re: Problem with LCD and Motor
Post by: dc42 on Jan 21, 2012, 09:05 am

Quote
Do you have a diode connected across the motor to catch the back emf when the mosfet switches off?


Yes I do. I also have a diode across the coil of the relay. Cathode to Vcc (+12V).

I may have solved the problem. I connected a 1000 uF cap across the supply voltage for the LCD, and it's working much better. Now only having problems about 9 out of 10 iterations. I think I can solve the problem by filtering the motor supply a bit with a cap across the +12 supply. Should have done this before I made the PCB.



Yes, a large cap across the motor supply is important, negative side connected as close to the mosfet source terminal as possible (I am assuming you are using an n-channel mosfet as a low side switch).
Title: Re: Problem with LCD and Motor
Post by: MikMo on Jan 21, 2012, 04:23 pm
Is it just me or does anybody else get scared by a device called "Willy winder" running at 100 RPM    :) :) :) :)
Title: Re: Problem with LCD and Motor
Post by: wbegg on Jan 21, 2012, 04:44 pm
Quote
(I am assuming you are using an n-channel mosfet as a low side switch).


Yes, that is correct. With logic level switching. I'll put 1000uF across and give it a whirly-whirl. Thanks a bunch.

Quote
Is it just me or does anybody else get scared by a device called "Willy winder" running at 100 RPM


You should see the guitar amps I build. The "Little Willy" and the "Fat Willy".

Title: Re: Problem with LCD and Motor
Post by: dc42 on Jan 21, 2012, 05:17 pm
What's the purpose of the relay, given that you already have a mosfet controlling the motor? Additional safety?
Title: Re: Problem with LCD and Motor
Post by: wbegg on Jan 21, 2012, 05:36 pm
Quote
What's the purpose of the relay, given that you already have a mosfet controlling the motor? Additional safety?


Well ... not really. I am using the parts on hand. The relay has 12V coil , so it's being driven by an NPN transistor from a digital output from arduino (engages and disengages motor).

The relay supplies 12VDC to the motor, and it's speed is controlled by a PWM signal into the MOSFET.
I know I could accomplish the same with 2 mosfets or maybe a power transistor for the motor engage/disengage, but I just like the "clickety-click" of the mechanical relay. I'll post a schematic here shortly.
Title: Re: Problem with LCD and Motor
Post by: dc42 on Jan 21, 2012, 05:44 pm
Do you mean that the motor incorporates an electric clutch to engage it, and you are driving that clutch with the relay?
Title: Re: Problem with LCD and Motor
Post by: wbegg on Jan 21, 2012, 07:03 pm
Maybe this schematic explains it.

All the relay does is supply 12V to the motor. I use this to turn off the motor when a certain number of winds has been reached. The Motor is connected to a MOSFET which is driven by 5V PWM from a digital pin on the arduino. A Potentiometer controls the duty cycle via an analog input. I guess I could controlled the state of the motor with the digital pwm pin. Maybe I've overthought this. At any rate, since this is an LCD question, the cap will be added across the 12V supply close to the MOSFET to quiet some of the electrical noise from the motor and this should solve the issue of my LCD resetting.

Title: Re: Problem with LCD and Motor
Post by: dc42 on Jan 21, 2012, 07:34 pm
OK, that looks like overkill, but it should work. The capacitor should help, but make sure the negative side is connected as close to the mosfet source as possible, to avoid noise on the ground connection. Other things that may help are keeping the wires between the LCD and then Arduino (especially the ground wire) short and away from the motor wiring, and putting a 10uF capacitor between the Vdd and Vss pins of the LCD.
Title: Re: Problem with LCD and Motor
Post by: wbegg on Jan 21, 2012, 09:21 pm
Thanks dc42.

I did away with the relay, and designed a new board with a standalone arduino and motor driver together. Do you see anything that might interfere signal wise?

Should I use shielded cable to run my logic to the LCD?

Title: Re: Problem with LCD and Motor
Post by: floresta on Jan 21, 2012, 10:31 pm
I don't see any decoupling capacitors on the microprocessor power pins.

Don
Title: Re: Problem with LCD and Motor
Post by: dc42 on Jan 21, 2012, 10:58 pm
As Don days, you need at least one decoupling capacitor for the microprocessor. Your layout for the mosfet, 1000uF capacitor and motor terminals is good, however you should connect the ground side of the 12v supply direct to the junction of the mosfet source terminal and 1000uF capacitor, instead of via the mcu ground pins as you appear to be doing.
Title: Re: Problem with LCD and Motor
Post by: wbegg on Jan 21, 2012, 11:06 pm
Quote
however you should connect the ground side of the 12v supply direct to the junction of the mosfet source terminal and 1000uF capacitor, instead of via the mcu ground pins as you appear to be doing.


I'm using an old computer supply with both 12 and 5 volts with a common ground.

I'll add the decoupling caps as suggested. Thanks a bunch, guys.
Title: Re: Problem with LCD and Motor
Post by: dc42 on Jan 21, 2012, 11:20 pm

I'm using an old computer supply with both 12 and 5 volts with a common ground.


In that case, if you can't design the pcb with a ground plane, then I suggest you put a separate ground pin on your pcb for the PSU input, connected direct to that mosfet/capacitor junction. You can use the ground pin you already have for connecting the ground sides of input devices and the LCD. What you don't want is high switched currents from the psu to the motor going along a long pcb trace with devices connected to different points on that trace.

Title: Re: Problem with LCD and Motor
Post by: wbegg on Jan 22, 2012, 12:56 am
Thanks. I think I might have a completed PCB design.

Title: Re: Problem with LCD and Motor
Post by: dc42 on Jan 22, 2012, 10:51 am
No, you've now broken the connection between mosfet source and Arduino ground.
Title: Re: Problem with LCD and Motor
Post by: wbegg on Jan 22, 2012, 03:08 pm
Quote
you've now broken the connection between mosfet source and Arduino ground


There is one ground on the modified PSU (+5, +12, Gnd), so technically the source of the mosfet is connected to the arduino ground via the power supply wiring. The two grounds on the PCB are connected, just with 3 inches of wire instead of a trace. Should I still do this locally on the board as well? (i.e. add trace from mosfet source to arduino ground).

Title: Re: Problem with LCD and Motor
Post by: dc42 on Jan 22, 2012, 03:39 pm
My recommendation is to connect the ground line locally on the board instead of off-board. Take the ground feed to the Arduino from the -ve side of that 1000uF capacitor, so that capacitor leg is the junction between the wires to mosfet source, power supply ground, and Arduino ground. This will help to minimize switching noise feeding back to the Arduino. Also connect a 0.1uF ceramic capacitor in parallel with the 1000uF.
Title: Re: Problem with LCD and Motor
Post by: wbegg on Jan 22, 2012, 05:40 pm
Will do. Thank you so much for your help. I will be isolation routing this today on the CNC.
Title: Re: Problem with LCD and Motor
Post by: wbegg on Jan 23, 2012, 05:06 pm
This seems to have solved the problem, but now I just found a new one with my LCD display.

When I turn the contrast down - with 10K pot - below a certain level, and back up again, It displays strange characters, and must be reset. This is regardless of whether I have the logic pins connected or not. It's not a big issue, as I leave it turned up anyway, but just curious as to what could be causing this.

This is after an hour of wondering why the contrast didn't adjust at all only to find out the pin2 and pin 3 are swapped on my particular HD44780 compatible LCD (JHD204A - made in China).
Title: Re: Problem with LCD and Motor
Post by: floresta on Jan 23, 2012, 06:38 pm
Quote
but just curious as to what could be causing this.

You may have the potentiometer miswired so that it is shorting the power supply (and overloading the potentiometer) when you turn it to one end.

Quote
This is after an hour of wondering why the contrast didn't adjust at all only to find out the pin2 and pin 3 are swapped on my particular HD44780 compatible LCD (JHD204A - made in China).

I doubt it.  Are you sure you haven't misinterpreted or miswired the potentiometer pins.

Don
Title: Re: Problem with LCD and Motor
Post by: liuzengqiang on Jan 23, 2012, 07:39 pm
Sorry I ran away while everyone else here is kicking the ball. Could you post some hi-res pictures of how you connected the pot? I have the same suspicion as floresta. Unless you supply a picture, nobody can be sure you connected the wires correctly. Is it possible that pins 2 and 3 or pins 1 and 2 are shorted with solder bridge?
Title: Re: Problem with LCD and Motor
Post by: wbegg on Jan 23, 2012, 11:58 pm
A little tight and messy for a picture. I'm sure the pot is wired correctly, as a voltage divider. Wiper (center) to Pin 2 of LCD, one side to ground, other side to +5V. I even swapped out the pot, and same thing occurs. I even checked to make sure it was a linear pot and not log taper.

I am positive the pins 2 and 3 are swapped, and there are no solder bridges. I also had read in another forum that someone else had a JHD204A with swapped pins 2 and 3.
Title: Re: Problem with LCD and Motor
Post by: wbegg on Jan 24, 2012, 12:12 am
Oh silly me, silly me. I thought contrast was supposed to fade the lcd (characters) and not the backlight. I swapped the pot to pin 3, and all is well in silly land.

So the pins aren't switched, but my brain synapses are!
Title: Re: Problem with LCD and Motor
Post by: wbegg on Jan 24, 2012, 01:09 am
Oops, yet another brainfart. When I swapped the pins back to Pin2 5V and Pin3 Pot, I forgot I had the anode of the display (pin 15) linked to pin 3 (as I originally thought Pin 3 was Vcc. So in actuality, I was placing a voltage divider in the LED (backlight) circuit.

I am confident now that Pin 2 is Vcc as all HD44780's are. However, now I find that contrast does nothing at all if I wire everything up as correct. This is the main reason I swapped pin 2 and pin 3 originally. I prefer the way it's set up now anyway. I would much rather control the backlight anyway. Here's my hookup with contrast NOT working.

Pin 1 - Ground
Pin 2 - Vcc (+5V)
Pin 3 - Vo (wiper of potentiometer to pin 3 with one side to 5V and other side to ground).
Pin 15 - +5V through 330 ohm resistor
Pin 16 - Ground
Title: Re: Problem with LCD and Motor
Post by: floresta on Jan 24, 2012, 01:48 am
Quote
now I find that contrast does nothing at all if I wire everything up as correct.

You probably burned out the potentiometer when it was wired incorrectly.  I mentioned this in reply #23:  "You may have the potentiometer miswired so that it is shorting the power supply (and overloading the potentiometer) when you turn it to one end."

Don
Title: Re: Problem with LCD and Motor
Post by: wbegg on Jan 24, 2012, 01:55 am
Quote
You probably burned out the potentiometer when it was wired incorrectly.


Nope. Potentiometer is OK. I even swapped it out. This problem was present "out of the box" when I recieved the LCD. Plus, the potentiometer was never wired incorrectly, I just accidentally wired it to the backlight circuit (as voltage divider, so safe), but long after I first tested the LCD upon receiving it.


Title: Re: Problem with LCD and Motor
Post by: floresta on Jan 24, 2012, 03:15 am
Quote
Nope. Potentiometer is OK. I even swapped it out.

OK - Can you verify that the voltage at pin 3 is varying when you turn the potentiometer knob?

Don
Title: Re: Problem with LCD and Motor
Post by: wbegg on Jan 24, 2012, 03:31 am
Quote
Can you verify that the voltage at pin 3 is varying when you turn the potentiometer knob?


That's the first thing I checked. Yes. 0V to 5V. Meter connected  Pin 3 to ground. Fluke 175 meter.


Title: Re: Problem with LCD and Motor
Post by: DRBArduino on Jan 24, 2012, 05:12 am
I'm having the same symptoms when using a 5v relay to switch current from a 12v supply to a solenoid. I put a 2n4004 diode across the coils of the relay and the solenoid to short the back EMF, but no joy.  It works OK with just the relay clicking on and off, but one or two cycles of the 12v solenoid takes out the LCD.  Should I try the capacitor across either or both DC supplies?
Title: Re: Problem with LCD and Motor
Post by: liuzengqiang on Jan 24, 2012, 05:38 am
I'm confused. Is it working already or do you still have problems?! BTW, if you intend to use a pot to adjust back light, use a 100 ohm pot and have a 47 ohm resistor in series. You don't use 10Kohm pot for back light, which only gives you like, on (burn the back light) and off.
Title: Re: Problem with LCD and Motor
Post by: wbegg on Jan 24, 2012, 07:21 am
liudr,

Read the past posts. I hooked up wrong to the backlite, and the pot worked to dim the backlight. I hooked up as it should have been, and the LCD contrast does not work.

Now I have a 330 ohm in series with the backlight and control the brightness with a 10k pot. It works. Still, pin 3 does not adjust contrast.
Title: Re: Problem with LCD and Motor
Post by: wbegg on Jan 24, 2012, 07:51 am
DRBArduino,

yes, It worked for me. Filtering is your friend and caps seem to work.
Title: Re: Problem with LCD and Motor
Post by: liuzengqiang on Jan 24, 2012, 04:25 pm

liudr,

Read the past posts. I hooked up wrong to the backlite, and the pot worked to dim the backlight. I hooked up as it should have been, and the LCD contrast does not work.

Now I have a 330 ohm in series with the backlight and control the brightness with a 10k pot. It works. Still, pin 3 does not adjust contrast.



That's good summary. I still don't recommend using 10K pot for backlight though but I get how overconfident you are so do what you want. So now you can't make the contrast to change. Please disconnect all data, RS, EN wires from the LCD if you want to try the contrast. I didn't get whether you are running some LCD code or not. Just don't run LCD code and get the contrast step to work first. Bear in mind, you did connect up wrong wires so the LCD may have already been damaged beyond operation. Things happen rather quickly when wires are connected up wrong. Again, where are those pictures? You apparently were overconfident and under-organized but a few pictures will redeem yourself here. You were "connecting everything correctly" and that made several helpers think hard what other things could have gone wrong, all wasting their time, only if you showed a pic or two.
Title: Re: Problem with LCD and Motor
Post by: wbegg on Jan 25, 2012, 03:19 am
Tried another LCD and it works. Guess the contrast circuit on the one in question is Fubared.
Title: Re: Problem with LCD and Motor
Post by: liuzengqiang on Jan 25, 2012, 02:43 pm
That's good news. So in this case, there is no need for a picture unless you want to show a working LCD. Electronics just don't like to be connected up wrong. I fried a $30 accelerometer once. It only took seconds.
Title: Re: Problem with LCD and Motor
Post by: daytrader152 on Oct 11, 2012, 08:03 am
I am having similar issue. My LCD connected to the UNO displays strange characters after turning on/off the 5V relay for a dozen times. The relay controls a 12V solenoid (an electric strike for a door). I know it has to do with the EMF because if I disconnect the solenoid, the problem does not happen. My relay setup is similar to this: http://www.instructables.com/id/Connecting-a-12V-Relay-to-Arduino, except my relay is 5V, and I am powering the relay with 5V from the UNO. Here are the things I have tried so far:

- used an external power adaptor to power the 5V relay
- placed 6.8uF cap across the coil of the relay
- placed 90uF cap across the 12V rail
- used a separate 12V power supply for the solenoid

Does anyone have any suggestion for me to how suppress the EMF? Thanks.
Title: Re: Problem with LCD and Motor
Post by: dc42 on Oct 11, 2012, 11:06 am
Assuming the solenoid is powered from DC, connect a diode (1N400x or similar, x = 1 to 7) in parallel with the solenoid, wired so that when the solenoid is engaged it does not conduct (otherwise it would short out the power supply).

Also, don't run the solenoid wires close to the LCD or its wiring, and do run the solenoid wires close to each other so that the area enclosed by the 12V supply - relay contacts - solenoid circuit is kept to a minimum.

Also, make sure that the +5v and ground wires from the LCD go directly to the Arduino, not to some common connection that then has a shared wire connecting it to the Arduino.
Title: Re: Problem with LCD and Motor
Post by: daytrader152 on Oct 11, 2012, 08:17 pm
Thanks a lot, mate! Placing the diode across the solenoid did the trick! It's much more stable now. I think I just need to place the diode even closer to the solenoid to completely get rid off the problem. Right now the diode is about 30cm away from the solenoid.

I have another similar circuit with a LCD and 256 relays (to control 256 electronic solenoids). This setup also experiences the same rubbish character problem on the LCD, so I will need to place the diode across all the solenoids as shown in the attachment. Is there an easier way to place the diodes? It's quite a bit of work to cut the wires and solder the diodes on all 256 solenoids. Thanks again!
Title: Re: Problem with LCD and Motor
Post by: dc42 on Oct 11, 2012, 10:28 pm
From the photo, it looks as if those solenoids are held together by 4 screws with hex or Torx heads. It might be worth disassembling one, to see whether there is room to fit a diode inside (although that will probably invalidate the warranty). If space is limited, then depending on the current taken by the solenoid, you may be able to use a smaller diode. You can also get 1N400x diodes in SMD packages.
Title: Re: Problem with LCD and Motor
Post by: amitkrj on Oct 12, 2012, 08:06 pm
I am also having similar issue. My LCD connected to the UNO displays strange characters after turning on/off the 5V relay for a 10-15 times. The relay controls a 220v AC solenoid and another relay controls a Contactor (220V AC). Both relay has diode contected (IN4007).
I tryed putting cap 100uF around display but LCD still displays strange characters.
Does anyone have any suggestion for me. Thanks
Title: Re: Problem with LCD and Motor
Post by: liuzengqiang on Oct 12, 2012, 08:24 pm
You tried a 1n4004 diode yet?
Title: Re: Problem with LCD and Motor
Post by: floresta on Oct 12, 2012, 08:49 pm
Whenever you see the term 'motor' or 'relay' in the same sentence as 'LCD problem' the answer is almost always the same. 

Don
Title: Re: Problem with LCD and Motor
Post by: dc42 on Oct 12, 2012, 09:45 pm
Do you have dedicated +5V and ground wires from the Arduino to the LCD? Shared grounds can cause a lot of problems.
Title: Re: Problem with LCD and Motor
Post by: daytrader152 on Oct 13, 2012, 08:07 am

From the photo, it looks as if those solenoids are held together by 4 screws with hex or Torx heads. It might be worth disassembling one, to see whether there is room to fit a diode inside (although that will probably invalidate the warranty). If space is limited, then depending on the current taken by the solenoid, you may be able to use a smaller diode. You can also get 1N400x diodes in SMD packages.


@DC42, I opened up the solenoid, and inside is one complete unit, so there is no way to place the diode inside. What I did was to place the diode as shown in my previous photo (where the scissors symbol is pointing at) to see if I can completely suppress the EMF. To my surprise, this new setup actually made it worse. Now I see garbage on the LCD all the time. Attached is a drawing of my old and new setup. The diode on the left-hand side is the old setup where I place the diode about half way between the solenoid and the 12V power supply. This setup works sometimes. The diode on the right-hand side is the new setup, which always fails, i.e. garbage on LCD. This is completely opposite to what I expect to happen. Any suggestion? Thanks.
Title: Re: Problem with LCD and Motor
Post by: dc42 on Oct 13, 2012, 10:45 am
Yes, it does seem strange. I suggest you test the diode that you fitted in the new position. Does the garbage appear when the solenoid turns on, or when it turns off? Also see my previous reply about +5v and ground wires to the LCD. A photo of your wiring would help.
Title: Re: Problem with LCD and Motor
Post by: daytrader152 on Oct 13, 2012, 06:51 pm

Yes, it does seem strange. I suggest you test the diode that you fitted in the new position. Does the garbage appear when the solenoid turns on, or when it turns off? Also see my previous reply about +5v and ground wires to the LCD. A photo of your wiring would help.


I will do more testing here, and take a photo after I clean up the wiring. The garbage characters appear always when the solenoid is turned off. I am powering the LCD using the 5V and GND pins directly from the Arduino UNO's power rail. Thanks.
Title: Re: Problem with LCD and Motor
Post by: amitkrj on Oct 13, 2012, 08:19 pm

You tried a 1n4004 diode yet?

Thanks liudr for your reply, Today i tried to buy 1n4004 diode but all verdors are saying that the replacement/upgrade is 1n4007 and 1n4004 is outdated and not avalable. Do you have any other solution for this problme? Thanks in advance.
Title: Re: Problem with LCD and Motor
Post by: floresta on Oct 13, 2012, 09:35 pm
Quote
Thanks liudr for your reply, Today i tried to buy 1n4004 diode but all verdors are saying that the replacement/upgrade is 1n4007 and 1n4004 is outdated and not avalable. Do you have any other solution for this problme? Thanks in advance.

All of the 1N4000 series devices are essentially the same except for their reverse voltage rating.  The higher the number the higher the voltage rating.  Therefore a 1N4007 can replace a 1N4004 with no problems.

Don
Title: Re: Problem with LCD and Motor
Post by: liuzengqiang on Oct 14, 2012, 02:57 am
If you get problem when you disengage the solenoid, then it is the diode's problem or how it is connected. If you have it correctly connected then the diode will bypass the back EMF. Let us see the connection diagram and the actual photo.
Title: Re: Problem with LCD and Motor
Post by: daytrader152 on Oct 14, 2012, 08:53 am

If you get problem when you disengage the solenoid, then it is the diode's problem or how it is connected. If you have it correctly connected then the diode will bypass the back EMF. Let us see the connection diagram and the actual photo.


Attached is a photo of the relay and solenoid. I was trying out different length of the wires, and it seems that a long wire between NO of the relay to the cathode of the diode yields the best result (even though it still does not completely suppress the back EMF). The power supply is a dedicated 12V with 10A rating, and has no connection to the Arduino UNO. The 12V solenoid draws about 1A when active. Please let me know if you have any suggestion or need more information. Thanks.
Title: Re: Problem with LCD and Motor
Post by: liuzengqiang on Oct 15, 2012, 01:10 am
Help me here, is this what you want to do?

Turn on a relay that powers a solenoid? The diode needs to be at the relay coil side. The solenoid? separate the 12V supply ground from arduino's. They don't have to and should not share grounds.

I only see the box (you held it in your hand in the other picture). Is the relay inside the box or is it outside your picture?
Title: Re: Problem with LCD and Motor
Post by: daytrader152 on Oct 15, 2012, 08:43 am

Help me here, is this what you want to do?

Turn on a relay that powers a solenoid? The diode needs to be at the relay coil side. The solenoid? separate the 12V supply ground from arduino's. They don't have to and should not share grounds.

I only see the box (you held it in your hand in the other picture). Is the relay inside the box or is it outside your picture?


Yes, there is also a diode on the relay coil side. Attached are the schematics of the customized 8-unit relay board and a photo of the relay PCB. I am using the Arduino to control the two input pins of each relay (a matrix configuration), so I can control 256 relays with one Arduino. The box in my hand is the solenoid. The relay is shown in this attachment.

Regarding the ground, Arduino is powered by its own 12V power supply, which is separate from the 12V power supply for the solenoid. The relay is 5V and is powered from Arduino. Thanks.
Title: Re: Problem with LCD and Motor
Post by: liuzengqiang on Oct 15, 2012, 05:12 pm
OK got it. If you only switch relays without solenoids attached, will you see garbage on LCD? Can you give a large picture of the arduino and LCD included?
Title: Re: Problem with LCD and Motor
Post by: daytrader152 on Oct 23, 2012, 01:49 am

OK got it. If you only switch relays without solenoids attached, will you see garbage on LCD? Can you give a large picture of the arduino and LCD included?


Sorry for the delay. This past week I have been trying to find a consistent way to reproduce the problem. I cleaned up the wiring, so I can take a better picture to show you guys. After that, I have not been able to reproduce the problems consistently (the problem still exists). Attached are the photos of the Arduino side with two closeup photos. The wiring of the LCD is the same as the Arduino tutorial, except I have added a 150 ohm resistor to the LCD backlight supply voltage as suggested by another post. I will add more labels to the wiring later tonight or tomorrow, so you guys can better understand my setup. Thanks.
Title: Re: Problem with LCD and Motor
Post by: liuzengqiang on Oct 23, 2012, 05:05 am
What about driving the relays without the solenoids connected? Still junks?
Title: Re: Problem with LCD and Motor
Post by: dc42 on Oct 23, 2012, 02:34 pm
In the photo, I can see a brown wire and a black wire from the LCD, and these wires appear to go under the table. Which connections are they, and where do they go? I also see some wires from the top end of the LCD going to the breadboard, and there appears to be a +5V connection to the breadboard which is shared with other devices. See my previous advice about using dedicated Vcc and ground wires between the Arduino and the LED. Sharing the Vcc and ground to the backlight with other connection should be OK though, provided the backlight cathode connection on the LCD is isolated from the LCD signal ground connection.

Try to keep all the LCD signal, Vcc and ground wires (not counting the backlight wires) close together, with no big loops. I can see 4 wires (red, yellow, orange, green) like this, but the rest are all over the place.
Title: Re: Problem with LCD and Motor
Post by: liuzengqiang on Oct 23, 2012, 03:14 pm
To add on dc42's suggestion, you want a capacitor between 5V and gnd on the breadboard. Try 0.1 uF to 10uF cap.
Title: Re: Problem with LCD and Motor
Post by: daytrader152 on Oct 23, 2012, 07:06 pm
Hi dc42 and liudr,

Thank you for your advice. Attached is a closeup of the Arduino with labels. It should clear up some confusion regarding the wiring.

@liudr, I will add the cap between Vcc and GND.

@dc42, just to confirm, the Arduino, LCD and backlight should be powered as follows:

Arduino <- dedicated 12V power supply
LCD <- dedicated 5V power supply
backlight <- same power supply as the LCD

Many thanks!
Title: Re: Problem with LCD and Motor
Post by: dc42 on Oct 23, 2012, 07:20 pm
No, the LCD (other than the backlight) must be powered from the Arduino 5V pin. The backlight can also be powered from the 5V pin (but that will increase the dissipation in the regulator), or from a separate 5V supply, or (if it is a standard LED backlight and has no low-voltage caps across it) from the 12V supply if you use a larger series resistor.
Title: Re: Problem with LCD and Motor
Post by: liuzengqiang on Oct 23, 2012, 10:02 pm
Does the relay control have a ground that goes from arduino to breadboard then to relay control? Just checking.
Title: Re: Problem with LCD and Motor
Post by: daytrader152 on Oct 24, 2012, 03:05 am

Does the relay control have a ground that goes from arduino to breadboard then to relay control? Just checking.


The 5V relay control is currently powered by the same 5V/GND from the Arduino to the LCD & backlight. Is this correct?

About half an hour ago, the garbage character problem showed up again. It happened when I tried to turn on and off 17 solenoids (one by one in consecutive order with one second in between). But it did not happen again when I repeated the same steps. So the problem is evasive. BTW, I do not have the 10uF cap between Vcc and GND yet as I still need to get the part from the local store.
Title: Re: Problem with LCD and Motor
Post by: liuzengqiang on Oct 24, 2012, 05:54 am
This is the LAST time I am asking you: what happens if you just switch the relays without solenoids connected to the relays.
Title: Re: Problem with LCD and Motor
Post by: daytrader152 on Oct 24, 2012, 06:30 am

This is the LAST time I am asking you: what happens if you just switch the relays without solenoids connected to the relays.


I would like to give you a definitive answer, but I can't. It took entire day to reproduce this problem once (with the solenoid connected). A few days ago I did disconnect the solenoid, and the problem did not occur for the entire day. However, it does not mean the problem would not occur without the solenoid connected. Until I find a consistent way of producing the problem, there is just no way to be sure.
Title: Re: Problem with LCD and Motor
Post by: liuzengqiang on Oct 24, 2012, 06:45 am


This is the LAST time I am asking you: what happens if you just switch the relays without solenoids connected to the relays.


I would like to give you a definitive answer, but I can't. It took entire day to reproduce this problem once (with the solenoid connected). A few days ago I did disconnect the solenoid, and the problem did not occur for the entire day. However, it does not mean the problem would not occur without the solenoid connected. Until I find a consistent way of producing the problem, there is just no way to be sure.


En, understand. Try the capacitor then, just leave your system for a day or so and check back on the LCD. You don't need 10 uF something less than that will also work.
Title: Re: Problem with LCD and Motor
Post by: nanohex on Oct 27, 2012, 10:14 am
This may seem like a noob point, but I noticed your PCB doesn't have a ground flood? You should try adding one in to aid in heat-sinking!

...apologies if you already know this  :P
Title: Re: Problem with LCD and Motor
Post by: daytrader152 on Oct 27, 2012, 06:02 pm

This may seem like a noob point, but I noticed your PCB doesn't have a ground flood? You should try adding one in to aid in heat-sinking!

...apologies if you already know this  :P


@liudr, I added the cap at LCD Vdd and Vss. Unfortunately the problem still exists. :( I will try cleaning up all the wiring and solder joints.

@nanohex, would you mind clarifying the ground flood for me? I am not too familiar with it. Thanks.
Title: Re: Problem with LCD and Motor
Post by: liuzengqiang on Oct 27, 2012, 06:55 pm
I think nanohex was talking about your relay circuit board having no ground plane. But it may have some on the bottom side.
Title: Re: Problem with LCD and Motor
Post by: dc42 on Oct 27, 2012, 07:11 pm

Hi dc42 and liudr,

Thank you for your advice. Attached is a closeup of the Arduino with labels. It should clear up some confusion regarding the wiring.


You haven't yet implemented the suggestion in my reply #59 because the power and ground wires to the LCD do not follow the same route as the signal wires.

Keep the +5v and ground wires to the relay separate from the ones to the LCD as far as possible. You shouldn't need to use the same ground pin for both because you have 3 ground pins on the mega. If the LCD and relay share the +5V connection, keep that shared wire as short as possible.

How are you driving the relay: through a transistor?
Title: Re: Problem with LCD and Motor
Post by: daytrader152 on Oct 27, 2012, 09:06 pm


Hi dc42 and liudr,

Thank you for your advice. Attached is a closeup of the Arduino with labels. It should clear up some confusion regarding the wiring.


You haven't yet implemented the suggestion in my reply #59 because the power and ground wires to the LCD do not follow the same route as the signal wires.

Keep the +5v and ground wires to the relay separate from the ones to the LCD as far as possible. You shouldn't need to use the same ground pin for both because you have 3 ground pins on the mega. If the LCD and relay share the +5V connection, keep that shared wire as short as possible.

How are you driving the relay: through a transistor?


I will keep the LCD signal/power/gnd wires all close together.

Regarding the relay, it is powered by a separate 5V power supply. I am driving the relay through two transistors to provide a matrix configuration as shown in the attached schematic (containing 8 relay modules).
Title: Re: Problem with LCD and Motor
Post by: nanohex on Oct 28, 2012, 11:47 am
Quote
@nanohex, would you mind clarifying the ground flood for me? I am not too familiar with it. Thanks./


I couldn't come up with a decent explanation in my own words so this is from Wikipedia:

"A ground plane on a printed circuit board (PCB) is a large area or layer of copper foil connected to the circuit's ground point, usually one terminal of the power supply. It serves as the return path for current from many different components.
A ground plane is often made as large as possible, covering most of the area of the PCB which is not occupied by circuit traces. In multilayer PCBs, it is often a separate layer covering the entire board. This serves to make circuit design easier, allowing the designer to ground any component without having to run additional traces; component wire needing grounding is routed directly through a hole in the board to the ground plane on another layer. The large area of copper also conducts the large return currents from many components without significant voltage drops, ensuring that the ground connection of all the components are at the same reference potential."

Basically any area that's just left empty (copper etched away; no traces) is instead left with its original copper. These are then connected to ground.
Title: Re: Problem with LCD and Motor
Post by: daytrader152 on Oct 28, 2012, 06:00 pm

Quote
@nanohex, would you mind clarifying the ground flood for me? I am not too familiar with it. Thanks./


I couldn't come up with a decent explanation in my own words so this is from Wikipedia:

"A ground plane on a printed circuit board (PCB) is a large area or layer of copper foil connected to the circuit's ground point, usually one terminal of the power supply. It serves as the return path for current from many different components.
A ground plane is often made as large as possible, covering most of the area of the PCB which is not occupied by circuit traces. In multilayer PCBs, it is often a separate layer covering the entire board. This serves to make circuit design easier, allowing the designer to ground any component without having to run additional traces; component wire needing grounding is routed directly through a hole in the board to the ground plane on another layer. The large area of copper also conducts the large return currents from many components without significant voltage drops, ensuring that the ground connection of all the components are at the same reference potential."

Basically any area that's just left empty (copper etched away; no traces) is instead left with its original copper. These are then connected to ground.


Thank you for the explanation. It turned out that there is no ground plane on my relay PCB. Is there anything I can do?
Title: Re: Problem with LCD and Motor
Post by: nanohex on Oct 29, 2012, 03:04 pm
If you're using Eagle CAD, you need to draw a polygon around the perimeter of your board, and rename it to GND. Make sure you change the 'isolation' tab to around 12 mils or so (this changes how much clearance you want between the ground plane and other traces). Do this on both sides, then hit the rat's nest tool to see it work! I'm not sure how to do this on other PCB layout programs though.

Jeremy Blum has a nice tutorial on youtube (for Eagle) - watch part 2 and skip forward to where he adds the ground plane to see!
Title: Re: Problem with LCD and Motor
Post by: shinesreedhar on Jun 22, 2015, 10:44 pm
You need to put the snubber between from "-" to "+" on the relay coil. Problem will definitely solved.




(https://upload.wikimedia.org/wikipedia/commons/e/ec/Snubber.jpg)



Visit : Techjeeva Technologies Pvt. Ltd. (http://techjeeva.com)
Title: Re: Problem with LCD and Motor
Post by: floresta on Jun 22, 2015, 11:03 pm
This must be the universal answer to all LCD problems no matter how old.

Don