Controlling passive buzzer

JohnInTX

Joined Jun 26, 2012
4,787
0.10 volt when object is in front of sensor
And 3.42 volt when there is no object in front of the sensor
OK! That tells you that my schematic is correct when it shows the LED and R as the pull up for the comparator's output. As I said earlier, the forward voltage drop of the LED (Vf) reduces the high output voltage to the measured 3.42V. That is below the 4.0V Vih(min) for the PIC input. That means that you must use an external pull up resistor to get the output high voltage to meet the PIC spec. If you don't, you can not rely on the PIC input to reliably report what the sensor is doing.

There are several lessons here that you should think about. First, always know what the specifications are for the parts you are using and make sure they are compatible. Next, always verify the voltages, signals etc. at the port pins to make sure that your circuit, sensors meet minimum specifications. Finally, understand that many things you buy for cheap from AliBaba, Amazon, eBay and the like are knock-off copies of something. They are engineered solely for the lowest cost. If you look at the schematic in the YouTube video you'll see R3, 10K is across the LED and its series resistor R1. R3 is the pull up that ensures a good high voltage. Someone thought they would save a few micro cents by deleting that resistor from the circuit. The result is that YOU have to install your own pull up resistor (like we did) or put up with possibly incorrect operation. That's why I avoid that stuff. I am not saying that you can't get some service from it but always double check the operation, voltages etc. and don't trust that what you have been sold as a KY-033 will perform like the original.

Your code should be happier with the external pull up.
 
Last edited:

Thread Starter

Djsarakar

Joined Jul 26, 2020
489
Here's an updated schematic with a better description of the pull up.
Hi JohnIn. Thank you very much for help.
I ran previous code and it worked as expected. I am happy at end sensor module is working

I will try to find out the problem with obstacle avoidance sensor module.

https://easyeda.com/adrirobot/KY-032_Obstacle_avoidance_sensor_module

Output voltage 5.5 volt DC when no object detected
When I keep the object in front of the sensor, I measured 4.95 v DC output
 
Last edited:

JohnInTX

Joined Jun 26, 2012
4,787
Output voltage 5.5 volt DC when no object detected
When I keep the object in front of the sensor, I measured 4.95 v DC output
I guess the indicator (SLED) does not turn on?

The datasheet for the IR detector is attached. Note that it needs the IR LED to be switched at 38KHz - that's what the 555 is for.
You can adjust the pot R5 to increase the drive to the IR LED. Do NOT turn it all the way CCW. That will overdrive the LED.

The other pot R6 controls the frequency of the 555 and must be set to oscillate at 38KHz.

EDIT: Note this from the HS0038B datasheet
The data signal should fullfill the following condition:
• Carrier frequency should be close to center
frequency of the bandpass (e.g. 38kHz).
• Burst length should be 10 cycles/burst or longer.
• After each burst which is between 10 cycles and 70
cycles a gap time of at least 14 cycles is neccessary.
• For each burst which is longer than 1.8ms a
corresponding gap time is necessary at some time in
the data stream. This gap time should be at least 4
times longer than the burst.

Some examples for such disturbance signals which
are suppressed by the HS0038B are
:
• DC light (e.g. from tungsten bulb or sunlight)
Continuous signal at 38kHz or at any other
frequency

• Signals from fluorescent lamps with electronic
ballast with high or low modulation (see Figure A or
Figure B).
That means that even though you have a continuous reflection, you won't get a continuous output LOW signal. That is common with these receivers. These are used in TV remote controls which issue pulsed 38KHz bursts. The restriction on a continuous signal is part of the filtering against spurious signals.
 

Attachments

Last edited:

Thread Starter

Djsarakar

Joined Jul 26, 2020
489
The datasheet for the IR detector is attached. Note that it needs the IR LED to be switched at 38KHz - that's what the 555 is for.
You can adjust the pot R5 to increase the drive to the IR LED. Do NOT turn it all the way CCW. That will overdrive the LED.
Thank you I have adjusted R5 and R6 and now sensor module is working fine
 

Thread Starter

Djsarakar

Joined Jul 26, 2020
489
Last edited:

hexreader

Joined Apr 16, 2011
581
Looks like 200 Ohms to me, not 220

Minimum resistance that I would use with 5 Volt circuit is 330 Ohms. Usually I use anywhere between 470 Ohms and 1000 Ohms.

