Arduino Uno
Would you like to react to this message? Create an account in a few clicks or log in to continue.

Go down
Admin
Admin
Admin
Posts : 17
Join date : 2017-09-20
Age : 26
http://unosketches.forumotion.asia

Sketching programs that will control the state of transistor Empty Sketching programs that will control the state of transistor

Wed Sep 20, 2017 3:55 pm
The program below will turn "ON" a 12V DC lamp for 1min and turn it "OFF" for 30 sec using pin 13 of Arduino UNO board.
( I used a transistor to interface a 12V Dc load to the board)

void setup() {
pinMode(13, OUTPUT);
}
void loop() {
digitalWrite(13, HIGH);
delay(60000);
digitalWrite(13, LOW);
delay(30000);
}

It works!

Now, I need sketch another simple programs using a transistor. What could be the possible codes for the following:

1. A program that will turn "ON" a 12 DC lamp for 1min and turn "OFF" for 30secs using pin 0 of Arduino UNO board.

2. A program that will check the logic status of signal fed to the pin 0 of Arduino UNO board, and will turn "ON" the 12Vdc load connected at pin 13 if the logic status of pin 0 is 1 and turn "OFF" the 12Vdc load connected at pin 13 if the logic status of 0 is 0.

3. A program for Arduino UNO board that will turn "ON" the 12Vdc load connected at pin 13 if both pin 0 or pin 1 is logic 1.

You can answer any of the questions. Feel free to ask questions too. Laughing
avatar
nicanorroberto
NEWBIE
Posts : 2
Join date : 2017-10-11

Sketching programs that will control the state of transistor Empty Re: Sketching programs that will control the state of transistor

Wed Oct 11, 2017 3:55 pm
Ma'am for number 1 program, I think the codes would be:

void setup() {
pinMode(0, OUTPUT);
}
void loop() {
digitalWrite(0, HIGH);
delay(60000);
digitalWrite(0, LOW);
delay(30000);
}

delay(30000);
}


Laughing  Laughing  Laughing
avatar
adrianmorcilla
GURU
Posts : 12
Join date : 2017-10-03

Sketching programs that will control the state of transistor Empty Re: Sketching programs that will control the state of transistor

Thu Oct 12, 2017 8:59 am
Maam Cha, for no. 3 program, I tried it and I use these codes:

void setup() {
pinMode(13, OUTPUT);
pinMode(0, INPUT);
}
void loop() {
if (digitalRead (0)== HIGH) {
digitalWrite (13, HIGH);
}
else
digitalWrite(13, LOW);
}}
avatar
lancemaximo
GURU
Posts : 12
Join date : 2017-10-12

Sketching programs that will control the state of transistor Empty Re: Sketching programs that will control the state of transistor

Thu Oct 12, 2017 9:52 am
Ma'am what's better to use? " delay() " or " millis() " ??
avatar
lancemaximo
GURU
Posts : 12
Join date : 2017-10-12

Sketching programs that will control the state of transistor Empty Re: Sketching programs that will control the state of transistor

Thu Oct 12, 2017 10:14 am
No. 3 program:

