Press "Enter" to skip to content

Wk 2: Intro. to Microcontroller Circuits

Some important takeaways from labs

Microcontroller/controller: a simple processor to do only one task
Processor/ computer: a device that runs a program

The microcontroller is less computationally capable, requires less power, and easier to interface with the physical world compared with a processor. A microcontroller can communicate with other processors.

Digital input: namely binary input only allows people to sense two states: off and on.
Digital output: namely binary output only allows people to control activities that have two states.

Analog input: read a variable voltage
Analog output:…

Whenever you use a new sensor, the first thing you need to understand is what the range is that it can read and deliver. As inputs, the pins of a microcontroller can accept very little current. Likewise, as outputs, they produce very little current. The electrical signals that they read and write are mainly changes in voltage, not current. When you want to read an electrical change that’s high-current, you limit the current input using a resistor. Similarly, when you want to control a high-current circuit, you use a transistor or relay, both of which allow you to control a circuit with only small voltage changes and minimal current

Coding in Arduino

Digital signals:

digitalRead(PIN);
digitalWrite(PIN, LOW);

Analog signals:
Since a microcontroller’s inputs can read only two values (typically 0 volts or 5 volts), an analog-to-digital converter (ADC) reads a changing input voltage and converts it to a binary value, which a microcontroller can then store in memory in an int type. Add pause between two analog reads, because a microcontroller has only one ADC.

int analogInPin_A0 = A0;
int analogInPin_A1 = A1;

analogRead(analogInPin_A0); // read from analog pins
delay(1);
analogRead(analogInPin_A1);

int analogOutputPin = A1;
pinMode(analogOutputPin, OUTPUT); // set to an analogOutputPin to output
digitalWrite(analogOutputPin, HIGH); // set analog out pin high

The analogRead command will not work correctly if a pin has been previously set to an output, so if this is the case, set it back to an input before using analogRead.

Analog input: switch, potentiometer, photocell

analog input 3 caseanalog input 3 case circuit

When I adjust the potentiometer, the output value of the potentiometer varies.
But when I click the button, the value remains 1, which doesn’t make sense. (??? office hour)

analog input 3 case screen

Digital input and output: LED blinks

https://youtu.be/6VeC-GEcXCA

 

led switch
Led controlled by switch