Move blue wire two columns to the left and see if red LED lights. If it does not light, then I would guess that red LED is burnt out.

.... but only a guess ...
 

hexreader

Joined Apr 16, 2011
581
No, move blue wire TWO to the left

Leave everything else as it was, (except that 470 Ohm resistor is good)

EDIT: - disclaimer - all guess work, as even if schematic were available, I would have little confidence of accuracy.
 
Last edited:

JohnInTX

Joined Jun 26, 2012
4,787
The resistor has moved. It needs to be on the center pin.
’morning hex..
EDIT: disregard this. I was working from an incorrect schematic.
 
Last edited:

hexreader

Joined Apr 16, 2011
581
Forgot I had been through all of this before ... (how could I have forgotten?)

I think my guess at pinout was wrong and Djsarker perhaps had it right all along.

But I think OP has tried enough combinations to make the guess that red LED is maybe blown.
 

JohnInTX

Joined Jun 26, 2012
4,787
If you google

37 in 1 sensor kit tutorial

you'll get several hits to large, detailed tutorials for each sensor. It's written for Arduino but has the pinouts which seem to be pretty standard across the clones.
 

Thread Starter

Djsarakar

Joined Jul 26, 2020
489
Forgot I had been through all of this before ... (how could I have forgotten?)

I think my guess at pinout was wrong and Djsarker perhaps had it right all along.

But I think OP has tried enough combinations to make the guess that red LED is maybe blown.
Anyway I have another similar module.

IMG_20201020_185325.jpg

https://startingelectronics.org/tutorials/arduino/modules/common-cathode-LED/

There are the different advice in many links

I will try to connect module I hope LED should not burn
 

hexreader

Joined Apr 16, 2011
581
Be sure to ALWAYS put 470 Ohm resistor in series with +5V lead and your LEDs should be protected from wrong connections

When you progress to using a PIC, be sure to connect 470 Ohm resistor between PIC output and LED.

If I am reading correct schematic, then final circuit will require:
GND connection to left-hand pin of LED module (looking from front with pins pointing downwards)
470 Ohm resistor to centre pin of module - other side of resistor goes to PIC output pin (for now use PIC pin D0)
470 Ohm resistor to right pin of module - other side of resistor goes to different PIC output pin (for now use PIC pin D1)

I will write you a simple, tested program for this soon
 
Last edited:

JohnInTX

Joined Jun 26, 2012
4,787
And for TS, it would help in your photos if you used a consistent color code for your wires because we can't always see where the other end is connected. Use:
RED +5V
BLACK GND
Other colors that make sense if possible. Match the wire colors to the LED colors if you can or use something close. Use BLUE for signal outputs etc.
If you are consistent, it will help us and you too.
 

hexreader

Joined Apr 16, 2011
581
and as promised...

(read useful information in comments at top of code.)
(I edited out an error in earlier post - connect D0, D1 - not D0, D0)

C:
// random code for forum
// PIC18F45K80 with external 2-pin 20MHz crystal
// test some random 2 colour LED thing that gives digital on/off output

// connect gnd lead to LED module left-hand pin
// connect 470 Ohms resistor from RD0 , then other side of resistor to centre pin of LED module
// connect 470 Ohms resistor from RD1 , then other side of resistor to right pin of LED module

// PIC18F45K80 Configuration Bit Settings

#define _XTAL_FREQ 20000000

// CONFIG1L
#pragma config RETEN = ON       // VREG Sleep Enable bit (Ultra low-power regulator is Enabled (Controlled by SRETEN bit))
#pragma config INTOSCSEL = LOW  // LF-INTOSC Low-power Enable bit (LF-INTOSC in Low-power mode during Sleep)
// SOSCSEL = No Setting
#pragma config XINST = OFF      // Extended Instruction Set (Disabled)

// CONFIG1H
#pragma config FOSC = HS2       //  HS oscillator (high power, 16 MHz-25 MHz
#pragma config PLLCFG = OFF     // PLL x4 Enable bit (Disabled)
#pragma config FCMEN = OFF      // Fail-Safe Clock Monitor (Disabled)
#pragma config IESO = OFF       // Internal External Oscillator Switch Over Mode (Disabled)

// CONFIG2L
#pragma config PWRTEN = ON      // Power Up Timer (Enabled)
#pragma config BOREN = OFF      // Brown Out Detect (Disabled in hardware, SBOREN disabled)
#pragma config BORV = 0         // Brown-out Reset Voltage bits (3.0V)
#pragma config BORPWR = LOW     // BORMV Power level (BORMV set to low power level)

