Nestboxtech
Posts: 40
Joined: Fri Apr 11, 2014 9:45 pm
Contact: Website

L293D troubleshooting for IR camera cut control

Sun Jan 18, 2015 5:24 pm

Hi,

I've got a mechanical IR cut filter that I'm planning on using to convert the IR PiCamera to a Normal light version depending on the levels of ambient light (+/- external IR LED array). This particular mechanical IR filter I think is based on a solenoid that moves the IR filter when a current is applied. If I connect it 5V and GND, it moves the IR filter one way. To move it back, I need to swop V and GND around. I had the idea of using an L293D ic in the same way as used to run a DC motor forwards or backwards as a way of achieving the same effect of manually swopping the polarity around of the 5v and GND connections.

I've built my bread board as follows, which is based on the following blog post:
http://computers.tutsplus.com/tutorials ... -cms-20051
My main modification is to remove the external batteries for the 'motor Vcc' input and substitue with the 5V supply of the Pi, on the basis that the IR cut filter is activated by connecting directly to the 5V pin and GND.

My layout is as follows:
Image

Code as follows:

Code: Select all

import RPi.GPIO as GPIO
from time import sleep
 
GPIO.setmode(GPIO.BOARD)
 
Motor1A = 16
Motor1B = 18
Motor1E = 22
 
GPIO.setup(Motor1A,GPIO.OUT)
GPIO.setup(Motor1B,GPIO.OUT)
GPIO.setup(Motor1E,GPIO.OUT)
 
print "Going forwards"
GPIO.output(Motor1A,GPIO.HIGH)
GPIO.output(Motor1B,GPIO.LOW)
GPIO.output(Motor1E,GPIO.HIGH)
 
sleep(2)
 
print "Going backwards"
GPIO.output(Motor1A,GPIO.LOW)
GPIO.output(Motor1B,GPIO.HIGH)
GPIO.output(Motor1E,GPIO.HIGH)
 
sleep(2)
 
print "Now stop"
GPIO.output(Motor1E,GPIO.LOW)
 
GPIO.cleanup()
The problem is that I just get 0V across pin 3 and 6 of the L293D.
I can detect voltage changing as per the code in the enabling GPIO lead and both the other two, but cannot get any output to work. Power form the Pi seems okay, and GPIO pins go high / low as they should.

Any ideas - or have a made silly mistake ?
http://nestboxtech.blogspot.co.uk/

User avatar
joan
Posts: 12776
Joined: Thu Jul 05, 2012 5:09 pm
Location: UK

Re: L293D troubleshooting for IR camera cut control

Sun Jan 18, 2015 6:12 pm

Post a photo of your actual set up.

PiGraham
Posts: 2679
Joined: Fri Jun 07, 2013 12:37 pm
Location: Waterlooville

Re: L293D troubleshooting for IR camera cut control

Sun Jan 18, 2015 6:27 pm

Does this device require voltage reversal to
You should have flywheel diodes across the motor terminals to protect high voltage spikes that result when you turn off the supply to an inductive load. {ETA} Use the L293D not L293, or add extrernal diodes.
See the data sheet: http://www.ti.com/lit/ds/symlink/l293d.pdf

That isn't why this doesn't work, unless high voltages have damaged the L293 already.

What voltage do you measure between GND and 3 and GND and 6? If the enable is high and the input is high the output should be high. To turn the motor you need one side high and the other low.

Actually, it might help if you could measure the voltage on each pin of the L193 for forward and reverse conditions.

I take it the device switches OK if you connect the wires direct to 5V and GND?
Last edited by PiGraham on Sun Jan 18, 2015 6:42 pm, edited 1 time in total.

User avatar
joan
Posts: 12776
Joined: Thu Jul 05, 2012 5:09 pm
Location: UK

Re: L293D troubleshooting for IR camera cut control

Sun Jan 18, 2015 6:31 pm

PiGraham wrote:Does this device require voltage reversal to
You should have flywheel diodes across the motor terminals to protect high voltage spikes that result when you turn off the supply to an inductive load. See the data sheet: http://www.ti.com/lit/ds/symlink/l293d.pdf

That isn't why this doesn't work, unless high voltages have damaged the L293 already.