void setup() {
pinMode (13, OUTPUT);
pinMode (0, INPUT);
pinMode (1, INPUT);
}
void loop () {
if(digitalRead (0)== HIGH &&
digitalRead (6)== HIGH)
{
digitalWrite (13, HIGH);
}
else
{
digitalwrite (13, LOW)
}
Admin
Admin
Admin
Posts : 17
Join date : 2017-09-20
Age : 26
http://unosketches.forumotion.asia

Sketching programs that will control the state of transistor Empty Re: Sketching programs that will control the state of transistor

Thu Oct 12, 2017 10:50 am
Lance, using delay() to control timing is probably one of the very first things you learned when experimenting with the Arduino.  Timing with delay() is simple and straightforward, but it does cause problems down the road when you want to add additional functionality.  The problem is that delay() is a "busy wait" that monopolizes the processor. During a delay() call, you can’t respond to inputyyfghfs, you can't process any data and you can’t change any outputs.  The delay() ties up 100% of the processor.

The millis() function performs a single task. When called, it returns (as a long datatype) the number of milliseconds that have elapsed since the program was first launched. So, why is that useful?
Because by using a little bit of simple math, you can easily “time” aspects of your program without impacting how it works. The following is a basic demonstration of how millis() works. As you’ll see, the program will turns the LED light on for 1000 milliseconds (one second), and then turns it off. But crucially, it does it in a way that’s non-blocking.

Now let’s look at how it works with Arduino.
Sketching programs that will control the state of transistor Arduino-millis-example

This program – which is heavily based on one from the official Arduino documentation – works by subtracting the previous recorded time from the current time. If the remainder (ie. time elapsed since the time was last recorded) is greater than the interval (in this case, 1000 milliseconds), the program updates the previousTime variable to the current time, and either turns the LED on or off.

And because it’s a non-blocking, any code that’s located outside of that first if statement should work normally.

Simple, isn’t it? Note how we we created the variable currentTime as an unsigned long. An unsigned value simply means that it can never be negative; we do this so that the maximum number we can store is larger. By default, number variables are signed, which means one “bit” of memory for that variable is used to store whether the value is positive or negative. By specifying it’ll only be positive, we have one extra bit to play with.

So that's one way to approach timing in our Arduino program which is better than delay().
Admin
Admin
Admin
Posts : 17
Join date : 2017-09-20
Age : 26
http://unosketches.forumotion.asia

Sketching programs that will control the state of transistor Empty Re: Sketching programs that will control the state of transistor

Thu Oct 12, 2017 10:55 am
What's the another way to approach timing in Arduino program which is better than delay() ?
avatar
camillebungay
MEMBER
Posts : 4
Join date : 2017-10-12

Sketching programs that will control the state of transistor Empty Re: Sketching programs that will control the state of transistor

Thu Oct 12, 2017 10:59 am
Maam Cha I think it's the INTERRUPTS. Very Happy Very Happy
avatar
lancemaximo
GURU
Posts : 12
Join date : 2017-10-12

Sketching programs that will control the state of transistor Empty Re: Sketching programs that will control the state of transistor

Thu Oct 12, 2017 6:07 pm
INTERRUPTS Ma'am...

Interrupts are useful for making things happen automatically in microcontroller programs, and can help solve timing problems. Good tasks for using an interrupt may include reading a rotary encoder, or monitoring user input.

If you wanted to insure that a program always caught the pulses from a rotary encoder, so that it never misses a pulse, it would make it very tricky to write a program to do anything else, because the program would need to constantly poll the sensor lines for the encoder, in order to catch pulses when they occurred. Other sensors have a similar interface dynamic too, such as trying to read a sound sensor that is trying to catch a click, or an infrared slot sensor (photo-interrupter) trying to catch a coin drop. In all of these situations, using an interrupt can free the microcontroller to get some other work done while not missing the input.

Interrupt Service Routines:
ISRs are special kinds of functions that have some unique limitations most other functions do not have. An ISR cannot have any parameters, and they shouldn't return anything.
Generally, an ISR should be as short and fast as possible. If your sketch uses multiple ISRs, only one can run at a time, other interrupts will be executed after the current one finishes in an order that depends on the priority they have. millis() relies on interrupts to count, so it will never increment inside an ISR. Since delay() requires interrupts to work, it will not work if called inside an ISR. micros() works initially, but will start behaving erratically after 1-2 ms. delayMicroseconds() does not use any counter, so it will work as normal.

Typically global variables are used to pass data between an ISR and the main program. To make sure variables shared between an ISR and the main program are updated correctly, declare them as volatile.
avatar
adrianmorcilla
GURU
Posts : 12
Join date : 2017-10-03

Sketching programs that will control the state of transistor Empty Re: Sketching programs that will control the state of transistor

Thu Oct 12, 2017 6:34 pm
Transistor in Saturation region

Saturation region is one in which both Emitter Base and Base Collector junctions of the transistor are forward biased. In this region high currents flows through the transistor, as both junctions of the transistor are forward biased and bulk resistance offered is very much less.Transistor in saturation region is considered as on state in digital logic.

A transistor is said to be in saturation if and only if

β > Ic/Ib

This is due to the fact that as both junctions of transistor are forward biased along with electron current flowing from emitter to base in active region there will be additional component of electron current flowing from collector to base.Small changes in Collector to base forward voltage leads to large variations in collector currents(variations in currents will be exponential as mentioned before through diode current equation).

Transistor in Cutoff region

In this region both junctions of the transistor are reverse biased. Hence transistor in cut off does not conduct any currents expect for small reverse saturation currents that flow across junctions. In cutoff condition emitter current is zero and the collector current consists of small reverse saturation currents. The transistor when used as switch is operated in cutoff on condition and saturation regions which corresponds to switch off an on condition respectively.

Inverse active region of transistor

In inverse active region is just inverse or complementary to active region. In inverse active region the Base emitter junction is forward biased and Base Collector junction will be reverse biased.
avatar
cynthiacamarinta
NEWBIE
Posts : 2
Join date : 2017-10-12

Sketching programs that will control the state of transistor Empty Re: Sketching programs that will control the state of transistor

Thu Oct 12, 2017 6:47 pm
Interrupts are a simple way to make your system more responsive to time sensitive tasks. They also have the added benefit of freeing up your main `loop()` to focus on some primary task in the system. (I find that this tends to make my code a little more organized when I use them - it's easier to see what the main chunk of code was designed for, while the interrupts handle periodic events.) The example shown here is just about the most basic case for using an interrupt - you can use them for reading an I2C device, sending or receiving wireless data, or even starting or stopping a motor.
Admin
Admin
Admin
Posts : 17
Join date : 2017-09-20
Age : 26
http://unosketches.forumotion.asia

Sketching programs that will control the state of transistor Empty Re: Sketching programs that will control the state of transistor

Thu Oct 12, 2017 7:58 pm
Give me answers in these questions:

What is the most common bias circuit?

Which transistor bias circuit arrangement has poor stability because its Q-point varies widely with DC?

The input/output relationship of the common-collector and common-base amplifiers is?
avatar
adrianmorcilla
GURU
Posts : 12
Join date : 2017-10-03

Sketching programs that will control the state of transistor Empty Re: Sketching programs that will control the state of transistor

Thu Oct 12, 2017 8:13 pm
The input/output relationship of the common-collector and common-base amplifiers is 0 degrees
avatar
adrianmorcilla
GURU
Posts : 12
Join date : 2017-10-03

Sketching programs that will control the state of transistor Empty Re: Sketching programs that will control the state of transistor

Thu Oct 12, 2017 8:18 pm
With low-power transistor packages, the base terminal is usually the middle
Sponsored content

Sketching programs that will control the state of transistor Empty Re: Sketching programs that will control the state of transistor

Back to top
Permissions in this forum:
You cannot reply to topics in this forum