Posts

Showing posts from November, 2023

Controlling a motor with a transistor

Image
What are transistors How do transistors work. For NPN transistors Saturation.  Current flows from Collector to Emitter.  Occurs when the voltage of the base passes a threshold. Cut off.  No current flows from collector to emitter Caused when the voltage of the base is below another threshold (usually 0.6V) Active.  Output voltage is proportional to base voltage.  (Difficult to use with the Pi as we don't control the output voltage with the Pi).  Caused when the voltage is between 1 and 2 thresholds. Reverse Active (unusual state where the current goes from the emitter to the collector.) Youtube video Youtube video Difference between NPN and PNP Using the Pi to control the motor using PWM Flyback diodes (Protection) Youtube Video Trans BC548 Zerner 10V will do

Making a buzzer sound.

Image
  import RPi.GPIO as GPIO import time buzzer_pin = 18 GPIO.setmode (GPIO.BCM) GPIO.setup (buzzer_pin, GPIO.OUT) def buzz (pitch, duration):     print ("Pitch is " + str(pitch) + "Hz")     print ("Duration is " + str(duration) + "seconds")     period = 1.0 / pitch     #Trace period = 1/1000 = 0.001     print ("Period is " + str(period) + "seconds")     delay = period / 2     #Trace delay = 0.001/2 = 0.0005     cycles = int (duration * pitch)     #Trace cycles = 4 * 1000 = 4000     print ("Cycles are " + str(cycles))     #range function returns a sequence of numbers     for i in range (cycles):         GPIO.output (buzzer_pin, True)         time.sleep(delay)         GPIO.output (buzzer_pin, False)         time.sleep(delay) try:     while True:         #Chang...