What voltage do you measure between GND and 3 and GND and 6? If the enable is high and the input is high the output should be high. To turn the motor you need one side high and the other low.

Actually, it might help if you could measure the voltage on each pin of the L193 for forward and reverse conditions.

I take it the device switches OK if you connect the wires direct to 5V and GND?
Hopefully the OP is using the L293D as I think that has the fly-back diodes built-in.

PiGraham
Posts: 2679
Joined: Fri Jun 07, 2013 12:37 pm
Location: Waterlooville

Re: L293D troubleshooting for IR camera cut control

Sun Jan 18, 2015 6:41 pm

joan wrote:Hopefully the OP is using the L293D as I think that has the fly-back diodes built-in.
Ah, so it does.

gordon77
Posts: 2993
Joined: Sun Aug 05, 2012 3:12 pm

Re: L293D troubleshooting for IR camera cut control

Sun Jan 18, 2015 6:51 pm

joan wrote:
PiGraham wrote:Does this device require voltage reversal to
You should have flywheel diodes across the motor terminals to protect high voltage spikes that result when you turn off the supply to an inductive load. See the data sheet: http://www.ti.com/lit/ds/symlink/l293d.pdf

That isn't why this doesn't work, unless high voltages have damaged the L293 already.

What voltage do you measure between GND and 3 and GND and 6? If the enable is high and the input is high the output should be high. To turn the motor you need one side high and the other low.

Actually, it might help if you could measure the voltage on each pin of the L193 for forward and reverse conditions.

I take it the device switches OK if you connect the wires direct to 5V and GND?
Hopefully the OP is using the L293D as I think that has the fly-back diodes built-in.
The Op said they were.

Nestboxtech
Posts: 40
Joined: Fri Apr 11, 2014 9:45 pm
Contact: Website

Re: L293D troubleshooting for IR camera cut control

Sun Jan 18, 2015 7:07 pm

joan wrote:Post a photo of your actual set up.
Image
http://nestboxtech.blogspot.co.uk/

Nestboxtech
Posts: 40
Joined: Fri Apr 11, 2014 9:45 pm
Contact: Website

Re: L293D troubleshooting for IR camera cut control

Sun Jan 18, 2015 7:11 pm

joan wrote:
PiGraham wrote:Does this device require voltage reversal to
You should have flywheel diodes across the motor terminals to protect high voltage spikes that result when you turn off the supply to an inductive load. See the data sheet: http://www.ti.com/lit/ds/symlink/l293d.pdf

That isn't why this doesn't work, unless high voltages have damaged the L293 already.

What voltage do you measure between GND and 3 and GND and 6? If the enable is high and the input is high the output should be high. To turn the motor you need one side high and the other low.

Actually, it might help if you could measure the voltage on each pin of the L193 for forward and reverse conditions.

I take it the device switches OK if you connect the wires direct to 5V and GND?
Hopefully the OP is using the L293D as I think that has the fly-back diodes built-in.
Yup, using L293D. Also, it does work if connected directly to 5V and GND.
http://nestboxtech.blogspot.co.uk/

gordon77
Posts: 2993
Joined: Sun Aug 05, 2012 3:12 pm

Re: L293D troubleshooting for IR camera cut control

Sun Jan 18, 2015 7:34 pm

I cant see a wire on pin 16 of the l293

Nestboxtech
Posts: 40
Joined: Fri Apr 11, 2014 9:45 pm
Contact: Website

Re: L293D troubleshooting for IR camera cut control

Sun Jan 18, 2015 8:13 pm

gordon77 wrote:I cant see a wire on pin 16 of the l293
Oh for an easy fix ;)
Unfortunate camera angle, new pic below:

Image
http://nestboxtech.blogspot.co.uk/

User avatar
joan
Posts: 12776
Joined: Thu Jul 05, 2012 5:09 pm
Location: UK

Re: L293D troubleshooting for IR camera cut control

Sun Jan 18, 2015 8:33 pm

Are you sure the L293D is actually making contact with the breadboard? The top pins seem to be inserted one row higher than needed.

gordon77
Posts: 2993
Joined: Sun Aug 05, 2012 3:12 pm

Re: L293D troubleshooting for IR camera cut control

Sun Jan 18, 2015 9:40 pm

Can you measure 5v on pin 16?

