Professional Documents
Culture Documents
What is Arduino?
8-bit = 28 values
Pins A0-A5 : Analog pins, can take Analog inputs only. Controlled by
ADC (10-bit resolution)
File-> Examples->
Basics->Blink
WE SEND 5V TO THAT
PIN
WE SEND 0V TO
THE PIN
/*
Turns on an LED on for one second, then off for one
second, repeatedly.
*/
void setup() {
void loop() {
digitalWrite(9, HIGH); // set the LED on
delay(1000); // wait for a second
digitalWrite(9, LOW); // set the LED off
delay(1000); // wait for a second
}
VARIABLES AND DATA TYPES
A variable is nothing but a name given to a storage area
that our programs can manipulate. Each variable in C has
a specific type, which determines the size and layout of
the variable's memory; the range of values that can be
stored within that memory; and the set of operations
that can be applied to the variable.
void loop() {
analogWrite(9,(your wish between 0-255)); // set the LED on a certain intesity
delay(1000); // wait for a second
digitalWrite(9, (your wish)); // set the LED on a different intesnity
delay(1000); // wait for a second
}
What is PWM?
Pulse width modulation (PWM) is a fancy term for describing a type of digital signal.
This is for an 8bit resolution.
Potentiometer:
A potentiometer, informally
a pot, is a three-terminal
resistor with a sliding or
rotating contact that forms
an adjustable voltage
divider.
Moving the knob is like moving the point where the arrow taps the voltage on the resistor
Connections
void setup()
{
Serial.begin(9600);
// put your setup code here, to run once:
pinMode(9, OUTPUT);}
void loop() {
// put your main code here, to run repeatedly:
int potval = analogRead(A0); //potval ranges from 0-5v
Serial.println(potval);
delay(1000);
}
SET PIN 9 AS AN OUTUT PIN
void loop() {
// put your main code here, to run repeatedly:
double potval = analogRead(A3);
Serial.println(potval);
double norm=5.0/255; //what is norm?
analogWrite(9,(int)(potval*norm));
delay(1); - Try and change the value, and see what happens.
}
Activity #2 - AUTOMATIC LAMP
These babies
Brighter light = lower resistance
Connections
IF condition
The ability to control the flow of your program, letting it make decisions on what code to execute,
is valuable to the programmer.
The if statement allows you to control if a program enters a section of code or not based on whether a
given
condition is true or false.
One of the important functions of the if statement is that it allows the program to select an action
based upon
the user's input.
For example, by using an if statement to check a user-entered password, your program can decide
whether a
user is allowed access to the program.
If(statement is true)
{
run this;
}
SET PIN 9 AS AN
Code: OUTPUT PIN
void setup() {
Serial.begin(9600);
pinMode(9, OUTPUT);}
TAKE VALUES
void loop() { FROM LDR
int ldr = analogRead(A2); \\values from 0-5
Serial.println (ldr);
int thresh=enter;
if (ldr > thresh) IF VALUE>
TRUE
MAKE BULB
{ THRESHOL
D GLOW
digitalWrite(9,HIGH);
}
if (ldr < thresh)
{ TURN BULB
digitalWrite(9,LOW); OFF
}
delay(1);
}
ACTIVITY 3- PUSH BUTTONS
void setup() {
void loop() {
if (digitalRead(7) == HIGH) //if (digitalRead(push) == HIGH)
{
digitalWrite(13,HIGH);
}
else
{
digitalWrite(13,LOW);
}
}