// CONFIG2H
#pragma config WDTEN = OFF      // Watchdog Timer (WDT disabled in hardware; SWDTEN bit disabled)
#pragma config WDTPS = 1        // Watchdog Postscaler (1:1)

// CONFIG3H
#pragma config CANMX = PORTC    // ECAN Mux bit (ECAN TX and RX pins are located on RC6 and RC7, respectively)
#pragma config MSSPMSK = MSK5   // MSSP address masking (5 bit address masking mode)
#pragma config MCLRE = ON       // Master Clear Enable

// CONFIG4L
#pragma config STVREN = OFF     // Stack Overflow Reset (Disabled)
#pragma config BBSIZ = BB1K     // Boot Block Size (1K word Boot Block size)

// CONFIG5L
#pragma config CP0 = ON         // Code Protect 00800-01FFF (Enabled)
#pragma config CP1 = ON         // Code Protect 02000-03FFF (Enabled)
#pragma config CP2 = ON         // Code Protect 04000-05FFF (Enabled)
#pragma config CP3 = ON         // Code Protect 06000-07FFF (Enabled)

// CONFIG5H
#pragma config CPB = ON         // Code Protect Boot (Enabled)
#pragma config CPD = ON         // Data EE Read Protect (Enabled)

// CONFIG6L
#pragma config WRT0 = ON        // Table Write Protect 00800-01FFF (Enabled)
#pragma config WRT1 = ON        // Table Write Protect 02000-03FFF (Enabled)
#pragma config WRT2 = ON        // Table Write Protect 04000-05FFF (Enabled)
#pragma config WRT3 = ON        // Table Write Protect 06000-07FFF (Enabled)

// CONFIG6H
#pragma config WRTC = ON        // Config. Write Protect (Enabled)
#pragma config WRTB = ON        // Table Write Protect Boot (Enabled)
#pragma config WRTD = ON        // Data EE Write Protect (Enabled)

// CONFIG7L
#pragma config EBTR0 = ON       // Table Read Protect 00800-01FFF (Enabled)
#pragma config EBTR1 = ON       // Table Read Protect 02000-03FFF (Enabled)
#pragma config EBTR2 = ON       // Table Read Protect 04000-05FFF (Enabled)
#pragma config EBTR3 = ON       // Table Read Protect 06000-07FFF (Enabled)

// CONFIG7H
#pragma config EBTRB = ON       // Table Read Protect Boot (Enabled)

// #pragma config statements should precede project file includes.
// Use project enums instead of #define for ON and OFF.

#include <xc.h>

void Port_Initialized (void)
{
    ANCON0 = 0;                                                                 // Set to digital port
    ANCON1 = 0;                                                                 // Set to digital port
    CM1CON = 0;                                                                 // Comparator off
    CM2CON = 0;                                                                 // Comparator off
    ADCON0 = 0;                                                                 // A/D conversion Disabled
    ADCON1 = 0;                                                                 // A/D conversion Disabled
    ADCON2 = 0;                                                                 // A/D conversion Disabled

    LATA =  0;                                                                  // all outputs low  
    LATB =  0;                                                                  // all outputs low
    LATC =  0;                                                                  // all outputs low
    LATD =  0;                                                                  // all outputs low
    LATE =  0;                                                                  // all outputs low

    TRISA = 0b0000000;                                                          // all are output, Unused
    TRISB = 0b0000000;                                                          // all are output, Unused
    TRISC = 0b0000000;                                                          // all are output, Unused
    TRISD = 0b0000000;                                                          // all are output, LED on RD0 and RD1
    TRISE = 0b0000000;                                                          // All are output, Unused
}

void main(void)
{
    Port_Initialized();                                                         // Initialize PIC ports

    while (1)                                                                   // loop forever
    {
        LATD = 2;                                                               // D1 high to light LED, D0 low
            __delay_ms(1000);                                                   // keep LED lit long enough to see change of status
        LATD = 1;                                                               // D0 high to light LED, D1 low
            __delay_ms(1000);                                                   // keep LED off long enough to see change of status          
    }
}
 

Thread Starter

Djsarakar

Joined Jul 26, 2020
489
Thank you both so this module is not too difficult and all is working fine. I will try each module myself and if I don't understand I will come back
 
Top