Nestboxtech
Posts: 40
Joined: Fri Apr 11, 2014 9:45 pm
Contact: Website

Re: L293D troubleshooting for IR camera cut control

Sun Jan 18, 2015 10:19 pm

joan wrote:Are you sure the L293D is actually making contact with the breadboard? The top pins seem to be inserted one row higher than needed.
arrrgh... this was the problem. I'm such an idiot! Thanks for the help :)

Next step is to integrate this with PiNoir Camera
I can now work on switching the IR cutout based on ambient light and LED array activation.

Many thanks folks
http://nestboxtech.blogspot.co.uk/

User avatar
joan
Posts: 12776
Joined: Thu Jul 05, 2012 5:09 pm
Location: UK

Re: L293D troubleshooting for IR camera cut control

Sun Jan 18, 2015 10:22 pm

Nestboxtech wrote: ...
arrrgh... this was the problem. I'm such an idiot! Thanks for the help :)
...
We have the advantage of making the same mistake before you.

Nestboxtech
Posts: 40
Joined: Fri Apr 11, 2014 9:45 pm
Contact: Website

Re: L293D troubleshooting for IR camera cut control

Sun Jan 18, 2015 10:31 pm

....so if you could just list them all please ;)
http://nestboxtech.blogspot.co.uk/

physis
Posts: 7
Joined: Sun Oct 29, 2017 7:41 am

Re: L293D troubleshooting for IR camera cut control

Sat Nov 04, 2017 4:32 pm

Hi,

Great information. Cheers :)

One question, where would be the best place put a LDR sensor in your circuit?

Thanks.

Diogo

pcmanbob
Posts: 2015
Joined: Fri May 31, 2013 9:28 pm
Location: Mansfield UK

Re: L293D troubleshooting for IR camera cut control

Sat Nov 04, 2017 8:25 pm

You would not add an LDR to a motor driver circuit based on an L293D.
An L239D requires 3 digital inputs to control it, where as an LDR is an analogue device.
Please only ask questions in the forum I will not answer questions sent to me directly via PM
Remember we want information.......................no information no help

PiGraham
Posts: 2679
Joined: Fri Jun 07, 2013 12:37 pm
Location: Waterlooville

Re: L293D troubleshooting for IR camera cut control

Mon Nov 06, 2017 7:09 am

physis wrote:
Sat Nov 04, 2017 4:32 pm
Hi,

Great information. Cheers :)

One question, where would be the best place put a LDR sensor in your circuit?

Thanks.

Diogo
Why do you need an LDR when you have an image sensor? Take a picture and measure brightness from that. If the average is below some threshold then it's too dark and you should switch to night mode.

physis
Posts: 7
Joined: Sun Oct 29, 2017 7:41 am

Re: L293D troubleshooting for IR camera cut control

Thu Nov 09, 2017 3:20 pm

Hey,
Thanks for your reply. I will explain better why my question.
I'm building a trail cam with Pi3 + NoIR v2.1 cam with an IR-Cut filter. The cam software I'm using is the PiKrellCam with motion detection to trigger videos or photos. Shoots at night will be illuminate by IR Led that will depend of a LDR sensor. To avoid be all the time ON, the light IR leds will just turn on when the PIR sensor detects motion. I will use a circuit like this diagram to make the IR Light System:

Image

For the IR-Cut filter I will use the circuit like the one described in this topic. My question is, how could I make the IR-Cut Filter system depending of the LDR state but not influenced by the PIR sensor?
In this way the filter will switch when LDR is low changing the cam to "night mode".

Notes:
To power the Pi I will use a power bank with double outlet, one connected to the Pi and other outlet to power the IR Light System using a set-up boost 5v to 12v. The 3V3 source for the IR Light System will come from Pi.
I'm making the whole electronic circuit with Fritzing that I will upload soon for better visualization. Is my first Pi project and I don't have an electronic background. So, I'm open to all suggestions to make the whole circuit easier.

Cheers.
Diogo

pcmanbob
Posts: 2015
Joined: Fri May 31, 2013 9:28 pm
Location: Mansfield UK

Re: L293D troubleshooting for IR camera cut control

Thu Nov 09, 2017 4:34 pm

