Published on

Level 4

Table of Contents

Pre Requisites

  • TinkerCAD
  • Switch and Push Buttons
  • General Arduino Interfacing

A Brief Outline

  • Pull-up Resistor and De-bouncing
  • Analog Data - Read and Write
  • What is PWM, Duty Cycle
  • Dimming an LED
  • Analog Sensors: LDR And Potentiometers
  • Onshape : 3D Drafting

Pull-Up Resistors

A pull-up resistor is a simple resistor used to make sure that the voltage is well-defined even when the switch is open. It is used to ensure that a wire is pulled up to a high logical level in the absence of an input signal.

pinMode(INPUT_PULLUP)

The Arduino comes equipped with internal resistors which can be operated in the Pull-Up mode.

As you would have noticed in the pinMode() documentation (Link), The Digital GPIO pins can operate in the INPUT_PULLUP which enables the internal resistors on that pin and let's the pin be used in Pull-Up mode.

Pull-Up

MCU = Micro-Controller Unit

Links to Follow : Youtube - Floating Pins and Pull-Up resistors

Switch Debouncing

Bouncing?

A Push button comprises of two metal contacts that touch upon pressing action on the button. Upon touching the metal contacts bounce upon each other making the switch on and off for a time after impact from pressing action by user.

Thus, if the sensing element is sensitive enough, it registers multiple button press from a single action. This can introduce errors in the system you are using and can hinder a lot of processes.

Bouncing

To overcome these errors we establish "Debouncing" Techniques, This can be achieved both via software or hardware tweaks.

An very simple software debounce is to employ a delay before registering the button's state thus avoiding the Bouncing state of the button.

millis()

This function returns the number of milliseconds passed since the Arduino board began running the current program.

Syntax: time_variable = millis()

Analog Input

The Arduino UNO has 6 pins (A0 to A5) that can read analog input voltages received between 0 and the Operating voltage (Generally 5V).

These Analog Pins map the input voltages to a resolved value between 0 and 1023, Using a 10 bit ADC (Analog to Digital Converter)

AnalogInput

Links to Follow : Analog Input?

analogRead()

This in-built arduino function reads a value from a GPIO analog pin and resolves it to a value between 0 and 1023 which can be stored as an integer type variable.

Syntax : analogRead(pin)

int analogPin = 42;
int val; //to store the analog read

void setup(){

pinMode(analogPin, INPUT);
}

void loop(){

val = analogRead(analogPin);
}

Links to Follow : analogRead() function documentation

Can you use the analog pins(A0- A5) for Digtal Functions?

Find out for yourself!

analogWrite()

The arduino has 6 digital GPIO pins which can perform PWM to produce a varying duty cycle which can be controlled by passing a value between 0 and 255.

Pins 3, 5, 6, 9, 10, 11 on the Arduino UNO are equipped with the PWM logic, They can be used for both digitalWrite() and analogWrite().

Syntax : analogWrite(Pin_number, value)

PWM

Notice how the pins have a ~ symbol on them to help differentiate.

PWMpins

Documentation for analogWrite()

Dim an LED

int brightness = 0;

void setup()
{
	pinMode(9, OUTPUT);
}

void loop()
{
	// Increase brightness from 0 to 255
	for  (brightness = 0; brightness <= 255; brightness += 5)  {
		analogWrite(9,  brightness);
		delay(30);
     }
	//Decrease brightness from 255 to 0
	for  (brightness = 255; brightness >= 0; brightness -= 5)  {
		analogWrite(9,  brightness);
		delay(30);
     }
}
dimLED

Link to the PWM Simulation

Pulse Width Modulation

Pulse Width Modulation (PWM) is a technique for creating analog results with digital means. The Arduino generates a square wave, a signal switched on and off. This on- off pattern can simulate voltages in between the full Vcc (5V) and off (0V) by changing the "duty cycle" of the Square wave.

PWM_2

Duty Cycle

When the signal is high, we call this "on time". The Duty cycle specifically describes the percentage of time a digital signal is On (5V) over an interval or period of time.

duty cycle=tonton+toffduty\ cycle = {t_{on} \above{2pt} t_{on}+t_{off}}\newline
ton=ON timetoff=OFF timeton+toff=Time period \begin{gather} t_{on} = ON\ time\newline t_{off} = OFF\ time\newline t_{on} + t_{off} = Time\ period\newline \end{gather}
Vaverage=5V×Duty CycleV_{average} = 5V \times Duty\ Cycle

Analog Sensors

Potentiometer

A 3-terminal instrument which measures and gives out a fraction of voltage applied across its two ends, depending upon the variation of the position of sliding contact over the uniform resistance (placed in a semi-circular manner, acting as a voltage divider).

Potentiometer

LDR

A Light Dependent Resistor (a.k.a photoresistor or LDR) is a device whose resistivity varies with the incident electromagnetic radiation. Hence, they are light-sensitive devices. Also called photoconductors / photoconductive cells or simply photocells.

When the light of enough energy falls on it, the number of electrons available for the conduction increases proportional to the intensity of light.

LDR

RGB LED

The RGB LED can emit different colors by mixing the 3 basic colors red, green and blue. So it actually consists of 3 separate LEDs red, green and blue packed in a single case. That’s why it has 4 leads, one lead for each of the 3 colors and one common cathode or anode depending on the RGB LED type.

RGB-LED

Links to Follow : Using RGB Leds in TinkerCAD

Onshape : 3D Drafting

You are expected to watch the following videos, and practice a few questions.

  1. Let's Make an Assembly - Tech Tip
  2. OnShape Assemblies - Basic Assembly
  3. OnShape Assemblies: Creating Mate Connectors
  4. OnShape Assemblies - Intermediate Assemblies (optional)

Topics to pursue

  • The map() function
  • Hardware Debounce techniques
  • Basics of ADC (Resolution, Quantization etc)