Have you thought about hooking the PIR and LDR up to your pi gpio and then using the inputs from that in a simple python program to switch your filter via the motor driver and also switch your IR LED , that way you could switch your IR LED on only when you detected something you wanted to capture with the camera.

If you really want to do it all in hardware you would need to put fixed inputs on the L239D enable and one of the direction inputs and then use the LDR to control the other direction input, you would need to use the LDR as part of a potential divider circuit so that the input to the L239D goes from high to low with the change of light. Some experimentation would be required to get this working correctly.
Please only ask questions in the forum I will not answer questions sent to me directly via PM
Remember we want information.......................no information no help

physis
Posts: 7
Joined: Sun Oct 29, 2017 7:41 am

Re: L293D troubleshooting for IR camera cut control

Mon Nov 13, 2017 10:21 am

Hey pcmanbob,
Once again thanks for your reply. :)

My reason for using only hardware to control the light system is because I would like to connect as well a RTC and a temperature/humidity sensor and I thought that would be too many things running in the same time and could draw too much power from the Pi. However I found a new power bank with would be possible connect everything supplying a good current to Pi.
From the page that I took the hardware set-up showed in the previous post, they present the same system but using Pi.

Image

The Code:

Code: Select all

from gpiozero import LED, MotionSensor, LightSensor
from signal import pause
pir = MotionSensor(21)
ldr = LightSensor(26)
light = LED(25)
def daytime():
    pir.when_motion = None
    pir.when_no_motion = None
    light.off()
def nighttime():
    pir.when_motion = light.on
    pir.when_no_motion = light.off
ldr.when_light = daytime
ldr.when_dark = nighttime
pause()
Source: http://raspi.tv/2015/gpio-zero-test-dri ... f-security

I don't have python skills and is my first Pi project. My ultimate goal in to make a Pi Trail Cam with night vision as a gift for my girlfriend birthday :)

To use Pi to manage all the system, I need to merge/combine the two scripts, the one that controls the IR-Cut Filter with the one that controls the IR Light system. In this way I can put the IR-Cut system reading the data from the LDR sensor and switch the filter according with the ambient light.

I have no idea how to do it. Any suggestions?
As you said, with a simple python code I can do it, the thing is, at the moment, a simple code for me is still a big thing. I’m reading some tutorials and courses but at the moment I’m not able to do it by myself.

Well, thanks a lot.
Diogo

pcmanbob
Posts: 2015
Joined: Fri May 31, 2013 9:28 pm
Location: Mansfield UK

Re: L293D troubleshooting for IR camera cut control

Mon Nov 13, 2017 10:51 am

With any project the best thing to do is approach it as separate parts and once you have each working then you can consider combining them in to one program.

decide on which gpio software your going to use and use it for all the parts of your project, the original motor drive circuit used RPi.GPIO but your pir/light sensor is using gpiozero you can't mix them as you will be trying to control the gpio with 2 different bits of software a recipe for disaster.

we can't write your code for you as we don't have access to your particular hardware setup and your diagram does not show all the hardware connected to your pi.

if you want I can try and put a bit of code together based on your diagram and the original info on the motor driver assuming that non of the gpio assignments clash, but it will be untested and you will have to debug it yourself to make it work with your hardware, but it might give you a starting point.
Please only ask questions in the forum I will not answer questions sent to me directly via PM
Remember we want information.......................no information no help

physis
Posts: 7
Joined: Sun Oct 29, 2017 7:41 am

Re: L293D troubleshooting for IR camera cut control

Mon Nov 13, 2017 12:25 pm

I will use the GPIOzero because looks like it's easier to learn and use.
I'm away from my laptop for now I can't show all my circuit diagram. But will be the fusion of both diagrams.

From the GPIOZero Docs (https://gpiozero.readthedocs.io/en/stab ... tml#motors) the recipe to control de motor is really simple.

Image

Code: Select all

from gpiozero import Motor
from time import sleep

motor = Motor(forward=4, backward=14)

while True:
    motor.forward()
    sleep(5)
    motor.backward()
    sleep(5)
Having this two scripts using the gpiozero library, my problem is the final script, where the motor use data from the LDR.
I can't test the complete system for now because I'm still waiting for some parts. However this is my hardware list:

L293D: https://thepihut.com/products/adafruit- ... 00ma-l293d
IR-Cut Filter (works with 5V): https://www.ebay.co.uk/itm/IR-CUT-M12-M ... 2749.l2649
IR Leds: https://www.aliexpress.com/item/CCTV-Ac ... 44590.html
LDR: https://www.aliexpress.com/item/20pcs-P ... 21732.html
PIR: https://www.ebay.co.uk/itm/1-HC-SR501-A ... 2749.l2649
Relay: https://www.ebay.co.uk/itm/5V-1-2-4-6-8 ... x35DAVMXYg
PowerBoost 5v to 12: https://www.aliexpress.com/item/5pcs-DC ... 98973.html
Powerbank: https://www.asus.com/Phone-Accessory/AS ... fications/

Raspberry Pi 3 + NoIR v2.1


As soon as possible I will post my whole circuit.
An electronic question, if I connect all the components in the same breadboard can I use only a 5V pin from Pi? Or it would be too much for a single 5v output?

Thanks

pcmanbob
Posts: 2015
Joined: Fri May 31, 2013 9:28 pm
Location: Mansfield UK

Re: L293D troubleshooting for IR camera cut control

Mon Nov 13, 2017 12:43 pm

I would not try running all that directly from the 5v pin on the gpio.

you should use a separate connection to your 5v supply to provide power for some of them.

L293D & IR filter supply separate 5v supply for the motor supply that's feeding the IR filter
LDR & PIR current draw is minimal so you should be ok powering from 5v pin on gpio
Relay board should be powered from separate 5v supply ( also check 5v not being put on to gpio via control pin )
power boost don't know what you are using this for but I would never connect one of these to a pi gpio they will draw approximately twice the output current from the 5v supply so for every 1A output they need 2A input.

power bank I assume is what you are using for supply.
Please only ask questions in the forum I will not answer questions sent to me directly via PM
Remember we want information.......................no information no help

physis
Posts: 7
Joined: Sun Oct 29, 2017 7:41 am

Re: L293D troubleshooting for IR camera cut control

Tue Nov 14, 2017 12:12 pm

I'm using the power boost to power the IR Lights with 12V using the same power supply that I'm using to feed the Pi but from a different output port.
Will be an experiment because probably I'll end up using a different power bank for the IR Lights to increase the system autonomy.

Here is the circuit diagram that I end up:

Image

The motor part I changed the BCM 4 for BCM 5 in order to connect the RTC in the first 5 pins from the top left.
If the original is:

Code: Select all

from gpiozero import Motor
from time import sleep

motor = Motor(forward=4, backward=14)

while True:
    motor.forward()
    sleep(5)
    motor.backward()
    sleep(5)
The new would be:

Code: Select all

from gpiozero import Motor
from time import sleep

motor = Motor(forward=5, backward=14)

while True:
    motor.forward()
    sleep(5)
    motor.backward()
    sleep(5)
I'm correct?

For the other part of the system would be the same code (LDR, Light, PIR):

Code: Select all

from gpiozero import LED, MotionSensor, LightSensor
from signal import pause
pir = MotionSensor(21)
ldr = LightSensor(26)
light = LED(25)
def daytime():
    pir.when_motion = None
    pir.when_no_motion = None
    light.off()
def nighttime():
    pir.when_motion = light.on
    pir.when_no_motion = light.off
ldr.when_light = daytime
ldr.when_dark = nighttime
pause()
What I can realise by myself is that the motor state forward or backward should be related with the LDR (BCM 26). Can I use the def daytime/ nighttime to make it switch?
... something in this way:

Code: Select all

from gpiozero import LED, MotionSensor, LightSensor, Motor
from signal import pause
pir = MotionSensor(21)
ldr = LightSensor(26)
light = LED(25)
motor = Motor(forward=5, backward=14)
def daytime():
    pir.when_motion = None
    pir.when_no_motion = None
    light.off()
    motor.forward()
def nighttime():
    pir.when_motion = light.on
    pir.when_no_motion = light.off
    motor.backward()
ldr.when_light = daytime
ldr.when_dark = nighttime
pause()
Once again, thanks a lot for your help.
Best regards,
Diogo

Return to “Automation, sensing and robotics”

Who is online

Users browsing this forum: No registered users and 28 guests